11#! /bin/bash
22#
33set -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
812TRACE_FUNC
@@ -22,12 +26,13 @@ read_rom() {
2226}
2327
2428while 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\n Currently 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\n Currently 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 $' \n Test your keymap now. Press Enter to continue:\n ' dummy
630+ read -r - p $' \n Test 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' \
0 commit comments