diff --git a/initrd/bin/config-gui.sh b/initrd/bin/config-gui.sh index 67c5fbfa..55b3831c 100755 --- a/initrd/bin/config-gui.sh +++ b/initrd/bin/config-gui.sh @@ -2,7 +2,7 @@ # set -e -o pipefail . /etc/functions -. /etc/config +. /tmp/config file_selector() { FILE="" @@ -49,15 +49,6 @@ file_selector() { exit 1 fi } -replace_config() { - CONFIG_OPTION=$1 - NEW_SETTING=$2 - - awk "gsub(\"^export ${CONFIG_OPTION}=.*\",\"export ${CONFIG_OPTION}=\\\"${NEW_SETTING}\\\"\")" /etc/config > /tmp/config - awk "gsub(\"^${CONFIG_OPTION}=.*\",\"${CONFIG_OPTION}=\\\"${NEW_SETTING}\\\"\")" /etc/config >> /tmp/config - grep -v "^export ${CONFIG_OPTION}=" /etc/config | grep -v "^${CONFIG_OPTION}=" >> /tmp/config - mv /tmp/config /etc/config -} while true; do unset menu_choice @@ -76,7 +67,7 @@ while true; do exit 0 ;; "b" ) - CURRENT_OPTION=`grep 'CONFIG_BOOT_DEV=' /etc/config | cut -f2 -d '=' | tr -d '"'` + CURRENT_OPTION=`grep 'CONFIG_BOOT_DEV=' /tmp/config | cut -f2 -d '=' | tr -d '"'` find /dev -name 'sd*' -o -name 'nvme*' > /tmp/filelist.txt file_selector "/tmp/filelist.txt" "Choose the default /boot device.\n\nCurrently set to $CURRENT_OPTION." if [ "$FILE" == "" ]; then @@ -85,7 +76,8 @@ while true; do SELECTED_FILE=$FILE fi - replace_config "CONFIG_BOOT_DEV" "$SELECTED_FILE" + replace_config /etc/config.user "CONFIG_BOOT_DEV" "$SELECTED_FILE" + combine_configs whiptail --title 'Config change successful' \ --msgbox "The /boot device was successfully changed to $SELECTED_FILE" 16 60 @@ -94,7 +86,7 @@ while true; do whiptail --title 'Insert a USB thumb drive' \ --msgbox "Insert a USB thumb drive so we can detect the device" 16 60 mount-usb - CURRENT_OPTION=`grep 'CONFIG_USB_BOOT_DEV=' /etc/config | cut -f2 -d '=' | tr -d '"'` + CURRENT_OPTION=`grep 'CONFIG_USB_BOOT_DEV=' /tmp/config | cut -f2 -d '=' | tr -d '"'` find /dev -name 'sd*' -o -name 'nvme*' > /tmp/filelist.txt file_selector "/tmp/filelist.txt" "Choose the default USB boot device.\n\nCurrently set to $CURRENT_OPTION." if [ "$FILE" == "" ]; then @@ -103,7 +95,8 @@ while true; do SELECTED_FILE=$FILE fi - replace_config "CONFIG_USB_BOOT_DEV" "$SELECTED_FILE" + replace_config /etc/config.user "CONFIG_USB_BOOT_DEV" "$SELECTED_FILE" + combine_configs whiptail --title 'Config change successful' \ --msgbox "The USB boot device was successfully changed to $SELECTED_FILE" 16 60 @@ -116,10 +109,10 @@ while true; do exit 1 fi - if (cbfs -o /tmp/config-gui.rom -l | grep -q "heads/initrd/etc/config") then - cbfs -o /tmp/config-gui.rom -d "heads/initrd/etc/config" + if (cbfs -o /tmp/config-gui.rom -l | grep -q "heads/initrd/etc/config.user") then + cbfs -o /tmp/config-gui.rom -d "heads/initrd/etc/config.user" fi - cbfs -o /tmp/config-gui.rom -a "heads/initrd/etc/config" -f /etc/config + cbfs -o /tmp/config-gui.rom -a "heads/initrd/etc/config.user" -f /etc/config.user if (whiptail --title 'Update ROM?' \ --yesno "This will reflash your BIOS with the updated version\n\nDo you want to proceed?" 16 90) then diff --git a/initrd/bin/flash-gui.sh b/initrd/bin/flash-gui.sh index 191d977b..277a4fae 100755 --- a/initrd/bin/flash-gui.sh +++ b/initrd/bin/flash-gui.sh @@ -2,7 +2,7 @@ # set -e -o pipefail . /etc/functions -. /etc/config +. /tmp/config mount_usb(){ # Mount the USB boot device diff --git a/initrd/bin/flash.sh b/initrd/bin/flash.sh index 4b70ac8a..e89c9a98 100755 --- a/initrd/bin/flash.sh +++ b/initrd/bin/flash.sh @@ -4,7 +4,7 @@ # set -e -o pipefail . /etc/functions -. /etc/config +. /tmp/config case "$CONFIG_BOARD" in librem* ) diff --git a/initrd/bin/generic-init b/initrd/bin/generic-init index c0808e48..b63b0a05 100755 --- a/initrd/bin/generic-init +++ b/initrd/bin/generic-init @@ -2,7 +2,7 @@ # Boot from a local disk installation . /etc/functions -. /etc/config +. /tmp/config mount_boot() { diff --git a/initrd/bin/gui-init b/initrd/bin/gui-init index 20f12280..32dfc920 100755 --- a/initrd/bin/gui-init +++ b/initrd/bin/gui-init @@ -4,7 +4,7 @@ CONFIG_BOOT_GUI_MENU_NAME='Heads Boot Menu' . /etc/functions -. /etc/config +. /tmp/config mount_boot() { diff --git a/initrd/bin/kexec-boot b/initrd/bin/kexec-boot index 7d7d8367..49e48aee 100755 --- a/initrd/bin/kexec-boot +++ b/initrd/bin/kexec-boot @@ -1,7 +1,7 @@ #!/bin/sh # Launches kexec from saved configuration entries set -e -o pipefail -. /etc/config +. /tmp/config . /etc/functions dryrun="n" diff --git a/initrd/bin/kexec-iso-init b/initrd/bin/kexec-iso-init index 755ebba6..ebe48fe0 100755 --- a/initrd/bin/kexec-iso-init +++ b/initrd/bin/kexec-iso-init @@ -2,7 +2,7 @@ # Boot from signed ISO set -e -o pipefail . /etc/functions -. /etc/config +. /tmp/config MOUNTED_ISO_PATH="$1" ISO_PATH="$2" diff --git a/initrd/bin/kexec-save-default b/initrd/bin/kexec-save-default index 0bbaa100..85ac3f27 100755 --- a/initrd/bin/kexec-save-default +++ b/initrd/bin/kexec-save-default @@ -1,7 +1,7 @@ #!/bin/sh # Save these options to be the persistent default set -e -o pipefail -. /etc/config +. /tmp/config . /etc/functions while getopts "b:d:p:i:" arg; do diff --git a/initrd/bin/kexec-seal-key b/initrd/bin/kexec-seal-key index da5a187e..f574b558 100755 --- a/initrd/bin/kexec-seal-key +++ b/initrd/bin/kexec-seal-key @@ -11,7 +11,7 @@ TPM_SEALED="/tmp/secret/secret.sealed" RECOVERY_KEY="/tmp/secret/recovery.key" . /etc/functions -. /etc/config +. /tmp/config paramsdir=$1 if [ -z "$paramsdir" ]; then diff --git a/initrd/bin/kexec-select-boot b/initrd/bin/kexec-select-boot index 4a1f2a73..ab8002fe 100755 --- a/initrd/bin/kexec-select-boot +++ b/initrd/bin/kexec-select-boot @@ -1,7 +1,7 @@ #!/bin/sh # Generic configurable boot script via kexec set -e -o pipefail -. /etc/config +. /tmp/config . /etc/functions add="" diff --git a/initrd/bin/kexec-sign-config b/initrd/bin/kexec-sign-config index 1ff9f46c..23cdf28d 100755 --- a/initrd/bin/kexec-sign-config +++ b/initrd/bin/kexec-sign-config @@ -1,7 +1,7 @@ #!/bin/sh # Sign a valid directory of kexec params set -e -o pipefail -. /etc/config +. /tmp/config . /etc/functions rollback="n" diff --git a/initrd/bin/usb-init b/initrd/bin/usb-init index 5ddfdff1..4a52b262 100755 --- a/initrd/bin/usb-init +++ b/initrd/bin/usb-init @@ -2,7 +2,7 @@ # Boot a USB installation . /etc/functions -. /etc/config +. /tmp/config if [ "$CONFIG_TPM" = "y" ]; then # Extend PCR4 as soon as possible diff --git a/initrd/bin/usb-scan b/initrd/bin/usb-scan index 57f6879b..6d3eda27 100755 --- a/initrd/bin/usb-scan +++ b/initrd/bin/usb-scan @@ -2,7 +2,7 @@ # Scan for USB installation options set -e -o pipefail . /etc/functions -. /etc/config +. /tmp/config # Unmount any previous boot device if grep -q /boot /proc/mounts ; then diff --git a/initrd/bin/x230-flash.init b/initrd/bin/x230-flash.init index a4d22c0f..e02dcf5d 100755 --- a/initrd/bin/x230-flash.init +++ b/initrd/bin/x230-flash.init @@ -3,7 +3,7 @@ # invoke a recovery shell and prompt the user for how to proceed . /etc/functions -. /etc/config +. /tmp/config insmod /lib/modules/ehci-hcd.ko insmod /lib/modules/ehci-pci.ko diff --git a/initrd/etc/functions b/initrd/etc/functions index 4488476a..e556c960 100755 --- a/initrd/etc/functions +++ b/initrd/etc/functions @@ -217,3 +217,20 @@ preserve_rom() { fi done } +replace_config() { + CONFIG_FILE=$1 + CONFIG_OPTION=$2 + NEW_SETTING=$3 + +# first pull out the existing option from the global config and place in a tmp file + awk "gsub(\"^export ${CONFIG_OPTION}=.*\",\"export ${CONFIG_OPTION}=\\\"${NEW_SETTING}\\\"\")" /tmp/config > ${CONFIG_FILE}.tmp + awk "gsub(\"^${CONFIG_OPTION}=.*\",\"${CONFIG_OPTION}=\\\"${NEW_SETTING}\\\"\")" /tmp/config >> ${CONFIG_FILE}.tmp + +# then copy any remaining settings from the existing config file, minus the option you changed + grep -v "^export ${CONFIG_OPTION}=" ${CONFIG_FILE} | grep -v "^${CONFIG_OPTION}=" >> ${CONFIG_FILE}.tmp + + mv ${CONFIG_FILE}.tmp ${CONFIG_FILE} +} +combine_configs() { + sort /etc/config* | uniq > /tmp/config +} diff --git a/initrd/init b/initrd/init index d489f6ae..4410c6fb 100755 --- a/initrd/init +++ b/initrd/init @@ -40,7 +40,8 @@ hwclock -l -s # Read the system configuration parameters . /etc/functions -. /etc/config +combine_configs +. /tmp/config # Add our boot devices into the /etc/fstab, if they are defined # in the configuration file.