From 9069728e4ba60df6ada86610818baff11fdabf8f Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 6 Jun 2018 12:35:42 -0400 Subject: [PATCH 1/2] simplify the hook script Instead of copying the BUILD_DEPENDS array from a subshell that sources the dkms.conf and uses a herestring to pass that to readarray, run the whole function in a subshell. It needs one subshell either way, and heredocs use a temporary file which is just totally unnecessary albeit minimal overhead in this case. Heredocs also invoke command substitution which strips newlines, and do not support \0 which means readarray needs to re-split the content based on newlines instead. Neither of these are likely to matter in this case... but why not just avoid it, if it is free to do so? Both of these could be solved by using < <(commands) which communicates via a file instead of command substitution. But that still results in an unnecessary temporary file. Instead of copying the BUILD_EXCLUSIVE_KERNEL variable from a subshell that sources the dkms.conf and uses a herestring to pass that to readarray, simply use command substitution to assign the value to the variable. The herestring is once again inefficiently opening a temporary file, except this time it is totally unnecessary as the value in the dkms.conf is not an array and does not need to be split into one --- trunk/hook.sh | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/trunk/hook.sh b/trunk/hook.sh index 9999985..309bc35 100755 --- a/trunk/hook.sh +++ b/trunk/hook.sh @@ -26,25 +26,21 @@ run() { # check whether the dependencies of a module are installed # $1: module name/module version # $2: kernel version -check_dependency() { - local -a BUILD_DEPENDS - readarray -t BUILD_DEPENDS <<<$(source "$source_tree/${1/\//-}/dkms.conf"; printf '%s\n' "${BUILD_DEPENDS[@]}") - [[ -z ${BUILD_DEPENDS[@]} ]] && unset BUILD_DEPENDS - local mod - for mod in "${BUILD_DEPENDS[@]}"; do - if ! [[ "$(dkms status -m "$mod" -k "$2")" =~ :[[:space:]]installed$ ]]; then - return 1 +check_dependency() { ( + source "$source_tree/${1/\//-}/dkms.conf" + for dep in "${BUILD_DEPENDS[@]}"; do + if ! [[ "$(dkms status -m "$dep" -k "$2")" =~ :[[:space:]]installed$ ]]; then + exit 1 fi done - return 0 -} + exit 0 +) } # check whether the modules should be built with this kernel version # $1: module name/module version # $2: kernel version check_buildexclusive() { - local BUILD_EXCLUSIVE_KERNEL - readarray -t BUILD_EXCLUSIVE_KERNEL <<<$(source "$source_tree/${1/\//-}/dkms.conf"; printf '%s\n' "$BUILD_EXCLUSIVE_KERNEL") + local BUILD_EXCLUSIVE_KERNEL=$(source "$source_tree/${1/\//-}/dkms.conf"; printf '%s\n' "$BUILD_EXCLUSIVE_KERNEL") [[ "$2" =~ $BUILD_EXCLUSIVE_KERNEL ]] } -- 2.17.1 From a262e61037f2f15c92b741e68fa976346b88febb Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 6 Jun 2018 20:10:06 -0400 Subject: [PATCH 2/2] Trivial comment update --- trunk/hook.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trunk/hook.sh b/trunk/hook.sh index 309bc35..c6054b7 100755 --- a/trunk/hook.sh +++ b/trunk/hook.sh @@ -97,7 +97,7 @@ dkms_install() { elif [[ ! -d "$install_tree/$kver/kernel" ]]; then DKMS_MODULES[$nvk]="Missing kernel modules tree" continue - # postone modules with missing dependencies + # postpone modules with missing dependencies elif ! check_dependency "$mod" "$kver"; then DKMS_MODULES[$nvk]="Missing dependency" continue @@ -139,7 +139,7 @@ show_errors() { main() { [[ -n "$DKMS_ALPM_HOOK_DEBUG" ]] && set -x - # prevent to have all each dkms call to fail + # avoid having each dkms call fail with permission errors if (( EUID )); then echo 'You must be root to use this hook' >&2 exit 1 -- 2.17.1