@@ -176,13 +176,15 @@ invoke_command()
176176 if [[ -n " $cmd_output_file " ]]; then
177177 local t_start
178178 local t_end
179+ # shellcheck disable=SC2129
179180 echo " " >> " $cmd_output_file "
180181 echo -e " $cmd_description " >> " $cmd_output_file "
181182 echo -e " # command: $cmd " >> " $cmd_output_file "
182183 t_start=$SECONDS
183184 ( eval " $cmd " ) >> " $cmd_output_file " 2>&1
184185 exitval=$?
185186 t_end=$SECONDS
187+ # shellcheck disable=SC2129
186188 echo -e " \n# exit code: $exitval " >> " $cmd_output_file "
187189 echo " # elapsed time: $( date -u -d " 0 $t_end sec - $t_start sec" +%T) " >> " $cmd_output_file "
188190 echo " ----------------------------------------------------------------" >> " $cmd_output_file "
@@ -409,6 +411,8 @@ setup_kernels_arches()
409411 grep -v " not owned by any package" | grep kernel | head -n 1)
410412 if ! arch[0]=$( rpm -q --queryformat " %{ARCH}" " $kernelver_rpm " 2> /dev/null) ; then
411413 arch[0]=$( uname -m)
414+ # shellcheck disable=SC2010
415+ # TODO: replace ls | grep
412416 if [[ ${arch[0]} = x86_64 ]] && grep -q Intel /proc/cpuinfo && ls " $install_tree /${kernelver[0]} /build/configs" 2> /dev/null | grep -q " ia32e" ; then
413417 arch[0]=" ia32e"
414418 fi
@@ -433,6 +437,7 @@ setup_kernels_arches()
433437 local i
434438 for (( i= 0 ; i < ${# arch[@]} ; i++ )) ; do
435439 [[ " ${arch[0]} " != " ${arch[i]} " ]] && {
440+ # shellcheck disable=SC2034
436441 multi_arch=" true"
437442 break
438443 }
@@ -474,6 +479,7 @@ distro_version()
474479 for f in /etc/os-release /usr/lib/os-release; do
475480 if [[ -e $f ]]; then
476481 (
482+ # shellcheck disable=SC1090
477483 . " $f "
478484 if [[ " $ID " = " ubuntu" ]]; then
479485 # ID_LIKE=debian in ubuntu
@@ -529,14 +535,18 @@ safe_source() {
529535 # shellcheck disable=SC2206
530536 # we intentionally split the string into a multi-element array
531537 declare -a -r export_envs=( $@ )
538+ # shellcheck disable=SC2034
539+ # false positive
532540 local -r CR=$( echo -e ' \r' )
533541 local tmpfile
534542 tmpfile=$( mktemp_or_die)
535543 ( exec > " $tmpfile "
544+ # shellcheck disable=SC1090
536545 . " $to_source_file " > /dev/null
537546 # This is really ugly, but a neat hack
538547 # Remember, in bash 2.0 and greater all variables are really arrays.
539548 for _export_env in " ${export_envs[@]} " ; do
549+ # shellcheck disable=SC1083,SC2294
540550 for _i in $( eval echo \$ {! " ${_export_env} " [@]}) ; do
541551 eval echo ' $_export_env[$_i]=\"${' " ${_export_env} " ' [$_i]%$CR}\"'
542552 done
@@ -549,6 +559,7 @@ safe_source() {
549559 echo " $directive_name =\" $directive_value \" "
550560 done
551561 )
562+ # shellcheck disable=SC1090
552563 . " $tmpfile "
553564 rm " ${tmpfile:? } "
554565
@@ -621,15 +632,23 @@ read_conf()
621632 done
622633
623634 # Set variables
635+ # shellcheck disable=SC2153
624636 clean=" $CLEAN "
625637 package_name=" $PACKAGE_NAME "
626638 package_version=" $PACKAGE_VERSION "
639+ # shellcheck disable=SC2153
627640 post_add=" $POST_ADD "
641+ # shellcheck disable=SC2153
628642 post_build=" $POST_BUILD "
643+ # shellcheck disable=SC2153
629644 post_install=" $POST_INSTALL "
645+ # shellcheck disable=SC2153
630646 post_remove=" $POST_REMOVE "
647+ # shellcheck disable=SC2153
631648 pre_build=" $PRE_BUILD "
649+ # shellcheck disable=SC2153
632650 pre_install=" $PRE_INSTALL "
651+ # shellcheck disable=SC2153
633652 obsolete_by=" $OBSOLETE_BY "
634653
635654 # Fail if no PACKAGE_NAME
@@ -649,6 +668,7 @@ read_conf()
649668 local array_size
650669 local s
651670 array_size=0
671+ # shellcheck disable=SC2153
652672 for s in ${# BUILT_MODULE_NAME[@]} \
653673 ${# BUILT_MODULE_LOCATION[@]} \
654674 ${# DEST_MODULE_NAME[@]} \
@@ -661,6 +681,7 @@ read_conf()
661681 built_module_location[index]=${BUILT_MODULE_LOCATION[index]}
662682 dest_module_name[index]=${DEST_MODULE_NAME[index]}
663683 dest_module_location[index]=${DEST_MODULE_LOCATION[index]}
684+ # shellcheck disable=SC2153
664685 case ${STRIP[index]} in
665686 [nN]* )
666687 strip[index]=" no"
@@ -859,10 +880,8 @@ check_version_sanity()
859880 # $4 = dest_module_name
860881
861882 local lib_tree
862- local res
863883 local i
864884 lib_tree=" $install_tree /$1 "
865- res=
866885 i=0
867886 if [[ -n $3 ]]; then
868887 # Magic split into array syntax saves trivial awk and cut calls.
@@ -1095,7 +1114,7 @@ prepare_mok()
10951114 echo " Public certificate (MOK): $mok_certificate "
10961115
10971116 # scripts/sign-file.c in kernel source also supports using "pkcs11:..." as private key
1098- if [[ $mok_signing_key != " pkcs11:" * ]] && ( [[ ! -f $mok_signing_key || ! -f $mok_certificate ]] ) ; then
1117+ if [[ $mok_signing_key != " pkcs11:" * ]] && [[ ! -f $mok_signing_key || ! -f $mok_certificate ]]; then
10991118 echo " Certificate or key are missing, generating self signed certificate for MOK..."
11001119 if ! command -v openssl > /dev/null; then
11011120 echo " openssl not found, can't generate key and certificate."
@@ -1198,12 +1217,15 @@ prepare_and_actual_build()
11981217 " This indicates that it should not be built."
11991218
12001219 # Error out if source_tree is basically empty (binary-only dkms tarball w/ --force check)
1220+ # shellcheck disable=SC1083,SC2012
1221+ # TODO: use find instead of ls
12011222 (( $(ls "$source_dir " | wc - l | awk {'print $1 '}) < 2 )) && die 8 \
12021223 " The directory $source_dir does not appear to have module source located within it." \
12031224 " Build halted."
12041225
12051226 # Check for missing BUILD_DEPENDS
12061227 bd_missing=
1228+ # shellcheck disable=SC2153
12071229 for bd in " ${BUILD_DEPENDS[@]} " ; do
12081230 while read -r status mvka; do
12091231 [[ $status = installed ]] && continue 2
@@ -1332,10 +1354,16 @@ prepare_and_actual_build()
13321354 fi
13331355
13341356 if [[ $module_compressed_suffix = .gz ]]; then
1357+ # shellcheck disable=SC2086
1358+ # splitting is intentional
13351359 gzip $compress_gzip_opts -f " $built_module " || compressed_module=" "
13361360 elif [[ $module_compressed_suffix = .xz ]]; then
1361+ # shellcheck disable=SC2086
1362+ # splitting is intentional
13371363 xz $compress_xz_opts -f " $built_module " || compressed_module=" "
13381364 elif [[ $module_compressed_suffix = .zst ]]; then
1365+ # shellcheck disable=SC2086
1366+ # splitting is intentional
13391367 zstd $compress_zstd_opts -f " $built_module " || compressed_module=" "
13401368 fi
13411369 if [[ -n $compressed_module ]]; then
@@ -1897,6 +1925,8 @@ remove_module()
18971925 fi
18981926
18991927 # Get rid of any remnant directories if necessary
1928+ # shellcheck disable=SC2012
1929+ # TODO: use find instead
19001930 if (( $(ls "$dkms_tree / $module " | wc - w | awk '{print $1 }') == 0 )) ; then
19011931 rm -rf " ${dkms_tree:? } /$module " 2> /dev/null
19021932 fi
@@ -1951,7 +1981,11 @@ module_status_weak() {
19511981 local -A already_found
19521982 for weak_ko in " $install_tree /" * /weak-updates/* ; do
19531983 [[ -e $weak_ko ]] || continue
1954- [[ -L $weak_ko ]] && installed_ko=" $( readlink -f " $weak_ko " ) " || continue
1984+ if [[ -L $weak_ko ]]; then
1985+ installed_ko=" $( readlink -f " $weak_ko " ) "
1986+ else
1987+ continue
1988+ fi
19551989 IFS=/ read -r m v k a < <( IFS=$oifs find_module_from_ko " $weak_ko " ) || continue
19561990 kern=${weak_ko# " ${install_tree} /" }
19571991 kern=${kern%/ weak-updates/* }
@@ -1962,6 +1996,8 @@ module_status_weak() {
19621996 for mod in " ${! already_found[@]} " ; do
19631997 IFS=/ read -r m v k a kern <<< " $mod"
19641998 # ensure each module is weak linked
1999+ # shellcheck disable=SC2044
2000+ # TODO: use find + -exec instead
19652001 for installed_ko in $( find " $dkms_tree /$m /$v /$kern /$a /module" -type f) ; do
19662002 [[ ${already_found[$mod]} != * " $installed_ko " * ]] && continue 2
19672003 done
@@ -2117,7 +2153,6 @@ do_status() {
21172153show_status ()
21182154{
21192155 local j
2120- local state_array
21212156 if (( ${# kernelver[@]} == 0 )) ; then
21222157 do_status " $module " " $module_version " " $kernelver " " $arch "
21232158 do_status_weak " $module " " $module_version " " $kernelver " " $arch "
@@ -2185,6 +2220,7 @@ make_tarball()
21852220 cp -rf " $source_dir /" * " $temp_dir_name /dkms_source_tree"
21862221 fi
21872222
2223+ # shellcheck disable=SC1083
21882224 if (( $(echo "$kernel_version_list " | wc - m | awk {'print $1 '}) > 200 )) ; then
21892225 kernel_version_list=" manykernels"
21902226 fi
@@ -2379,7 +2415,9 @@ run_match()
23792415
23802416 # Iterate over the kernel_status and match kernel to the template_kernel
23812417 while read -r template_line; do
2418+ # shellcheck disable=SC1083
23822419 template_module=$( echo " $template_line " | awk {' print $1' } | sed ' s/,$//' )
2420+ # shellcheck disable=SC1083
23832421 template_version=$( echo " $template_line " | awk {' print $2' } | sed ' s/,$//' )
23842422
23852423 # Print out a match header
@@ -2401,7 +2439,7 @@ run_match()
24012439report_build_problem ()
24022440{
24032441 # If apport is on the system, files a build problem
2404- if [[ -x /usr/share/apport/apport ]] && which python3 > /dev/null; then
2442+ if [[ -x /usr/share/apport/apport ]] && command -v python3 > /dev/null; then
24052443 python3 /usr/share/apport/package-hooks/dkms_packages.py -m " $module " -v " $module_version " -k " ${kernelver[0]} "
24062444 fi
24072445 die " $@ "
@@ -2492,10 +2530,10 @@ add_source_tree() {
24922530 " $source_tree /$module -$module_version " )
24932531 return
24942532 ;;
2495- " $dkms_tree /$module /$version /source" )
2533+ " $dkms_tree /$module /$module_version /source" )
24962534 return
24972535 ;;
2498- " $dkms_tree /$module /$version /build" )
2536+ " $dkms_tree /$module /$module_version /build" )
24992537 return
25002538 ;;
25012539 esac
@@ -2753,6 +2791,8 @@ umask 022
27532791unset CC CXX CFLAGS CXXFLAGS LDFLAGS
27542792
27552793# Set important variables
2794+ # shellcheck disable=SC2034
2795+ # not used now, might use later
27562796current_kernel=$( uname -r)
27572797current_os=$( uname -s)
27582798running_distribution=$( distro_version) || exit
27772817rm -f " ${tmpfile:? } "
27782818
27792819# These can come from the environment or the config file
2820+ # shellcheck disable=SC1091
27802821[[ ! ${ADDON_MODULES_DIR} && -e /etc/sysconfig/module-init-tools ]] && . /etc/sysconfig/module-init-tools
27812822addon_modules_dir=" ${ADDON_MODULES_DIR} "
27822823
@@ -2822,13 +2863,15 @@ while (($# > 0)); do
28222863 case $1 in
28232864 --module* |-m)
28242865 read_arg _mv " $1 " " $2 " || shift
2866+ # shellcheck disable=SC2154
28252867 parse_moduleversion " $_mv "
28262868 ;;
28272869 -v)
28282870 read_arg module_version " $1 " " $2 " || shift
28292871 ;;
28302872 --kernelver* |-k)
28312873 read_arg _ka " $1 " " $2 " || shift
2874+ # shellcheck disable=SC2154
28322875 parse_kernelarch " $_ka "
28332876 ;;
28342877 --templatekernel* )
@@ -2898,6 +2941,7 @@ while (($# > 0)); do
28982941 ;;
28992942 --arch* |-a)
29002943 read_arg _aa " $1 " " $2 " || shift
2944+ # shellcheck disable=SC2154
29012945 arch[${# arch[@]} ]=" $_aa "
29022946 ;;
29032947 --kernelsourcedir* )
@@ -2906,6 +2950,7 @@ while (($# > 0)); do
29062950 ;;
29072951 --directive* )
29082952 read_arg _da " $1 " " $2 " || shift
2953+ # shellcheck disable=SC2154
29092954 directive_array[${# directive_array[@]} ]=" $_da "
29102955 ;;
29112956 --no-depmod)
@@ -3003,7 +3048,9 @@ if [[ -z $NO_WEAK_MODULES ]]; then
30033048 weak_modules_remove=' /usr/sbin/weak-modules --no-initramfs --remove-modules'
30043049 ;;
30053050 sles* | suse* | opensuse* )
3051+ # shellcheck disable=SC2016
30063052 weak_modules_add=' /usr/lib/module-init-tools/weak-modules2 --add-kernel-modules ${kernelver}'
3053+ # shellcheck disable=SC2016
30073054 weak_modules_remove=' /usr/lib/module-init-tools/weak-modules2 --remove-kernel-modules ${kernelver}'
30083055 ;;
30093056 * )
@@ -3016,13 +3063,21 @@ case "$action" in
30163063 check_module_args " $action "
30173064 module_is_broken_and_die
30183065 module_is_added_or_die
3019- [[ $action = uninstall ]] && check_root || check_rw_dkms_tree
3066+ if [[ $action = uninstall ]]; then
3067+ check_root
3068+ else
3069+ check_rw_dkms_tree
3070+ fi
30203071 " ${action} _module"
30213072 ;;
30223073 add | build | install)
30233074 check_all_is_banned " $action " # TODO: fix/enable --all
30243075 [[ $action != add ]] && module_is_broken_and_die
3025- [[ $action = install ]] && check_root || check_rw_dkms_tree
3076+ if [[ $action = install ]]; then
3077+ check_root
3078+ else
3079+ check_rw_dkms_tree
3080+ fi
30263081 " ${action} _module"
30273082 ;;
30283083 autoinstall)
0 commit comments