@@ -176,13 +176,15 @@ invoke_command()
176
176
if [[ -n " $cmd_output_file " ]]; then
177
177
local t_start
178
178
local t_end
179
+ # shellcheck disable=SC2129
179
180
echo " " >> " $cmd_output_file "
180
181
echo -e " $cmd_description " >> " $cmd_output_file "
181
182
echo -e " # command: $cmd " >> " $cmd_output_file "
182
183
t_start=$SECONDS
183
184
( eval " $cmd " ) >> " $cmd_output_file " 2>&1
184
185
exitval=$?
185
186
t_end=$SECONDS
187
+ # shellcheck disable=SC2129
186
188
echo -e " \n# exit code: $exitval " >> " $cmd_output_file "
187
189
echo " # elapsed time: $( date -u -d " 0 $t_end sec - $t_start sec" +%T) " >> " $cmd_output_file "
188
190
echo " ----------------------------------------------------------------" >> " $cmd_output_file "
@@ -409,6 +411,8 @@ setup_kernels_arches()
409
411
grep -v " not owned by any package" | grep kernel | head -n 1)
410
412
if ! arch[0]=$( rpm -q --queryformat " %{ARCH}" " $kernelver_rpm " 2> /dev/null) ; then
411
413
arch[0]=$( uname -m)
414
+ # shellcheck disable=SC2010
415
+ # TODO: replace ls | grep
412
416
if [[ ${arch[0]} = x86_64 ]] && grep -q Intel /proc/cpuinfo && ls " $install_tree /${kernelver[0]} /build/configs" 2> /dev/null | grep -q " ia32e" ; then
413
417
arch[0]=" ia32e"
414
418
fi
@@ -433,6 +437,7 @@ setup_kernels_arches()
433
437
local i
434
438
for (( i= 0 ; i < ${# arch[@]} ; i++ )) ; do
435
439
[[ " ${arch[0]} " != " ${arch[i]} " ]] && {
440
+ # shellcheck disable=SC2034
436
441
multi_arch=" true"
437
442
break
438
443
}
@@ -474,6 +479,7 @@ distro_version()
474
479
for f in /etc/os-release /usr/lib/os-release; do
475
480
if [[ -e $f ]]; then
476
481
(
482
+ # shellcheck disable=SC1090
477
483
. " $f "
478
484
if [[ " $ID " = " ubuntu" ]]; then
479
485
# ID_LIKE=debian in ubuntu
@@ -529,14 +535,18 @@ safe_source() {
529
535
# shellcheck disable=SC2206
530
536
# we intentionally split the string into a multi-element array
531
537
declare -a -r export_envs=( $@ )
538
+ # shellcheck disable=SC2034
539
+ # false positive
532
540
local -r CR=$( echo -e ' \r' )
533
541
local tmpfile
534
542
tmpfile=$( mktemp_or_die)
535
543
( exec > " $tmpfile "
544
+ # shellcheck disable=SC1090
536
545
. " $to_source_file " > /dev/null
537
546
# This is really ugly, but a neat hack
538
547
# Remember, in bash 2.0 and greater all variables are really arrays.
539
548
for _export_env in " ${export_envs[@]} " ; do
549
+ # shellcheck disable=SC1083,SC2294
540
550
for _i in $( eval echo \$ {! " ${_export_env} " [@]}) ; do
541
551
eval echo ' $_export_env[$_i]=\"${' " ${_export_env} " ' [$_i]%$CR}\"'
542
552
done
@@ -549,6 +559,7 @@ safe_source() {
549
559
echo " $directive_name =\" $directive_value \" "
550
560
done
551
561
)
562
+ # shellcheck disable=SC1090
552
563
. " $tmpfile "
553
564
rm " ${tmpfile:? } "
554
565
@@ -621,15 +632,23 @@ read_conf()
621
632
done
622
633
623
634
# Set variables
635
+ # shellcheck disable=SC2153
624
636
clean=" $CLEAN "
625
637
package_name=" $PACKAGE_NAME "
626
638
package_version=" $PACKAGE_VERSION "
639
+ # shellcheck disable=SC2153
627
640
post_add=" $POST_ADD "
641
+ # shellcheck disable=SC2153
628
642
post_build=" $POST_BUILD "
643
+ # shellcheck disable=SC2153
629
644
post_install=" $POST_INSTALL "
645
+ # shellcheck disable=SC2153
630
646
post_remove=" $POST_REMOVE "
647
+ # shellcheck disable=SC2153
631
648
pre_build=" $PRE_BUILD "
649
+ # shellcheck disable=SC2153
632
650
pre_install=" $PRE_INSTALL "
651
+ # shellcheck disable=SC2153
633
652
obsolete_by=" $OBSOLETE_BY "
634
653
635
654
# Fail if no PACKAGE_NAME
@@ -649,6 +668,7 @@ read_conf()
649
668
local array_size
650
669
local s
651
670
array_size=0
671
+ # shellcheck disable=SC2153
652
672
for s in ${# BUILT_MODULE_NAME[@]} \
653
673
${# BUILT_MODULE_LOCATION[@]} \
654
674
${# DEST_MODULE_NAME[@]} \
@@ -661,6 +681,7 @@ read_conf()
661
681
built_module_location[index]=${BUILT_MODULE_LOCATION[index]}
662
682
dest_module_name[index]=${DEST_MODULE_NAME[index]}
663
683
dest_module_location[index]=${DEST_MODULE_LOCATION[index]}
684
+ # shellcheck disable=SC2153
664
685
case ${STRIP[index]} in
665
686
[nN]* )
666
687
strip[index]=" no"
@@ -859,10 +880,8 @@ check_version_sanity()
859
880
# $4 = dest_module_name
860
881
861
882
local lib_tree
862
- local res
863
883
local i
864
884
lib_tree=" $install_tree /$1 "
865
- res=
866
885
i=0
867
886
if [[ -n $3 ]]; then
868
887
# Magic split into array syntax saves trivial awk and cut calls.
@@ -1095,7 +1114,7 @@ prepare_mok()
1095
1114
echo " Public certificate (MOK): $mok_certificate "
1096
1115
1097
1116
# 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
1099
1118
echo " Certificate or key are missing, generating self signed certificate for MOK..."
1100
1119
if ! command -v openssl > /dev/null; then
1101
1120
echo " openssl not found, can't generate key and certificate."
@@ -1198,12 +1217,15 @@ prepare_and_actual_build()
1198
1217
" This indicates that it should not be built."
1199
1218
1200
1219
# 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
1201
1222
(( $(ls "$source_dir " | wc - l | awk {'print $1 '}) < 2 )) && die 8 \
1202
1223
" The directory $source_dir does not appear to have module source located within it." \
1203
1224
" Build halted."
1204
1225
1205
1226
# Check for missing BUILD_DEPENDS
1206
1227
bd_missing=
1228
+ # shellcheck disable=SC2153
1207
1229
for bd in " ${BUILD_DEPENDS[@]} " ; do
1208
1230
while read -r status mvka; do
1209
1231
[[ $status = installed ]] && continue 2
@@ -1332,10 +1354,16 @@ prepare_and_actual_build()
1332
1354
fi
1333
1355
1334
1356
if [[ $module_compressed_suffix = .gz ]]; then
1357
+ # shellcheck disable=SC2086
1358
+ # splitting is intentional
1335
1359
gzip $compress_gzip_opts -f " $built_module " || compressed_module=" "
1336
1360
elif [[ $module_compressed_suffix = .xz ]]; then
1361
+ # shellcheck disable=SC2086
1362
+ # splitting is intentional
1337
1363
xz $compress_xz_opts -f " $built_module " || compressed_module=" "
1338
1364
elif [[ $module_compressed_suffix = .zst ]]; then
1365
+ # shellcheck disable=SC2086
1366
+ # splitting is intentional
1339
1367
zstd $compress_zstd_opts -f " $built_module " || compressed_module=" "
1340
1368
fi
1341
1369
if [[ -n $compressed_module ]]; then
@@ -1897,6 +1925,8 @@ remove_module()
1897
1925
fi
1898
1926
1899
1927
# Get rid of any remnant directories if necessary
1928
+ # shellcheck disable=SC2012
1929
+ # TODO: use find instead
1900
1930
if (( $(ls "$dkms_tree / $module " | wc - w | awk '{print $1 }') == 0 )) ; then
1901
1931
rm -rf " ${dkms_tree:? } /$module " 2> /dev/null
1902
1932
fi
@@ -1951,7 +1981,11 @@ module_status_weak() {
1951
1981
local -A already_found
1952
1982
for weak_ko in " $install_tree /" * /weak-updates/* ; do
1953
1983
[[ -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
1955
1989
IFS=/ read -r m v k a < <( IFS=$oifs find_module_from_ko " $weak_ko " ) || continue
1956
1990
kern=${weak_ko# " ${install_tree} /" }
1957
1991
kern=${kern%/ weak-updates/* }
@@ -1962,6 +1996,8 @@ module_status_weak() {
1962
1996
for mod in " ${! already_found[@]} " ; do
1963
1997
IFS=/ read -r m v k a kern <<< " $mod"
1964
1998
# ensure each module is weak linked
1999
+ # shellcheck disable=SC2044
2000
+ # TODO: use find + -exec instead
1965
2001
for installed_ko in $( find " $dkms_tree /$m /$v /$kern /$a /module" -type f) ; do
1966
2002
[[ ${already_found[$mod]} != * " $installed_ko " * ]] && continue 2
1967
2003
done
@@ -2117,7 +2153,6 @@ do_status() {
2117
2153
show_status ()
2118
2154
{
2119
2155
local j
2120
- local state_array
2121
2156
if (( ${# kernelver[@]} == 0 )) ; then
2122
2157
do_status " $module " " $module_version " " $kernelver " " $arch "
2123
2158
do_status_weak " $module " " $module_version " " $kernelver " " $arch "
@@ -2185,6 +2220,7 @@ make_tarball()
2185
2220
cp -rf " $source_dir /" * " $temp_dir_name /dkms_source_tree"
2186
2221
fi
2187
2222
2223
+ # shellcheck disable=SC1083
2188
2224
if (( $(echo "$kernel_version_list " | wc - m | awk {'print $1 '}) > 200 )) ; then
2189
2225
kernel_version_list=" manykernels"
2190
2226
fi
@@ -2379,7 +2415,9 @@ run_match()
2379
2415
2380
2416
# Iterate over the kernel_status and match kernel to the template_kernel
2381
2417
while read -r template_line; do
2418
+ # shellcheck disable=SC1083
2382
2419
template_module=$( echo " $template_line " | awk {' print $1' } | sed ' s/,$//' )
2420
+ # shellcheck disable=SC1083
2383
2421
template_version=$( echo " $template_line " | awk {' print $2' } | sed ' s/,$//' )
2384
2422
2385
2423
# Print out a match header
@@ -2401,7 +2439,7 @@ run_match()
2401
2439
report_build_problem ()
2402
2440
{
2403
2441
# 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
2405
2443
python3 /usr/share/apport/package-hooks/dkms_packages.py -m " $module " -v " $module_version " -k " ${kernelver[0]} "
2406
2444
fi
2407
2445
die " $@ "
@@ -2492,10 +2530,10 @@ add_source_tree() {
2492
2530
" $source_tree /$module -$module_version " )
2493
2531
return
2494
2532
;;
2495
- " $dkms_tree /$module /$version /source" )
2533
+ " $dkms_tree /$module /$module_version /source" )
2496
2534
return
2497
2535
;;
2498
- " $dkms_tree /$module /$version /build" )
2536
+ " $dkms_tree /$module /$module_version /build" )
2499
2537
return
2500
2538
;;
2501
2539
esac
@@ -2753,6 +2791,8 @@ umask 022
2753
2791
unset CC CXX CFLAGS CXXFLAGS LDFLAGS
2754
2792
2755
2793
# Set important variables
2794
+ # shellcheck disable=SC2034
2795
+ # not used now, might use later
2756
2796
current_kernel=$( uname -r)
2757
2797
current_os=$( uname -s)
2758
2798
running_distribution=$( distro_version) || exit
2777
2817
rm -f " ${tmpfile:? } "
2778
2818
2779
2819
# These can come from the environment or the config file
2820
+ # shellcheck disable=SC1091
2780
2821
[[ ! ${ADDON_MODULES_DIR} && -e /etc/sysconfig/module-init-tools ]] && . /etc/sysconfig/module-init-tools
2781
2822
addon_modules_dir=" ${ADDON_MODULES_DIR} "
2782
2823
@@ -2822,13 +2863,15 @@ while (($# > 0)); do
2822
2863
case $1 in
2823
2864
--module* |-m)
2824
2865
read_arg _mv " $1 " " $2 " || shift
2866
+ # shellcheck disable=SC2154
2825
2867
parse_moduleversion " $_mv "
2826
2868
;;
2827
2869
-v)
2828
2870
read_arg module_version " $1 " " $2 " || shift
2829
2871
;;
2830
2872
--kernelver* |-k)
2831
2873
read_arg _ka " $1 " " $2 " || shift
2874
+ # shellcheck disable=SC2154
2832
2875
parse_kernelarch " $_ka "
2833
2876
;;
2834
2877
--templatekernel* )
@@ -2898,6 +2941,7 @@ while (($# > 0)); do
2898
2941
;;
2899
2942
--arch* |-a)
2900
2943
read_arg _aa " $1 " " $2 " || shift
2944
+ # shellcheck disable=SC2154
2901
2945
arch[${# arch[@]} ]=" $_aa "
2902
2946
;;
2903
2947
--kernelsourcedir* )
@@ -2906,6 +2950,7 @@ while (($# > 0)); do
2906
2950
;;
2907
2951
--directive* )
2908
2952
read_arg _da " $1 " " $2 " || shift
2953
+ # shellcheck disable=SC2154
2909
2954
directive_array[${# directive_array[@]} ]=" $_da "
2910
2955
;;
2911
2956
--no-depmod)
@@ -3003,7 +3048,9 @@ if [[ -z $NO_WEAK_MODULES ]]; then
3003
3048
weak_modules_remove=' /usr/sbin/weak-modules --no-initramfs --remove-modules'
3004
3049
;;
3005
3050
sles* | suse* | opensuse* )
3051
+ # shellcheck disable=SC2016
3006
3052
weak_modules_add=' /usr/lib/module-init-tools/weak-modules2 --add-kernel-modules ${kernelver}'
3053
+ # shellcheck disable=SC2016
3007
3054
weak_modules_remove=' /usr/lib/module-init-tools/weak-modules2 --remove-kernel-modules ${kernelver}'
3008
3055
;;
3009
3056
* )
@@ -3016,13 +3063,21 @@ case "$action" in
3016
3063
check_module_args " $action "
3017
3064
module_is_broken_and_die
3018
3065
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
3020
3071
" ${action} _module"
3021
3072
;;
3022
3073
add | build | install)
3023
3074
check_all_is_banned " $action " # TODO: fix/enable --all
3024
3075
[[ $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
3026
3081
" ${action} _module"
3027
3082
;;
3028
3083
autoinstall)
0 commit comments