[arch-commits] Commit in dkms/trunk (PKGBUILD hook.remove hook.sh hook.upgrade)

Sébastien Luttringer seblu at archlinux.org
Wed May 27 16:31:26 UTC 2020


    Date: Wednesday, May 27, 2020 @ 16:31:26
  Author: seblu
Revision: 387727

upgpkg: dkms 2.8.1-4

- Run depmod only once per kernel (implement FS#59265)
- Add upgrade hook
- Error messages when remove fail
- Improve modules dependencies when concurent version installed
- Do not remove excluded modules
- Remove workaround from FS#49816. (Fixed in https://git.archlinux.org/pacman.git/commit/?id=9886566abb375043740167ce5066f1a186c71176.)
- Use spaces instead of tabs

Added:
  dkms/trunk/hook.upgrade
Modified:
  dkms/trunk/PKGBUILD
  dkms/trunk/hook.remove
  dkms/trunk/hook.sh

--------------+
 PKGBUILD     |   18 ++-
 hook.remove  |    5 
 hook.sh      |  301 +++++++++++++++++++++++++++++++++------------------------
 hook.upgrade |   13 ++
 4 files changed, 203 insertions(+), 134 deletions(-)

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2020-05-27 14:57:54 UTC (rev 387726)
+++ PKGBUILD	2020-05-27 16:31:26 UTC (rev 387727)
@@ -3,7 +3,7 @@
 
 pkgname=dkms
 pkgver=2.8.1
-pkgrel=3
+pkgrel=4
 pkgdesc='Dynamic Kernel Modules System'
 arch=('any')
 url='https://github.com/dell/dkms'
@@ -19,12 +19,14 @@
 source=("git+https://github.com/dell/dkms.git#tag=v$pkgver"
         'hook.install'
         'hook.remove'
+        'hook.upgrade'
         'hook.sh'
         '0001-Revert-Make-newly-installed-modules-available-immedi.patch')
 sha256sums=('SKIP'
             '047e0e46967e98fbf3ff8860a80f259c28693d5989373d5a5395714495b59844'
-            'c3e3a20857e628116bde499af1b3614bcafb49dbe9b5775cfcf0aa862af1750a'
-            '3463adfe18dad0805a806c2fb0fc4faf88924056168980a3c7cbc28a27c8867b'
+            'ae5483980db914d52bff981ed83356c85679dd7e6e8f73bdd94265f065014c73'
+            'd61d94532789928085a8494ba039c59244cfb3bfd47deaf21bcbe54a2243dc45'
+            '6bc3931865afce6ee17a56099cf551ab2827db99b609de78e1bf9a1962e6ef56'
             '124b821b1b44ba365d915945825bcf32c1077655c3a98eb1644de56b6abfcd09')
 
 prepare() {
@@ -47,9 +49,15 @@
 }
 
 package() {
-  # alpm hook
+  # alpm hooks
   install -D -m 644 hook.install "$pkgdir/usr/share/libalpm/hooks/70-dkms-install.hook"
-  install -D -m 644 hook.remove "$pkgdir/usr/share/libalpm/hooks/70-dkms-remove.hook"
+  # both upgrade and remove hooks are removing dkms modules.
+  # remove always call depmod while upgrade never, as install will later.
+  # upgrade is run before remove in order to have the cleanest depmod file,
+  # if something goes wrong before the depmod call in install hook.
+  install -D -m 644 hook.upgrade "$pkgdir/usr/share/libalpm/hooks/70-dkms-upgrade.hook"
+  install -D -m 644 hook.remove "$pkgdir/usr/share/libalpm/hooks/71-dkms-remove.hook"
+  # hook helper
   install -D -m 755 hook.sh "$pkgdir/usr/lib/dkms/alpm-hook"
   # upstream installer
   cd dkms

Modified: hook.remove
===================================================================
--- hook.remove	2020-05-27 14:57:54 UTC (rev 387726)
+++ hook.remove	2020-05-27 16:31:26 UTC (rev 387727)
@@ -1,5 +1,4 @@
 [Trigger]
-Operation = Upgrade
 Operation = Remove
 Type = Path
 Target = usr/src/*/dkms.conf
@@ -10,7 +9,5 @@
 Description = Remove DKMS modules
 Depends = dkms
 When = PreTransaction
-# SIGPIPE workaround. See FS#49816
-#Exec = /usr/lib/dkms/alpm-hook remove
-Exec = /usr/bin/perl -e "$SIG{PIPE}='DEFAULT'; exec('/usr/lib/dkms/alpm-hook', 'remove');"
+Exec = /usr/lib/dkms/alpm-hook remove
 NeedsTargets

Modified: hook.sh
===================================================================
--- hook.sh	2020-05-27 14:57:54 UTC (rev 387726)
+++ hook.sh	2020-05-27 16:31:26 UTC (rev 387727)
@@ -19,33 +19,37 @@
 
 # display what to run and run it quietly
 run() {
-	echo "==> $*"
-	"$@" > /dev/null
-	local ret=$?
-	(( $ret )) && echo "==> Warning, \`$*' returned $ret"
+  echo "==> $*"
+  "$@" > /dev/null
+  local ret=$?
+  (( $ret )) && echo "==> Warning, \`$*' returned $ret"
+  return $ret
 }
 
 # check whether the dependencies of a module are installed
-# $1: module name/module version
-# $2: kernel version
+# $1: module name
+# $2: module version
+# $3: kernel version
 check_dependency() { (
-	source "$source_tree/${1/\//-}/dkms.conf"
-	local state
-	for dep in "${BUILD_DEPENDS[@]}"; do
-		state=$(dkms status -m "$dep" -k "$2")
-		if ! [[ "$state" =~ "$mod, $mver, $kver, "[^:]+': installed' ]]; then
-			exit 1
-		fi
-	done
-	exit 0
+  source "$source_tree/$1-$2/dkms.conf"
+  local mod lines line
+  for mod in "${BUILD_DEPENDS[@]}"; do
+    mapfile lines < <(dkms status -m "$mod" -k "$3")
+    for line in "${lines[@]}"; do
+      [[ "$line" =~ "$mod, "[^,]+", $3, "[^:]+': installed' ]] && break 2
+    done
+    exit 1
+  done
+  exit 0
 ) }
 
 # check whether the modules should be built with this kernel version
-# $1: module name/module version
-# $2: kernel version
+# $1: module name
+# $2: module version
+# $3: kernel version
 check_buildexclusive() {
-	local BUILD_EXCLUSIVE_KERNEL=$(source "$source_tree/${1/\//-}/dkms.conf"; printf '%s\n' "$BUILD_EXCLUSIVE_KERNEL")
-	[[ "$2" =~ $BUILD_EXCLUSIVE_KERNEL ]]
+  local BUILD_EXCLUSIVE_KERNEL=$(source "$source_tree/$1-$2/dkms.conf"; printf '%s\n' "$BUILD_EXCLUSIVE_KERNEL")
+  [[ "$3" =~ $BUILD_EXCLUSIVE_KERNEL ]]
 }
 
 # handle actions on module addition/upgrade/removal
@@ -52,24 +56,24 @@
 # $1: module name
 # $2: module version
 parse_module() {
-	pushd "$install_tree" >/dev/null
-	local path
-	for path in */build/; do
-		local kver="${path%%/*}"
-		dkms_register "$1" "$2" "$kver"
-	done
-	popd >/dev/null
+  pushd "$install_tree" >/dev/null
+  local path
+  for path in */build/; do
+    local kver="${path%%/*}"
+    dkms_register "$1" "$2" "$kver"
+  done
+  popd >/dev/null
 }
 
 # handle actions on kernel addition/upgrade/removal
 # $1: kernel version
 parse_kernel() {
-	local path
-	for path in "$source_tree"/*-*/dkms.conf; do
-		if [[ -f "$path" && "$path" =~ ^$source_tree/([^/]+)-([^/]+)/dkms\.conf$ ]]; then
-			dkms_register "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "$1"
-		fi
-	done
+  local path
+  for path in "$source_tree"/*-*/dkms.conf; do
+    if [[ -f "$path" && "$path" =~ ^$source_tree/([^/]+)-([^/]+)/dkms\.conf$ ]]; then
+      dkms_register "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "$1"
+    fi
+  done
 }
 
 # register a dkms module to install/remove
@@ -76,125 +80,172 @@
 # this function suppress echo call for a module
 # $1: module name, $2: module version, $3: kernel version
 dkms_register() {
-	DKMS_MODULES["$1/$2/$3"]=''
+  DKMS_MODULES["$1/$2/$3"]=''
 }
 
 # install registered modules
 dkms_install() {
-	local nvk mod kver
-	local -i retry=1
+  local nvk mod mver kver
+  local -i retry=1
+  local -A dmods=()
 
-	while (( $retry > 0 )); do
-		retry=0
-		for nvk in "${!DKMS_MODULES[@]}"; do
-			mod=${nvk%/*}
-			kver=${nvk##*/}
-			# do not build excluded modules
-			if ! check_buildexclusive "$mod" "$kver"; then
-				unset DKMS_MODULES[$nvk]
-				continue
-			# skip modules with missing kernel headers
-			elif [[ ! -d "$install_tree/$kver/build/include" ]]; then
-				DKMS_MODULES[$nvk]="Missing kernel headers"
-				continue
-			# skip modules with missing kernel package
-			elif [[ ! -d "$install_tree/$kver/kernel" ]]; then
-				DKMS_MODULES[$nvk]="Missing kernel modules tree"
-				continue
-			# postpone modules with missing dependencies
-			elif ! check_dependency "$mod" "$kver"; then
-				DKMS_MODULES[$nvk]="Missing dependency"
-				continue
-			fi
-			# give it a try dkms
-			run dkms install "$mod" -k "$kver"
-			unset DKMS_MODULES[$nvk]
-			# maybe this module was a dep of another, so we retry
-			retry=1
-		done
-	done
+  while (( $retry > 0 )); do
+    retry=0
+    for nvk in "${!DKMS_MODULES[@]}"; do
+      [[ "$nvk" =~ ([^/]+)/([^/]+)/(.+) ]]
+      mod="${BASH_REMATCH[1]}"
+      mver="${BASH_REMATCH[2]}"
+      kver="${BASH_REMATCH[3]}"
+      # do not build excluded modules
+      if ! check_buildexclusive "$mod" "$mver" "$kver"; then
+        unset DKMS_MODULES[$nvk]
+        continue
+      # skip modules with missing kernel headers
+      elif [[ ! -d "$install_tree/$kver/build/include" ]]; then
+        DKMS_MODULES[$nvk]='Missing kernel headers'
+        continue
+      # skip modules with missing kernel package
+      elif [[ ! -d "$install_tree/$kver/kernel" ]]; then
+        DKMS_MODULES[$nvk]='Missing kernel modules tree'
+        continue
+      # postpone modules with missing dependencies
+      elif ! check_dependency "$mod" "$mver" "$kver"; then
+        DKMS_MODULES[$nvk]='Missing dependency'
+        continue
+      fi
+      # give it a try dkms
+      run dkms install --no-depmod -m "$mod" -v "$mver" -k "$kver"
+      dmods[$kver]=''
+      unset DKMS_MODULES[$nvk]
+      # maybe this module was a dep of another, so we retry
+      retry=1
+    done
+  done
+  # run depmod later for performance improvments
+  if (( $DKMS_DEPMOD )); then
+    for kver in "${!dmods[@]}"; do
+      run depmod "$kver"
+    done
+  fi
 }
 
 # remove registered modules when built/installed
+# run depmod later for performance improvments
 dkms_remove() {
-	local nvk mod mver kver state
-	for nvk in "${!DKMS_MODULES[@]}"; do
-		[[ "$nvk" =~ ([^/]+)/([^/]+)/(.+) ]]
-		mod="${BASH_REMATCH[1]}"
-		mver="${BASH_REMATCH[2]}"
-		kver="${BASH_REMATCH[3]}"
-		state=$(dkms status -m "$mod" -v "$mver" -k "$kver")
-		if [[ "$state" =~ "$mod, $mver, $kver, "[^:]+": "(built|installed) ]]; then
-			run dkms remove "$mod" -v "$mver" -k "$kver"
-		fi
-		unset DKMS_MODULES[$nvk]
-	done
+  local nvk mod mver kver state
+  local -A dmods=()
+  for nvk in "${!DKMS_MODULES[@]}"; do
+    [[ "$nvk" =~ ([^/]+)/([^/]+)/(.+) ]]
+    mod="${BASH_REMATCH[1]}"
+    mver="${BASH_REMATCH[2]}"
+    kver="${BASH_REMATCH[3]}"
+    # do not remove excluded modules (n.b. display not found errors)
+    if ! check_buildexclusive "$mod" "$mver" "$kver"; then
+      unset DKMS_MODULES[$nvk]
+      continue
+    fi
+    state=$(dkms status -m "$mod" -v "$mver" -k "$kver")
+    if [[ "$state" =~ "$mod, $mver, $kver, "[^:]+": "(added|built|installed) ]]; then
+      dmods[$kver]=''
+      run dkms remove --no-depmod -m "$mod" -v "$mver" -k "$kver"
+      if (( $? == 0 )); then
+        unset DKMS_MODULES[$nvk]
+      else
+        DKMS_MODULES[$nvk]='dkms remove failed'
+      fi
+    else
+      DKMS_MODULES[$nvk]='Not found in dkms status output'
+    fi
+  done
+  # run depmod later for performance improvments
+  if (( $DKMS_DEPMOD )); then
+    for kver in "${!dmods[@]}"; do
+      run depmod "$kver"
+    done
+  fi
 }
 
 # show information about failed modules
 show_errors() {
-	local nvk mod kver
-	for nvk in "${!DKMS_MODULES[@]}"; do
-		mod=${nvk%/*}
-		kver=${nvk##*/}
-		echo "==> Unable to $DKMS_ACTION module $mod for kernel $kver: ${DKMS_MODULES[$nvk]}."
-	done
+  local nvk mod kver
+  for nvk in "${!DKMS_MODULES[@]}"; do
+    mod=${nvk%/*}
+    kver=${nvk##*/}
+    echo "==> Unable to $DKMS_ACTION module $mod for kernel $kver: ${DKMS_MODULES[$nvk]}."
+  done
 }
 
+# display hook usage and exit $1 (default 1)
+usage() {
+  cat << EOF >&2
+usage: ${0##*/} <options> install|remove
+options: -D  Do not run depmod
+EOF
+  exit ${1:-1}
+}
+
 # emulated program entry point
 main() {
-	[[ -n "$DKMS_ALPM_HOOK_DEBUG" ]] && set -x
+  [[ "$DKMS_ALPM_HOOK_DEBUG" ]] && set -x
 
-	# prevent each dkms call from failing with authorization errors
-	if (( EUID )); then
-		echo 'You must be root to use this hook' >&2
-		exit 1
-	fi
+  # prevent each dkms call from failing with authorization errors
+  if (( EUID )); then
+    echo 'You must be root to use this hook' >&2
+    exit 1
+  fi
 
-	# register DKMS action
-	case "$1" in
-		install|remove)
-			declare -r DKMS_ACTION="$1"
-			;;
-		*)
-			echo "usage: ${0##*/} install|remove" >&2
-			exit 1
-			;;
-	esac
+  # parse command line options
+  declare -i DKMS_DEPMOD=1
+  local opt
+  while getopts 'hD' opt; do
+    case $opt in
+      D) DKMS_DEPMOD=0;;
+      *) usage;;
+    esac
+  done
+  shift $((OPTIND - 1))
+  (( $# != 1 )) && usage
 
-	# dkms path from framework config
-	# note: the alpm hooks which trigger this script use static path
-	source_tree='/usr/src'
-	install_tree='/usr/lib/modules'
-	source /etc/dkms/framework.conf
+  # register DKMS action
+  case "$1" in
+    install|remove)
+      declare -r DKMS_ACTION="$1";;
+    *) usage;;
+  esac
 
-	# check source_tree and install_tree exists
-	local path
-	for path in "$source_tree" "$install_tree"; do
-		if [[ ! -d "$path" ]]; then
-			echo "==> Missing mandatory directory: $path. Exiting!"
-			return 1
-		fi
-	done
+  # dkms path from framework config
+  # note: the alpm hooks which trigger this script use static path
+  source_tree='/usr/src'
+  install_tree='/usr/lib/modules'
+  source /etc/dkms/framework.conf
 
-	# storage for DKMS modules to install/remove
-	# we use associate arrays to prevent duplicate
-	declare -A DKMS_MODULES
+  # check source_tree and install_tree exists
+  local path
+  for path in "$source_tree" "$install_tree"; do
+    if [[ ! -d "$path" ]]; then
+      echo "==> Missing mandatory directory: $path. Exiting!"
+      return 1
+    fi
+  done
 
-	# parse stdin paths to guess what do do
-	while read -r path; do
-		if [[ "/$path" =~ ^$source_tree/([^/]+)-([^/]+)/dkms\.conf$ ]]; then
-			parse_module "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
-		elif [[ "/$path" =~ ^$install_tree/([^/]+)/ ]]; then
-			parse_kernel "${BASH_REMATCH[1]}"
-		fi
-	done
+  # storage for DKMS modules to install/remove
+  # we use associate arrays to prevent duplicate
+  declare -A DKMS_MODULES
 
-	dkms_$DKMS_ACTION
+  # parse stdin paths to guess what do do
+  while read -r path; do
+    if [[ "/$path" =~ ^$source_tree/([^/]+)-([^/]+)/dkms\.conf$ ]]; then
+      parse_module "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}"
+    elif [[ "/$path" =~ ^$install_tree/([^/]+)/ ]]; then
+      parse_kernel "${BASH_REMATCH[1]}"
+    fi
+  done
 
-	show_errors
+  dkms_$DKMS_ACTION
 
-	return 0
+  show_errors
+
+  return 0
 }
 
 main "$@"

Added: hook.upgrade
===================================================================
--- hook.upgrade	                        (rev 0)
+++ hook.upgrade	2020-05-27 16:31:26 UTC (rev 387727)
@@ -0,0 +1,13 @@
+[Trigger]
+Operation = Upgrade
+Type = Path
+Target = usr/src/*/dkms.conf
+Target = usr/lib/modules/*/build/include/
+Target = usr/lib/modules/*/modules.alias
+
+[Action]
+Description = Remove upgraded DKMS modules
+Depends = dkms
+When = PreTransaction
+Exec = /usr/lib/dkms/alpm-hook -D remove
+NeedsTargets


More information about the arch-commits mailing list