Skip to content

Commit cdfe716

Browse files
committed
Shellcheck fixes and error silencing
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent 950b06d commit cdfe716

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1171
-730
lines changed

boards/librem_mini/initrd/bin/board-init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
set -o pipefail
33

4+
# shellcheck disable=SC1091
45
. /tmp/config
56

67
# If CONFIG_AUTOMATIC_POWERON is set, always set the EC BRAM setting during

boards/librem_mini_v2/initrd/bin/board-init.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
set -o pipefail
33

4+
# shellcheck disable=SC1091
45
. /tmp/config
56

67
# If CONFIG_AUTOMATIC_POWERON is set, always set the EC BRAM setting during

initrd/bin/basic-autoboot.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
set -o pipefail
33

4+
# shellcheck source=initrd/etc/functions.sh
45
. /etc/functions.sh
56

67
BOOT_MENU_OPTIONS=/tmp/basic-autoboot-options

initrd/bin/cbfs-init.sh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
set -e -o pipefail
3+
# shellcheck source=initrd/etc/functions.sh
34
. /etc/functions.sh
45

56
# CBFS extraction and measurement
@@ -16,24 +17,32 @@ if [ -z "$CONFIG_PCR" ]; then
1617
CONFIG_PCR=7
1718
fi
1819

20+
DEBUG "CONFIG_CBFS_VIA_FLASHPROG='$CONFIG_CBFS_VIA_FLASHPROG'"
21+
1922
if [ "$CONFIG_CBFS_VIA_FLASHPROG" = "y" ]; then
2023
# Use flashrom directly, because we don't have /tmp/config with params for flash.sh yet
2124
/bin/flashprog -p internal --fmap -i COREBOOT -i FMAP -r /tmp/cbfs-init.rom \
22-
&& CBFS_ARG=" -o /tmp/cbfs-init.rom" \
25+
&& CBFS_ARG="-o /tmp/cbfs-init.rom" \
2326
|| echo "Failed reading Heads configuration from flash! Some features may not be available."
2427
fi
2528

29+
DEBUG "CBFS_ARG='$CBFS_ARG'"
30+
2631
# Load individual files
27-
cbfsfiles=`cbfs -t 50 -l $CBFS_ARG 2>/dev/null | grep "^heads/initrd/"`
32+
# shellcheck disable=SC2086
33+
cbfsfiles=$(cbfs -t 50 $CBFS_ARG -l 2>/dev/null | grep "^heads/initrd/")
34+
DEBUG "cbfsfiles='$cbfsfiles'"
2835

29-
for cbfsname in `echo $cbfsfiles`; do
36+
for cbfsname in $cbfsfiles; do
3037
filename=${cbfsname:12}
31-
if [ ! -z "$filename" ]; then
32-
mkdir -p `dirname $filename` \
38+
if [ -n "$filename" ]; then
39+
mkdir -p "$(dirname "$filename")" \
3340
|| die "$filename: mkdir failed"
3441
INFO "Extracting CBFS file $cbfsname into $filename"
35-
cbfs -t 50 $CBFS_ARG -r $cbfsname > "$filename" \
42+
# shellcheck disable=SC2086
43+
cbfs -t 50 $CBFS_ARG -r "$cbfsname" > "$filename" \
3644
|| die "$filename: cbfs file read failed"
45+
DEBUG "Extracted $cbfsname to $filename"
3746
if [ "$CONFIG_TPM" = "y" ]; then
3847
TRACE_FUNC
3948
INFO "TPM: Extending PCR[$CONFIG_PCR] with filename $filename and then its content"

initrd/bin/cbfs.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/bin/bash
22
set -e -o pipefail
3+
# shellcheck source=initrd/etc/functions.sh
34
. /etc/functions.sh
5+
# /tmp/config is generated at runtime and cannot be followed by shellcheck
6+
# shellcheck disable=SC1091
47
. /tmp/config
58

69
TRACE_FUNC
710

811
if pnor "$2" -r HBI > /tmp/pnor.part 2>/dev/null; then
9-
cbfs "$@" -o /tmp/pnor.part && pnor "$2" -w HBI < /tmp/pnor.part
12+
cbfs "$@" -o /tmp/pnor.part && pnor "$2" -w HBI < /tmp/pnor.part
1013
else
11-
cbfs "$@"
14+
cbfs "$@"
1215
fi

initrd/bin/change-time.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ echo
7070

7171
echo "Press Enter to return to the menu"
7272
echo
73-
read -r nothing
73+
read -r

initrd/bin/config-gui.sh

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/bin/bash
22
#
33
set -e -o pipefail
4+
5+
# shellcheck source=initrd/etc/functions.sh
46
. /etc/functions.sh
7+
# shellcheck source=initrd/etc/gui_functions.sh
58
. /etc/gui_functions.sh
9+
# shellcheck disable=SC1091
610
. /tmp/config
711

812
TRACE_FUNC
@@ -22,12 +26,13 @@ read_rom() {
2226
}
2327

2428
while true; do
25-
if [ ! -z "$param" ]; then
29+
if [ -n "$param" ]; then
2630
# use first char from parameter
2731
menu_choice=${param::1}
2832
unset param
2933
else
3034
# Re-source config because we change it when an option is toggled
35+
# shellcheck disable=SC1091
3136
. /tmp/config
3237

3338
dynamic_config_options=(
@@ -100,6 +105,7 @@ while true; do
100105
)
101106

102107
unset menu_choice
108+
# shellcheck disable=SC2086
103109
whiptail_type $BG_COLOR_MAIN_MENU --title "Config Management Menu" \
104110
--menu "This menu lets you change settings for the current BIOS session.\n\nAll changes will revert after a reboot,\n\nunless you also save them to the running BIOS." 0 80 10 \
105111
"${dynamic_config_options[@]}" \
@@ -113,6 +119,7 @@ while true; do
113119
unset CONFIG_FINALIZE_PLATFORM_LOCKING
114120
replace_config /etc/config.user "CONFIG_FINALIZE_PLATFORM_LOCKING" "n"
115121
combine_configs
122+
# shellcheck disable=SC1091
116123
. /tmp/config
117124
;;
118125
"x")
@@ -126,16 +133,16 @@ while true; do
126133
exit 1
127134
fi
128135
# filter out extraneous options
129-
>/tmp/boot_device_list.txt
130-
for i in $(cat /tmp/disklist.txt); do
136+
: >/tmp/boot_device_list.txt
137+
while read -r i; do
131138
# remove block device from list if numeric partitions exist, since not bootable
132-
DEV_NUM_PARTITIONS=$(($(ls -1 $i* | wc -l) - 1))
139+
DEV_NUM_PARTITIONS=$(($(find "$i"* | wc -l) - 1))
133140
if [ ${DEV_NUM_PARTITIONS} -eq 0 ]; then
134-
echo $i >>/tmp/boot_device_list.txt
141+
echo "$i" >>/tmp/boot_device_list.txt
135142
else
136-
ls $i* | tail -${DEV_NUM_PARTITIONS} >>/tmp/boot_device_list.txt
143+
find "$i"* | tail -${DEV_NUM_PARTITIONS} >>/tmp/boot_device_list.txt
137144
fi
138-
done
145+
done < /tmp/disklist.txt
139146
file_selector "/tmp/boot_device_list.txt" \
140147
"Choose the default /boot device.\n\n${CURRENT_OPTION:+\n\nCurrently set to }$CURRENT_OPTION." \
141148
"Boot Device Selection"
@@ -150,7 +157,7 @@ while true; do
150157
umount /boot 2>/dev/null
151158
fi
152159
# mount newly selected /boot device
153-
if ! mount -o ro $SELECTED_FILE /boot 2>/tmp/error; then
160+
if ! mount -o ro "$SELECTED_FILE" /boot 2>/tmp/error; then
154161
ERROR=$(cat /tmp/error)
155162
whiptail_error --title 'ERROR: unable to mount /boot' \
156163
--msgbox " $ERROR\n\n" 0 80
@@ -197,14 +204,14 @@ while true; do
197204

198205
# clear GPG keys and user settings
199206
for i in $(cbfs.sh -o /tmp/config-gui.rom -l | grep -e "heads/"); do
200-
cbfs.sh -o /tmp/config-gui.rom -d $i
207+
cbfs.sh -o /tmp/config-gui.rom -d "$i"
201208
done
202209
# flash cleared ROM
203210
/bin/flash.sh -c /tmp/config-gui.rom
204211

205212
# reset TPM if present
206213
if [ "$CONFIG_TPM" = "y" ]; then
207-
/bin/tpm-reset.sh
214+
/bin/tpm-reset.sh
208215
fi
209216
whiptail --title 'Configuration Reset Updated Successfully' \
210217
--msgbox "Configuration reset and BIOS updated successfully.\n\nPress Enter to reboot" 0 80
@@ -216,17 +223,19 @@ while true; do
216223
"R")
217224
CURRENT_OPTION="$(load_config_value CONFIG_ROOT_DEV)"
218225
fdisk -l 2>/dev/null | grep "Disk /dev/" | cut -f2 -d " " | cut -f1 -d ":" >/tmp/disklist.txt
226+
INFO "DEBUG disklist: $(cat /tmp/disklist.txt)"
219227
# filter out extraneous options
220-
>/tmp/root_device_list.txt
221-
for i in $(cat /tmp/disklist.txt); do
228+
true > /tmp/root_device_list.txt
229+
while read -r i; do
222230
# remove block device from list if numeric partitions exist, since not bootable
223-
DEV_NUM_PARTITIONS=$(($(ls -1 $i* | wc -l) - 1))
231+
DEV_NUM_PARTITIONS=$(($(find "$i"* | wc -l) - 1))
224232
if [ ${DEV_NUM_PARTITIONS} -eq 0 ]; then
225-
echo $i >>/tmp/root_device_list.txt
233+
echo "$i" >>/tmp/root_device_list.txt
226234
else
227-
ls $i* | tail -${DEV_NUM_PARTITIONS} >>/tmp/root_device_list.txt
235+
find "$i"* | tail -${DEV_NUM_PARTITIONS} >>/tmp/root_device_list.txt
228236
fi
229-
done
237+
done < /tmp/disklist.txt
238+
INFO "DEBUG root_device_list: $(cat /tmp/root_device_list.txt)"
230239
file_selector "/tmp/root_device_list.txt" \
231240
"Choose the default root device.${CURRENT_OPTION:+\n\nCurrently set to }$CURRENT_OPTION." \
232241
"Root Device Selection"
@@ -256,7 +265,7 @@ while true; do
256265
read -r NEW_CONFIG_ROOT_DIRLIST
257266

258267
# strip any leading forward slashes
259-
NEW_CONFIG_ROOT_DIRLIST=$(echo $NEW_CONFIG_ROOT_DIRLIST | sed -e 's/^\///;s/ \// /g')
268+
NEW_CONFIG_ROOT_DIRLIST=$(echo "$NEW_CONFIG_ROOT_DIRLIST" | sed -e 's/^\///;s/ \// /g')
260269

261270
#check if list empty
262271
if [ -z "$NEW_CONFIG_ROOT_DIRLIST" ]; then
@@ -618,7 +627,7 @@ while true; do
618627
echo "You can now test your keyboard layout in this shell."
619628
echo "Press Enter when done testing to continue..."
620629
echo "------------------------------------------------------------"
621-
read -p $'\nTest your keymap now. Press Enter to continue:\n' dummy
630+
read -r -p $'\nTest your keymap now. Press Enter to continue:\n' _
622631
if whiptail --title "Keep this keymap?" \
623632
--yesno "Do you want to use this keymap?\n\n$SELECTED_KEYMAP" 0 70; then
624633
set_user_config "CONFIG_KEYBOARD_KEYMAP" "$SELECTED_KEYMAP"
@@ -632,6 +641,7 @@ while true; do
632641
;;
633642
"Z")
634643
unset output_choice
644+
# shellcheck disable=SC2086
635645
whiptail_type $BG_COLOR_MAIN_MENU --title "Informational / Debug Output" \
636646
--menu "$CONFIG_BRAND_NAME can display informational or debug output.\n\nChoose the output level:" 0 80 10 \
637647
0 'None - Show no extra output' \

initrd/bin/flash-gui.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/bin/bash
22
#
33
set -e -o pipefail
4+
# shellcheck source=initrd/etc/functions.sh
45
. /etc/functions.sh
6+
# shellcheck source=initrd/etc/gui_functions.sh
57
. /etc/gui_functions.sh
6-
. /tmp/config
8+
# shellcheck disable=SC1091
9+
. /tmp/config
710

811
TRACE_FUNC
912

@@ -42,6 +45,7 @@ single_glob() {
4245

4346
while true; do
4447
unset menu_choice
48+
# shellcheck disable=SC2086
4549
whiptail_type $BG_COLOR_MAIN_MENU --title "Firmware Management Menu" \
4650
--menu "Select the firmware function to perform\n\nRetaining settings copies existing settings to the new firmware:\n* Keeps your GPG keyring\n* Keeps changes to the default /boot device\n\nErasing settings uses the new firmware as-is:\n* Erases any existing GPG keyring\n* Restores firmware to default factory settings\n* Clears out /boot signatures\n\nIf you are just updating your firmware, you probably want to retain\nyour settings." 0 80 10 \
4751
'f' ' Flash the firmware with a new ROM, retain settings' \

initrd/bin/flash.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# NOTE: This script is used on legacy-flash boards and runs with busybox ash,
44
# not bash
55
set -e -o pipefail
6+
# shellcheck source=initrd/etc/functions.sh
67
. /etc/functions.sh
8+
# shellcheck disable=SC1091
79
. /tmp/config
810

911
echo
@@ -26,29 +28,29 @@ flash_rom() {
2628
$CONFIG_FLASH_OPTIONS -r "${ROM}" \
2729
|| recovery "Backup to $ROM failed"
2830
else
29-
cp "$ROM" /tmp/${CONFIG_BOARD}.rom
30-
sha256sum /tmp/${CONFIG_BOARD}.rom
31+
cp "$ROM" /tmp/"${CONFIG_BOARD}".rom
32+
sha256sum /tmp/"${CONFIG_BOARD}".rom
3133
if [ "$CLEAN" -eq 0 ]; then
32-
preserve_rom /tmp/${CONFIG_BOARD}.rom \
34+
preserve_rom /tmp/"${CONFIG_BOARD}".rom \
3335
|| recovery "$ROM: Config preservation failed"
3436
fi
3537
# persist serial number from CBFS
3638
if cbfs.sh -r serial_number > /tmp/serial 2>/dev/null; then
3739
echo "Persisting system serial"
38-
cbfs.sh -o /tmp/${CONFIG_BOARD}.rom -d serial_number 2>/dev/null || true
39-
cbfs.sh -o /tmp/${CONFIG_BOARD}.rom -a serial_number -f /tmp/serial
40+
cbfs.sh -o /tmp/"${CONFIG_BOARD}".rom -d serial_number 2>/dev/null || true
41+
cbfs.sh -o /tmp/"${CONFIG_BOARD}".rom -a serial_number -f /tmp/serial
4042
fi
4143
# persist PCHSTRP9 from flash descriptor
4244
if [ "$CONFIG_BOARD" = "librem_l1um" ]; then
4345
echo "Persisting PCHSTRP9"
4446
$CONFIG_FLASH_OPTIONS -r /tmp/ifd.bin --ifd -i fd >/dev/null 2>&1 \
4547
|| die "Failed to read flash descriptor"
4648
dd if=/tmp/ifd.bin bs=1 count=4 skip=292 of=/tmp/pchstrp9.bin >/dev/null 2>&1
47-
dd if=/tmp/pchstrp9.bin bs=1 count=4 seek=292 of=/tmp/${CONFIG_BOARD}.rom conv=notrunc >/dev/null 2>&1
49+
dd if=/tmp/pchstrp9.bin bs=1 count=4 seek=292 of=/tmp/"${CONFIG_BOARD}".rom conv=notrunc >/dev/null 2>&1
4850
fi
4951

5052
warn "Do not power off computer. Updating firmware, this will take a few minutes"
51-
$CONFIG_FLASH_OPTIONS -w /tmp/${CONFIG_BOARD}.rom 2>&1 \
53+
$CONFIG_FLASH_OPTIONS -w /tmp/"${CONFIG_BOARD}".rom 2>&1 \
5254
|| recovery "$ROM: Flash failed"
5355
fi
5456
}
@@ -61,7 +63,7 @@ elif [ "$1" == "-r" ]; then
6163
CLEAN=0
6264
READ=1
6365
ROM="$2"
64-
touch $ROM
66+
touch "$ROM"
6567
else
6668
CLEAN=0
6769
READ=0
@@ -77,7 +79,7 @@ if [ "$READ" -eq 0 ] && [ "${ROM##*.}" = tgz ]; then
7779
rm -rf /tmp/verified_rom
7880
mkdir /tmp/verified_rom
7981

80-
tar -C /tmp/verified_rom -xf $ROM || die "Rom archive $ROM could not be extracted"
82+
tar -C /tmp/verified_rom -xf "$ROM" || die "Rom archive $ROM could not be extracted"
8183
if ! (cd /tmp/verified_rom/ && sha256sum -cs sha256sum.txt); then
8284
die "Provided tgz image did not pass hash verification"
8385
fi
@@ -90,9 +92,9 @@ if [ "$READ" -eq 0 ] && [ "${ROM##*.}" = tgz ]; then
9092
bootblock=$(echo /tmp/verified_rom/*.bootblock)
9193
rom=$(echo /tmp/verified_rom/*.rom)
9294
kernel=$(echo /tmp/verified_rom/*-zImage.bundled)
93-
pnor /tmp/flash.sh.bak -aw HBB < $bootblock
94-
pnor /tmp/flash.sh.bak -aw HBI < $rom
95-
pnor /tmp/flash.sh.bak -aw BOOTKERNEL < $kernel
95+
pnor /tmp/flash.sh.bak -aw HBB < "$bootblock"
96+
pnor /tmp/flash.sh.bak -aw HBI < "$rom"
97+
pnor /tmp/flash.sh.bak -aw BOOTKERNEL < "$kernel"
9698
rm -rf /tmp/verified_rom
9799

98100
ROM=/tmp/flash.sh.bak
@@ -101,7 +103,7 @@ if [ "$READ" -eq 0 ] && [ "${ROM##*.}" = tgz ]; then
101103
fi
102104
fi
103105

104-
flash_rom $ROM
106+
flash_rom "$ROM"
105107

106108
# don't leave temporary files lying around
107109
rm -f /tmp/flash.sh.bak

initrd/bin/flashprog-kgpe-d16-openbmc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
# shellcheck source=initrd/etc/functions.sh
23
. /etc/functions.sh
34

45
TRACE_FUNC

0 commit comments

Comments
 (0)