Skip to content

Commit de4bb73

Browse files
committed
Replace [ expr ]' with [[ expr ]]' and (( expr ))
In regard of: dell#268. Replaced all instances of `[ expr ]' I could find with `[[ expr ]]', or `(( expr ))'. Also removed the now obsolete quoting. Some unnecessary grouped conditional commands have been consolidated. Signed-off-by: Mart Frauenlob <[email protected]>
1 parent 580e6a5 commit de4bb73

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

dkms.in

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ invoke_command()
9595
wait $(jobs -p) 2>/dev/null
9696
}
9797
trap on_exit EXIT
98-
while [ -d /proc/$pid ]; do
98+
while [[ -d /proc/$pid ]]; do
9999
sleep 3 &
100100
wait $!
101101
echo -en "."
@@ -198,7 +198,7 @@ VER()
198198
get_num_cpus()
199199
{
200200
# use nproc(1) from coreutils 8.1-1+ if available, otherwise single job
201-
if [ -x /usr/bin/nproc ]; then
201+
if [[ -x /usr/bin/nproc ]]; then
202202
nproc
203203
else
204204
echo "1"
@@ -334,20 +334,20 @@ do_depmod()
334334
return
335335
fi
336336
# $1 = kernel version
337-
if [ "${current_os}" != "Linux" ] ; then
337+
if [[ ${current_os} != Linux ]] ; then
338338
return
339339
fi
340340
if [[ -f /boot/System.map-$1 ]]; then
341341
depmod -a "$1" -F "/boot/System.map-$1"
342342
else
343343
depmod -a "$1"
344344
fi
345-
if [ -f /lib/modules/$1/modules.dep ] && [ ! -s /lib/modules/$1/modules.dep ]; then
345+
if [[ -f /lib/modules/$1/modules.dep && ! -s /lib/modules/$1/modules.dep ]]; then
346346
# if modules.dep is empty, we just removed the last kernel module from
347347
# no longer installed kernel $1, so do not leave stale depmod files around
348348
rm -fv /lib/modules/$1/modules.{alias,dep,devname,softdep,symbols,*.bin}
349349
rmdir --ignore-fail-on-non-empty /lib/modules/$1
350-
test -d /lib/modules/$1 || echo $"Removed /lib/modules/$1"
350+
[[ -d /lib/modules/$1 ]] || echo $"Removed /lib/modules/$1"
351351
fi
352352
}
353353

@@ -378,7 +378,7 @@ override_dest_module_location()
378378
local orig_location="$1"
379379
[[ ${addon_modules_dir} ]] && echo "/${addon_modules_dir}" && return
380380

381-
if [ "$current_os" = "GNU/kFreeBSD" ] ; then
381+
if [[ $current_os = GNU/kFreeBSD ]] ; then
382382
# Does not support subdirs, regardless of distribution
383383
echo "" && return
384384
fi
@@ -481,7 +481,7 @@ read_conf()
481481
for _conf_file in "$read_conf_file" "/etc/dkms/$module.conf" \
482482
"/etc/dkms/$module-$module_version.conf" "/etc/dkms/$module-$module_version-$1.conf" \
483483
"/etc/dkms/$module-$module_version-$1-$2.conf"; do
484-
[ -e "$_conf_file" ] && safe_source "$_conf_file" $dkms_conf_variables
484+
[[ -e $_conf_file ]] && safe_source "$_conf_file" $dkms_conf_variables
485485
done
486486

487487
# Source in the directive_array
@@ -735,7 +735,7 @@ check_version_sanity()
735735
local lib_tree="$install_tree/$1" res=
736736
echo $"Running module version sanity check."
737737
local i=0
738-
if [ -n "$3" ]; then
738+
if [[ -n $3 ]]; then
739739
# Magic split into array syntax saves trivial awk and cut calls.
740740
local -a obs=(${3//-/ })
741741
local -a my=(${1//-/ })
@@ -770,7 +770,7 @@ check_version_sanity()
770770
fi
771771
set_module_suffix "$1"
772772
read -a kernels_module < <(find_module "$lib_tree" "${4}")
773-
[ -z $kernels_module ] && return 0
773+
[[ -z $kernels_module ]] && return 0
774774

775775
if [[ "$force_version_override" == "true" ]]; then
776776
# Skip the following version checking code.
@@ -921,7 +921,7 @@ prepare_signing()
921921
{
922922
do_signing=0
923923

924-
if [[ ! -f "${kernel_config}" ]]; then
924+
if [[ ! -f ${kernel_config} ]]; then
925925
echo "Kernel config ${kernel_config} not found, modules won't be signed"
926926
return
927927
fi
@@ -936,7 +936,7 @@ prepare_signing()
936936
# Lazy source in signing related configuration
937937
read_framework_conf $dkms_framework_signing_variables
938938

939-
if [ ! "${sign_file}" ]; then
939+
if [[ ! ${sign_file} ]]; then
940940
case "$running_distribution" in
941941
debian* )
942942
sign_file="/usr/lib/linux-kbuild-${kernelver%.*}/scripts/sign-file"
@@ -948,13 +948,13 @@ prepare_signing()
948948
fi
949949
;;
950950
esac
951-
if [[ ! -f "${sign_file}" ]]; then
951+
if [[ ! -f ${sign_file} ]]; then
952952
sign_file="/lib/modules/$kernelver/build/scripts/sign-file"
953953
fi
954954
fi
955955
echo "Sign command: $sign_file"
956956

957-
if [[ ! -f "${sign_file}" ]] || [[ ! -x "${sign_file}" ]]; then
957+
if [[ ! -f ${sign_file} || ! -x ${sign_file} ]]; then
958958
echo "Binary ${sign_file} not found, modules won't be signed"
959959
return
960960
fi
@@ -967,13 +967,13 @@ prepare_signing()
967967
mok_signing_key="/var/lib/shim-signed/mok/MOK.priv"
968968
mok_certificate="/var/lib/shim-signed/mok/MOK.der"
969969

970-
if [[ ! -f "${mok_signing_key}" ]] || [[ ! -f "${mok_certificate}" ]]; then
970+
if [[ ! -f ${mok_signing_key} || ! -f ${mok_certificate} ]]; then
971971
if [[ ! -x "$(command -v update-secureboot-policy)" ]]; then
972972
echo "Binary update-secureboot-policy not found, modules won't be signed"
973973
return
974974
fi
975975
# update-secureboot-policy won't create new key if $mok_certificate exists
976-
if [[ -f "${mok_certificate}" ]]; then
976+
if [[ -f ${mok_certificate} ]]; then
977977
rm -f "${mok_certificate}"
978978
fi
979979
echo "Certificate or key are missing, generating them using update-secureboot-policy..."
@@ -985,18 +985,18 @@ prepare_signing()
985985
esac
986986
fi
987987

988-
if [ ! "${mok_signing_key}" ]; then
988+
if [[ ! ${mok_signing_key} ]]; then
989989
mok_signing_key="/var/lib/dkms/mok.key"
990990
fi
991991
echo "Signing key: $mok_signing_key"
992992

993-
if [ ! "${mok_certificate}" ]; then
993+
if [[ ! ${mok_certificate} ]]; then
994994
mok_certificate="/var/lib/dkms/mok.pub"
995995
fi
996996
echo "Public certificate (MOK): $mok_certificate"
997997

998998
# scripts/sign-file.c in kernel source also supports using "pkcs11:..." as private key
999-
if [[ "$mok_signing_key" != "pkcs11:"* ]] && ( [ ! -f "$mok_signing_key" ] || [ ! -f "$mok_certificate" ] ); then
999+
if [[ $mok_signing_key != "pkcs11:"* ]] && ( [[ ! -f $mok_signing_key || ! -f $mok_certificate ]] ); then
10001000
echo "Certificate or key are missing, generating self signed certificate for MOK..."
10011001
if ! command -v openssl >/dev/null; then
10021002
echo "openssl not found, can't generate key and certificate."
@@ -1005,13 +1005,13 @@ prepare_signing()
10051005
openssl req -new -x509 -nodes -days 36500 -subj "/CN=DKMS module signing key" \
10061006
-newkey rsa:2048 -keyout "$mok_signing_key" \
10071007
-outform DER -out "$mok_certificate" > /dev/null 2>&1
1008-
if [ ! -f "${mok_signing_key}" ]; then
1008+
if [[ ! -f ${mok_signing_key} ]]; then
10091009
echo "Key file ${mok_signing_key} not found and can't be generated, modules won't be signed"
10101010
return
10111011
fi
10121012
fi
10131013

1014-
if [ ! -f "${mok_certificate}" ]; then
1014+
if [[ ! -f ${mok_certificate} ]]; then
10151015
echo "Certificate file ${mok_certificate} not found and can't be generated, modules won't be signed"
10161016
return
10171017
fi
@@ -1067,7 +1067,7 @@ prepare_build()
10671067
$"Check $build_dir for more information."
10681068
done
10691069

1070-
if [ -f "$kernel_source_dir/.kernelvariables" ]; then
1070+
if [[ -f $kernel_source_dir/.kernelvariables ]]; then
10711071
export CC=$(echo -e "show-%:\n\t@echo \$(\$*)\ninclude $kernel_source_dir/.kernelvariables" | make -f - show-CC)
10721072
else
10731073
unset CC
@@ -1151,14 +1151,14 @@ actual_build()
11511151
"$sign_file" "$sign_hash" "$mok_signing_key" "$mok_certificate" "$built_module"
11521152
fi
11531153

1154-
if [ "$module_compressed_suffix" = ".gz" ]; then
1154+
if [[ $module_compressed_suffix = .gz ]]; then
11551155
gzip -9f "$built_module" || compressed_module=""
1156-
elif [ "$module_compressed_suffix" = ".xz" ]; then
1156+
elif [[ $module_compressed_suffix = .xz ]]; then
11571157
xz -f "$built_module" || compressed_module=""
1158-
elif [ "$module_compressed_suffix" = ".zst" ]; then
1158+
elif [[ $module_compressed_suffix = .zst ]]; then
11591159
zstd -q -f -T0 -20 --ultra "$built_module" || compressed_module=""
11601160
fi
1161-
if [ -n "$compressed_module" ]; then
1161+
if [[ -n $compressed_module ]]; then
11621162
cp -f "$compressed_module" "$base_dir/module/${dest_module_name[$count]}$module_suffix" >/dev/null
11631163
else
11641164
cp -f "$built_module" "$base_dir/module/${dest_module_name[$count]}$module_uncompressed_suffix" >/dev/null
@@ -1197,18 +1197,18 @@ force_installation()
11971197
{
11981198
forced_modules_dir="/usr/share/dkms/modules_to_force_install"
11991199
to_force=""
1200-
if [ -d $forced_modules_dir ]; then
1200+
if [[ -d $forced_modules_dir ]]; then
12011201
for elem in $forced_modules_dir/*; do
1202-
if [ -e $elem ]; then
1202+
if [[ -e $elem ]]; then
12031203
to_force="$to_force $(cat $elem)"
12041204
fi
12051205
done
12061206

12071207
for elem in $to_force; do
1208-
if [ "${1}" = "${elem}" ]; then
1208+
if [[ ${1} = ${elem} ]]; then
12091209
echo "force"
12101210
return 0
1211-
elif [ "${1}_version-override" = "${elem}" ]; then
1211+
elif [[ ${1}_version-override = ${elem} ]]; then
12121212
echo "version-override"
12131213
return 0
12141214
fi
@@ -1359,7 +1359,7 @@ do_install()
13591359
ln -s "$module_version/$kernelver/$arch" "$dkms_tree/$module/kernel-$kernelver-$arch" 2>/dev/null
13601360

13611361
# Add to kabi-tracking
1362-
if [ -z "$NO_WEAK_MODULES" ]; then
1362+
if [[ -z $NO_WEAK_MODULES ]]; then
13631363
if [[ ${weak_modules} ]]; then
13641364
echo $"Adding any weak-modules"
13651365
list_each_installed_module "$module" "$kernelver" "$arch" | ${weak_modules} ${weak_modules_no_initrd} --add-modules
@@ -1379,7 +1379,7 @@ do_install()
13791379
if [[ $modprobe_on_install ]]; then
13801380
# Make the newly installed modules available immediately
13811381
find /sys/devices -name modalias -print0 | xargs -0 cat | sort -u | xargs modprobe -a -b -q
1382-
if [ -f /lib/systemd/system/systemd-modules-load.service ]; then
1382+
if [[ -f /lib/systemd/system/systemd-modules-load.service ]]; then
13831383
systemctl restart systemd-modules-load.service
13841384
fi
13851385
fi
@@ -1540,7 +1540,7 @@ do_uninstall()
15401540
was_active="true"
15411541
echo $"Before uninstall, this module version was ACTIVE on this kernel."
15421542
# remove kabi-tracking if last instance removed
1543-
if [ -z "$NO_WEAK_MODULES" ]; then
1543+
if [[ -z $NO_WEAK_MODULES ]]; then
15441544
if [[ ${weak_modules} ]] && (module_status_built $module $module_version |grep -q "installed"); then
15451545
echo $"Removing any linked weak-modules"
15461546
list_each_installed_module "$module" "$1" "$2" | ${weak_modules} ${weak_modules_no_initrd} --remove-modules
@@ -1552,11 +1552,11 @@ do_uninstall()
15521552
echo $""
15531553
echo $"${dest_module_name[$count]}$module_suffix:"
15541554
echo $" - Uninstallation"
1555-
if [[ "${real_dest_module_location}" ]]; then
1555+
if [[ ${real_dest_module_location} ]]; then
15561556
echo $" - Deleting from: $install_tree/$1${real_dest_module_location}/"
15571557
rm -f "$install_tree/$1${real_dest_module_location}/${dest_module_name[$count]}$module_uncompressed_suffix"*
15581558
dir_to_remove="${real_dest_module_location#/}"
1559-
while [ "${dir_to_remove}" != "${dir_to_remove#/}" ]; do
1559+
while [[ ${dir_to_remove} != ${dir_to_remove#/} ]]; do
15601560
dir_to_remove="${dir_to_remove#/}"
15611561
done
15621562
(if cd "$install_tree/$1"; then rpm -qf "${dir_to_remove}" >/dev/null 2>&1 || rmdir -p --ignore-fail-on-non-empty "${dir_to_remove}"; fi || true)
@@ -1565,7 +1565,7 @@ do_uninstall()
15651565
fi
15661566
echo $" - Original module"
15671567
local origmod=$(compressed_or_uncompressed "$dkms_tree/$module/original_module/$1/$2" "${dest_module_name[$count]}")
1568-
if [[ -n "$origmod" ]]; then
1568+
if [[ -n $origmod ]]; then
15691569
case "$running_distribution" in
15701570
debian* | ubuntu* )
15711571
;;
@@ -1723,7 +1723,7 @@ find_module_from_ko()
17231723
module_status_weak() {
17241724
# $1 = module, $2 = module version, $3 = kernel version weak installed to,
17251725
# $4 = kernel arch, $5 = kernel version built for
1726-
[ -z "$NO_WEAK_MODULES" ] || return 1
1726+
[[ -z $NO_WEAK_MODULES ]] || return 1
17271727
[[ $weak_modules ]] || return 1
17281728
local m v k a kern weak_ko mod installed_ko f ret=1 oifs=$IFS
17291729
local -A already_found
@@ -2112,7 +2112,7 @@ run_match()
21122112
report_build_problem()
21132113
{
21142114
# If apport is on the system, files a build problem
2115-
if [ -x /usr/share/apport/apport ] && which python3 >/dev/null; then
2115+
if [[ -x /usr/share/apport/apport ]] && which python3 >/dev/null; then
21162116
python3 /usr/share/apport/package-hooks/dkms_packages.py -m $module -v $module_version -k ${kernelver[0]}
21172117
fi
21182118
die "$@"
@@ -2232,9 +2232,9 @@ autoinstall() {
22322232
# a list of modules and their latest version.
22332233
while read status mvka; do
22342234
IFS='/' read m v k a <<< "$mvka"
2235-
if [[ -z "${latest["$m"]}" ]]; then
2235+
if [[ -z ${latest[$m]} ]]; then
22362236
known_modules[${#known_modules[@]}]="$m"
2237-
latest["$m"]="$v"
2237+
latest[$m]="$v"
22382238
elif [[ ("$(VER "$v")" > "$(VER "${latest["$m"]}")") ]]; then
22392239
latest["$m"]="$v"
22402240
fi
@@ -2284,13 +2284,13 @@ autoinstall() {
22842284
# Step 2: Install modules that have an empty dependency list.
22852285
for mv in "${to_install[@]}"; do
22862286
IFS=/ read m v <<< "$mv"
2287-
if [[ -z "${build_depends[$m]}" ]]; then
2287+
if [[ -z ${build_depends[$m]} ]]; then
22882288
(module="$m" module_version="$v" kernelver="$kernelver" arch="$arch" install_module)
22892289
status=$?
2290-
if [ "$status" = 0 ]; then
2290+
if (( status == 0 )); then
22912291
installed_modules[${#installed_modules[@]}]="$m"
22922292
progress=$(($progress +1))
2293-
elif [ "$status" = 77 ]; then
2293+
elif (( status == 77 )); then
22942294
skipped_modules[${#skipped_modules[@]}]="$m"
22952295
progress=$(($progress +1))
22962296
else
@@ -2309,19 +2309,19 @@ autoinstall() {
23092309

23102310
# Step 4: Keep going if at least one module was installed during
23112311
# this iteration.
2312-
[[ "$progress" -gt 0 ]] || break;
2312+
(( progress > 0 )) || break;
23132313

23142314
done
23152315

2316-
if [[ "${#installed_modules[@]}" -gt 0 ]]; then
2316+
if (( ${#installed_modules[@]} > 0 )); then
23172317
echo "dkms autoinstall on $kernelver/$arch succeeded for ${installed_modules[@]}"
23182318
fi
23192319

2320-
if [[ "${#skipped_modules[@]}" -gt 0 ]]; then
2320+
if (( ${#skipped_modules[@]} > 0 )); then
23212321
echo "dkms autoinstall on $kernelver/$arch was skipped for ${skipped_modules[@]}"
23222322
fi
23232323

2324-
if [[ "${#failed_modules[@]}" -gt 0 ]]; then
2324+
if (( ${#failed_modules[@]} > 0 )); then
23252325
echo "dkms autoinstall on $kernelver/$arch failed for ${failed_modules[@]}"
23262326
fi
23272327

@@ -2330,7 +2330,7 @@ autoinstall() {
23302330
echo "$m/$v autoinstall failed due to missing dependencies: ${build_depends[$m]}"
23312331
done
23322332

2333-
if [[ "${#failed_modules[@]}" -gt 0 || "${#to_install[@]}" -gt 0 ]]; then
2333+
if (( ${#failed_modules[@]} > 0 || ${#to_install[@]} > 0 )); then
23342334
die 11 $"One or more modules failed to install during autoinstall." \
23352335
$"Refer to previous errors for more information."
23362336
fi
@@ -2363,7 +2363,7 @@ symlink_modules=""
23632363
# Check that we can write temporary files
23642364
tmpfile=$(mktemp_or_die)
23652365
echo "Hello, DKMS!" > "$tmpfile"
2366-
if [ "$(cat "$tmpfile")" != "Hello, DKMS!" ]; then
2366+
if [[ "$(cat "$tmpfile")" != "Hello, DKMS!" ]]; then
23672367
warn $"dkms will not function properly without some free space in \$TMPDIR ($tmp_location)."
23682368
fi
23692369
rm -f "$tmpfile"
@@ -2542,7 +2542,7 @@ done
25422542

25432543
# The <(cmd) idiom does not work if /proc is not mounted
25442544
read line < <(echo "Hello, DKMS!")
2545-
if [ "$line" != "Hello, DKMS!" ]; then
2545+
if [[ $line != "Hello, DKMS!" ]]; then
25462546
warn $"dkms will not function properly if /proc is not mounted."
25472547
fi
25482548

0 commit comments

Comments
 (0)