From e191c72a58272ca0bb13217167a6fb44056194a4 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 12 Feb 2025 18:25:58 +0000 Subject: [PATCH 01/10] Whitespace tidyups --- raspi-config | 227 +++++++++++++++++++++++++++------------------------ 1 file changed, 119 insertions(+), 108 deletions(-) diff --git a/raspi-config b/raspi-config index cf69a52..5200a07 100755 --- a/raspi-config +++ b/raspi-config @@ -140,7 +140,7 @@ is_ssh() { } is_kms() { - return 0 + return 0 } is_pulseaudio() { @@ -381,7 +381,7 @@ for line in file:lines() do end end if not found then - print(0) + print(0) end EOF } @@ -447,7 +447,10 @@ do_overscan_kms() { if [ "$INTERACTIVE" = True ]; then NDEVS=$(xrandr -q | grep -c connected) if [ $NDEVS -gt 1 ] ; then - DEV=$(whiptail --menu "Select the output for which overscan compensation is to be set" 20 60 10 "1" "HDMI-1" "2" "HDMI-2" 3>&1 1>&2 2>&3) + DEV=$(whiptail --menu "Select the output for which overscan compensation is to be set" 20 60 10 \ + "1" "HDMI-1" \ + "2" "HDMI-2" \ + 3>&1 1>&2 2>&3) if [ $? -eq 1 ] ; then return fi @@ -978,20 +981,20 @@ system instability, try a more modest overclock. Hold down shift during boot to temporarily disable overclock. See https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md for more information.\ " 20 70 1 - if is_pione; then - OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \ - "None" "700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ - "Modest" "800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ - "Medium" "900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt" \ - "High" "950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt" \ - "Turbo" "1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt" \ - 3>&1 1>&2 2>&3) - elif is_pitwo; then - OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \ - "None" "900MHz ARM, 250MHz core, 450MHz SDRAM, 0 overvolt" \ - "High" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" \ - 3>&1 1>&2 2>&3) - fi + if is_pione; then + OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \ + "None" "700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ + "Modest" "800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ + "Medium" "900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt" \ + "High" "950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt" \ + "Turbo" "1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt" \ + 3>&1 1>&2 2>&3) + elif is_pitwo; then + OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \ + "None" "900MHz ARM, 250MHz core, 450MHz SDRAM, 0 overvolt" \ + "High" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" \ + 3>&1 1>&2 2>&3) + fi else OVERCLOCK=$1 true @@ -1939,32 +1942,32 @@ EOF } get_bootloader_filename() { - CURDATE=$(date -d "$(vcgencmd bootloader_version | head -n 1)" +%Y%m%d) - FILNAME="" - EEBASE=$(rpi-eeprom-update | grep RELEASE | sed 's/.*(//g' | sed 's/[^\/]*)//g') - if grep FIRMWARE_RELEASE_STATUS /etc/default/rpi-eeprom-update | egrep -Eq "stable|latest"; then - EEPATH="${EEBASE}/latest/pieeprom*.bin" - else - EEPATH="${EEBASE}/default/pieeprom*.bin" - fi - EXACT_MATCH=0 - for filename in $(find $EEPATH -name "pieeprom*.bin" 2>/dev/null | sort); do - FILDATE=$(date -d "$(echo $filename | sed 's/.*\///g' | cut -d - -f 2- | cut -d . -f 1)" +%Y%m%d) - FILNAME=$filename - if [ $FILDATE -eq $CURDATE ]; then - EXACT_MATCH=1 - break - fi - done - if [ $EXACT_MATCH != 1 ]; then - if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Current EEPROM version $(date -d $CURDATE +%Y-%m-%d) or newer not found.\n\nTry updating the rpi-eeprom APT package.\n\nInstall latest local $(basename $FILNAME) anyway?" 20 70 3 - DEFAULTS=$? - if [ "$DEFAULTS" -ne 0 ]; then - FILNAME="none" # no - fi + CURDATE=$(date -d "$(vcgencmd bootloader_version | head -n 1)" +%Y%m%d) + FILNAME="" + EEBASE=$(rpi-eeprom-update | grep RELEASE | sed 's/.*(//g' | sed 's/[^\/]*)//g') + if grep FIRMWARE_RELEASE_STATUS /etc/default/rpi-eeprom-update | egrep -Eq "stable|latest"; then + EEPATH="${EEBASE}/latest/pieeprom*.bin" + else + EEPATH="${EEBASE}/default/pieeprom*.bin" + fi + EXACT_MATCH=0 + for filename in $(find $EEPATH -name "pieeprom*.bin" 2>/dev/null | sort); do + FILDATE=$(date -d "$(echo $filename | sed 's/.*\///g' | cut -d - -f 2- | cut -d . -f 1)" +%Y%m%d) + FILNAME=$filename + if [ $FILDATE -eq $CURDATE ]; then + EXACT_MATCH=1 + break + fi + done + if [ $EXACT_MATCH != 1 ]; then + if [ "$INTERACTIVE" = True ]; then + whiptail --yesno "Current EEPROM version $(date -d $CURDATE +%Y-%m-%d) or newer not found.\n\nTry updating the rpi-eeprom APT package.\n\nInstall latest local $(basename $FILNAME) anyway?" 20 70 3 + DEFAULTS=$? + if [ "$DEFAULTS" -ne 0 ]; then + FILNAME="none" # no fi - fi + fi + fi } do_network_install_ui() { @@ -1981,23 +1984,23 @@ do_network_install_ui() { if [ $? -eq 0 ]; then get_bootloader_filename if [ "${FILNAME}" = "none" ]; then - if [ "$INTERACTIVE" = True ]; then - return 0 - else - return 1 - fi + if [ "$INTERACTIVE" = True ]; then + return 0 + else + return 1 + fi fi EECFG=$(mktemp) rpi-eeprom-config > $EECFG sed $EECFG -i -e "/NET_INSTALL_AT_POWER_ON/d" case "$BOOTOPT" in B1*) - echo "NET_INSTALL_AT_POWER_ON=1" >> $EECFG - ;; + echo "NET_INSTALL_AT_POWER_ON=1" >> $EECFG + ;; B2*) - # NET_INSTALL_AT_POWER_ON default value is 0 - true - ;; + # NET_INSTALL_AT_POWER_ON default value is 0 + true + ;; *) whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 return 1 @@ -2006,14 +2009,14 @@ do_network_install_ui() { rpi-eeprom-config --apply $EECFG $FILNAME ASK_TO_REBOOT=1 fi - } +} do_libliftoff() { if [ "$INTERACTIVE" = True ]; then RET=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "libliftoff Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ - "L1 Disable" "Disable libliftoff hardware overlays" \ - "L2 Enable" "Enable libliftoff hardware overlays (experimental)" \ - 3>&1 1>&2 2>&3) + "L1 Disable" "Disable libliftoff hardware overlays" \ + "L2 Enable" "Enable libliftoff hardware overlays (experimental)" \ + 3>&1 1>&2 2>&3) else RET=$1 true @@ -2082,11 +2085,11 @@ do_power_off_on_halt() { if [ $? -eq 0 ]; then get_bootloader_filename if [ "${FILNAME}" = "none" ]; then - if [ "$INTERACTIVE" = True ]; then - return 0 - else - return 1 - fi + if [ "$INTERACTIVE" = True ]; then + return 0 + else + return 1 + fi fi EECFG=$(mktemp) rpi-eeprom-config > "$EECFG" @@ -2094,14 +2097,14 @@ do_power_off_on_halt() { sed "$EECFG" -i -e "/WAKE_ON_GPIO/d" case "$BOOTOPT" in B1*) - echo "POWER_OFF_ON_HALT=1" >> "$EECFG" - echo "WAKE_ON_GPIO=0" >> "$EECFG" - ;; + echo "POWER_OFF_ON_HALT=1" >> "$EECFG" + echo "WAKE_ON_GPIO=0" >> "$EECFG" + ;; B2*) - echo "POWER_OFF_ON_HALT=0" >> "$EECFG" - echo "WAKE_ON_GPIO=1" >> "$EECFG" - true - ;; + echo "POWER_OFF_ON_HALT=0" >> "$EECFG" + echo "WAKE_ON_GPIO=1" >> "$EECFG" + true + ;; *) whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 return 1 @@ -2110,7 +2113,7 @@ do_power_off_on_halt() { rpi-eeprom-config --apply "$EECFG" "$FILNAME" ASK_TO_REBOOT=1 fi - } +} do_boot_order() { if [ "$INTERACTIVE" = True ]; then @@ -2131,9 +2134,9 @@ do_boot_order() { case "$BOOTOPT" in B1*) if is_pifive; then - ORD=0xf461 + ORD=0xf461 else - ORD=0xf41 + ORD=0xf41 fi if ! grep -q "BOOT_ORDER" $EECFG ; then sed $EECFG -i -e "\$a[all]\nBOOT_ORDER=${ORD}" @@ -2144,9 +2147,9 @@ do_boot_order() { ;; B2*) if is_pifive; then - ORD=0xf146 + ORD=0xf146 else - ORD=0xf14 + ORD=0xf14 fi if ! grep -q "BOOT_ORDER" $EECFG ; then sed $EECFG -i -e "\$a[all]\nBOOT_ORDER=${ORD}" @@ -2170,11 +2173,11 @@ do_boot_order() { esac get_bootloader_filename if [ "${FILNAME}" = "none" ]; then - if [ "$INTERACTIVE" = True ]; then - return 0 - else - return 1 - fi + if [ "$INTERACTIVE" = True ]; then + return 0 + else + return 1 + fi fi rpi-eeprom-config --apply $EECFG $FILNAME ASK_TO_REBOOT=1 @@ -2219,15 +2222,15 @@ do_boot_rom() { if [ "$DEFAULTS" -eq 0 ]; then # yes get_bootloader_filename if [ "${FILNAME}" = "none" ]; then - if [ "$INTERACTIVE" = True ]; then - return 0 - else - return 1 - fi + if [ "$INTERACTIVE" = True ]; then + return 0 + else + return 1 + fi fi rpi-eeprom-update -d -f $FILNAME if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Bootloader reset to default configuration" 20 60 2 + whiptail --msgbox "Bootloader reset to default configuration" 20 60 2 fi else if [ "$INTERACTIVE" = True ]; then @@ -2650,15 +2653,15 @@ do_wayland() { if [ "$INTERACTIVE" = True ]; then if [ -f /usr/bin/labwc ]; then RET=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Wayland Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ - "W1 X11" "Openbox window manager with X11 backend" \ - "W2 Wayfire" "Wayfire window manager with Wayland backend" \ - "W3 Labwc" "Labwc window manager with Wayland backend" \ - 3>&1 1>&2 2>&3) + "W1 X11" "Openbox window manager with X11 backend" \ + "W2 Wayfire" "Wayfire window manager with Wayland backend" \ + "W3 Labwc" "Labwc window manager with Wayland backend" \ + 3>&1 1>&2 2>&3) else RET=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Wayland Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ - "W1 X11" "Openbox window manager with X11 backend" \ - "W2 Wayfire" "Wayfire window manager with Wayland backend" \ - 3>&1 1>&2 2>&3) + "W1 X11" "Openbox window manager with X11 backend" \ + "W2 Wayfire" "Wayfire window manager with Wayland backend" \ + 3>&1 1>&2 2>&3) fi else RET=$1 @@ -3017,7 +3020,15 @@ do_vnc_resolution() { CUR=640x480 fi FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --default-item $CUR --menu "Set VNC Resolution" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "640x480" "" "720x480" "" "800x600" "" "1024x768" "" "1280x720" "" "1280x1024" "" "1600x1200" "" "1920x1080" "" 3>&1 1>&2 2>&3) + "640x480" "" \ + "720x480" "" \ + "800x600" "" \ + "1024x768" "" \ + "1280x720" "" \ + "1280x1024" "" \ + "1600x1200" "" \ + "1920x1080" "" \ + 3>&1 1>&2 2>&3) RET=$? else FUN=$1 @@ -3091,9 +3102,9 @@ do_wifi_ssid_passphrase() { fi elif ! systemctl -q is-active NetworkManager; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "No supported network connection manager found" 20 60 - fi - return 1 + whiptail --msgbox "No supported network connection manager found" 20 60 + fi + return 1 fi SSID="$1" @@ -3116,8 +3127,8 @@ do_wifi_ssid_passphrase() { # Escape special characters for embedding in regex below ssid="$(echo "$SSID" \ - | sed 's;\\;\\\\;g' \ - | sed -e 's;\.;\\\.;g' \ + | sed -e 's;\\;\\\\;g' \ + -e 's;\.;\\\.;g' \ -e 's;\*;\\\*;g' \ -e 's;\+;\\\+;g' \ -e 's;\?;\\\?;g' \ @@ -3893,20 +3904,20 @@ do_interface_menu() { do_performance_menu() { case "$(get_pi_type)" in [03]) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - 3>&1 1>&2 2>&3) ;; + "P2 Overlay File System" "Enable/disable read-only file system" \ + 3>&1 1>&2 2>&3) ;; [12]) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "P1 Overclock" "Configure CPU overclocking" \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - 3>&1 1>&2 2>&3) ;; + "P1 Overclock" "Configure CPU overclocking" \ + "P2 Overlay File System" "Enable/disable read-only file system" \ + 3>&1 1>&2 2>&3) ;; 4) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - "P3 Fan" "Set behaviour of GPIO case fan" \ - 3>&1 1>&2 2>&3) ;; + "P2 Overlay File System" "Enable/disable read-only file system" \ + "P3 Fan" "Set behaviour of GPIO case fan" \ + 3>&1 1>&2 2>&3) ;; *) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - "P4 USB Current" "Set USB current limit" \ - 3>&1 1>&2 2>&3) ;; + "P2 Overlay File System" "Enable/disable read-only file system" \ + "P4 USB Current" "Set USB current limit" \ + 3>&1 1>&2 2>&3) ;; esac RET=$? if [ $RET -eq 1 ]; then From 6a2aa443270832580717594fe876f2b689ba10a6 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 10:32:11 +0000 Subject: [PATCH 02/10] Cache values which can't change, for more performant menus --- raspi-config | 207 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 132 insertions(+), 75 deletions(-) diff --git a/raspi-config b/raspi-config index 5200a07..f760fee 100755 --- a/raspi-config +++ b/raspi-config @@ -30,21 +30,31 @@ LABWCENV_FILE="$HOMEDIR/.config/labwc/environment" LABWCAST_FILE="$HOMEDIR/.config/labwc/autostart" is_pi () { - ARCH=$(dpkg --print-architecture) - if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then - return 0 - else - return 1 + if [ -z "$IS_PI" ]; then + if [ -z "$ARCH" ]; then + ARCH=$(dpkg --print-architecture) + fi + if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then + IS_PI=0 + else + IS_PI=1 + fi fi + return $IS_PI } is_64bit () { - ARCH=$(dpkg --print-architecture) - if [ "$ARCH" = "arm64" ] ; then - return 0 - else - return 1 + if [ -z "$IS_64BIT" ]; then + if [ -z "$ARCH" ]; then + ARCH=$(dpkg --print-architecture) + fi + if [ "$ARCH" = "arm64" ] ; then + IS_64BIT=0 + else + IS_64BIT=1 + fi fi + return $IS_64BIT } if is_pi ; then @@ -56,79 +66,109 @@ else CMDLINE=/proc/cmdline fi -# tests for Pi 1, 2 and 0 all test for specific boards... +# tests for Pi 1, 2, 0 and CM5 all test for specific boards... is_pione() { - if grep -q "^Revision\s*:\s*00[0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo; then - return 0 - elif grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[0-36][0-9a-fA-F]$" /proc/cpuinfo ; then - return 0 - else - return 1 + if [ -z "$IS_PIONE" ]; then + if grep -q "^Revision\s*:\s*00[0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo; then + IS_PIONE=0 + elif grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[0-36][0-9a-fA-F]$" /proc/cpuinfo ; then + IS_PIONE=0 + else + IS_PIONE=1 + fi fi + return $IS_PIONE } is_pitwo() { - grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]04[0-9a-fA-F]$" /proc/cpuinfo - return $? + if [ -z "$IS_PITWO" ]; then + grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]04[0-9a-fA-F]$" /proc/cpuinfo + IS_PITWO=$? + fi + return $IS_PITWO } is_pizero() { - grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo - return $? + if [ -z "$IS_PIZERO" ]; then + grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo + IS_PIZERO=$? + fi + return $IS_PIZERO } -# ...while tests for Pi 3 and 4 just test processor type, so will also find CM3, CM4, Zero 2 etc. +is_cmfive() { + if [ -z "$IS_CMFIVE" ]; then + grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]1[8aA][0-9a-fA-F]$" /proc/cpuinfo + IS_CMFIVE=$? + fi + return $IS_CMFIVE +} + +# ...while tests for Pi 3, 4 and 5 just test processor type, so will also find CM3, CM4, Zero 2 etc. is_pithree() { - grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]2[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo - return $? + if [ -z "$IS_PITHREE" ]; then + grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]2[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo + IS_PITHREE=$? + fi + return $IS_PITHREE } is_pifour() { - grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]3[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo - return $? + if [ -z "$IS_PIFOUR" ]; then + grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]3[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo + IS_PIFOUR=$? + fi + return $IS_PIFOUR } is_pifive() { - grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo - return $? -} - -is_cmfive() { - grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]1[8aA][0-9a-fA-F]$" /proc/cpuinfo - return $? + if [ -z "$IS_PIFIVE" ]; then + grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo + IS_PIFIVE=$? + fi + return $IS_PIFIVE } get_pi_type() { - if is_pione; then - echo 1 - elif is_pitwo; then - echo 2 - elif is_pithree; then - echo 3 - elif is_pifour; then - echo 4 - elif is_pifive; then - echo 5 - elif is_pizero; then - echo 0 - else - echo -1 + if [ -z "$PI_TYPE" ]; then + if is_pione; then + GET_PI_TYPE=1 + elif is_pitwo; then + GET_PI_TYPE=2 + elif is_pithree; then + GET_PI_TYPE=3 + elif is_pifour; then + GET_PI_TYPE=4 + elif is_pifive; then + GET_PI_TYPE=5 + elif is_pizero; then + GET_PI_TYPE=0 + else + GET_PI_TYPE=-1 + fi fi + echo $GET_PI_TYPE } gpu_has_mmu() { - if is_pifour || is_pifive ; then - return 0 - else - return 1 + if [ -z "$HAS_MMU" ]; then + if is_pifour || is_pifive ; then + GPU_HAS_MMU=0 + else + GPU_HAS_MMU=1 + fi fi + return $GPU_HAS_MMU } is_live() { - grep -q "boot=live" $CMDLINE - return $? + if [ -z "$IS_LIVE" ]; then + grep -q "boot=live" $CMDLINE + IS_LIVE=$? + fi + return $IS_LIVE } is_ssh() { @@ -149,31 +189,43 @@ is_pulseaudio() { } is_wayfire() { - pgrep wayfire > /dev/null - return $? + if [ -z "$IS_WAYFIRE" ]; then + pgrep wayfire > /dev/null + IS_WAYFIRE=$? + fi + return $IS_WAYFIRE } is_labwc() { - pgrep labwc > /dev/null - return $? + if [ -z "$IS_LABWC" ]; then + pgrep labwc > /dev/null + IS_LABWC=$? + fi + return $IS_LABWC } is_wayland() { - if is_wayfire; then - return 0 - elif is_labwc; then - return 0 - else - return 1 + if [ -z "$IS_WAYLAND" ]; then + if is_wayfire; then + IS_WAYLAND=0 + elif is_labwc; then + IS_WAYLAND=0 + else + IS_WAYLAND=1 + fi fi + return $IS_WAYLAND } has_analog() { - if [ $(get_leds) -eq -1 ] ; then - return 0 - else - return 1 + if [ -z "$HAS_ANALOG" ]; then + if [ $(get_leds) -eq -1 ] ; then + HAS_ANALOG=0 + else + HAS_ANALOG=1 + fi fi + return $HAS_ANALOG } is_installed() { @@ -185,8 +237,10 @@ is_installed() { } deb_ver () { - ver=$(cut -d . -f 1 < /etc/debian_version) - echo $ver + if [ -z "$DEB_VER" ]; then + DEB_VER=$(cut -d . -f 1 < /etc/debian_version) + fi + echo $DEB_VER } get_package_version() { @@ -4046,13 +4100,16 @@ if [ "$INTERACTIVE" = True ]; then done while true; do if is_pi ; then - MEMSIZE=$(vcgencmd get_config total_mem|cut -d= -f2) - if [ $MEMSIZE -lt 1024 ]; then - FMEMSIZE="${MEMSIZE}MB" - else - FMEMSIZE="$(expr $MEMSIZE / 1024)GB" + if [ -z "$MENU_BACKTITLE" ]; then + MEMSIZE=$(vcgencmd get_config total_mem|cut -d= -f2) + if [ $MEMSIZE -lt 1024 ]; then + FMEMSIZE="${MEMSIZE}MB" + else + FMEMSIZE="$(expr $MEMSIZE / 1024)GB" + fi + MENU_BACKTITLE="$(cat /proc/device-tree/model), ${FMEMSIZE}" fi - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --backtitle "$(cat /proc/device-tree/model), ${FMEMSIZE}" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \ + FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --backtitle "$MENU_BACKTITLE" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \ "1 System Options" "Configure system settings" \ "2 Display Options" "Configure display settings" \ "3 Interface Options" "Configure connections to peripherals" \ From afe7bccc654cbe3ddfa227dff3678a014e706959 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 11:00:13 +0000 Subject: [PATCH 03/10] Logic tweaks --- raspi-config | 99 ++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 46 deletions(-) diff --git a/raspi-config b/raspi-config index f760fee..150758c 100755 --- a/raspi-config +++ b/raspi-config @@ -26,8 +26,9 @@ INIT="$(ps --no-headers -o comm 1)" HOMEDIR="$(getent passwd "$USER" | cut -d: -f6)" WAYFIRE_FILE="$HOMEDIR/.config/wayfire.ini" -LABWCENV_FILE="$HOMEDIR/.config/labwc/environment" -LABWCAST_FILE="$HOMEDIR/.config/labwc/autostart" +LABWC_DIR="$HOMEDIR/.config/labwc" +LABWCENV_FILE="$LABWC_DIR/environment" +LABWCAST_FILE="$LABWC_DIR/autostart" is_pi () { if [ -z "$IS_PI" ]; then @@ -446,6 +447,13 @@ ensure_user_conf_dir() { fi } +ensure_user_labwc_dir() { + ensure_user_conf_dir + if [ ! -d "$LABWC_DIR" ]; then + install -d -o "$USER" -g "$USER" "$LABWC_DIR" + fi +} + get_overscan() { OVS=$(get_config_var disable_overscan $CONFIG) if [ $OVS -eq 1 ]; then @@ -588,13 +596,18 @@ do_blanking() { DEFAULT= CURRENT=1 fi - if is_wayfire; then - if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2 - RET=$? - else - RET=$1 + if [ "$INTERACTIVE" = True ]; then + if ! is_wayland ; then + if [ "$(dpkg -l xscreensaver | tail -n 1 | cut -d ' ' -f 1)" = "ii" ]; then + whiptail --msgbox "Warning: xscreensaver is installed and may override raspi-config settings" 20 60 2 + fi fi + whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2 + RET=$? + else + RET=$1 + fi + if is_wayfire; then if [ "$RET" -eq 0 ] ; then if grep -q dpms_timeout $WAYFIRE_FILE ; then sed -i 's/dpms_timeout.*/dpms_timeout=600/' $WAYFIRE_FILE @@ -623,18 +636,10 @@ do_blanking() { return "$RET" fi elif is_labwc; then - if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2 - RET=$? - else - RET=$1 - fi if [ "$RET" -eq "$CURRENT" ]; then ASK_TO_REBOOT=1 fi - ensure_user_conf_dir - mkdir -p "$HOMEDIR/.config/labwc/" - chown -R $USER:$USER "$HOMEDIR/.config/labwc/" + ensure_user_labwc_dir if [ "$RET" -eq 0 ] ; then echo "swayidle -w timeout 600 'wlopm --off \\*' resume 'wlopm --on \\*' &" >> $LABWCAST_FILE chown $USER:$USER $LABWCAST_FILE @@ -648,15 +653,6 @@ do_blanking() { return "$RET" fi else - if [ "$INTERACTIVE" = True ]; then - if [ "$(dpkg -l xscreensaver | tail -n 1 | cut -d ' ' -f 1)" = "ii" ]; then - whiptail --msgbox "Warning: xscreensaver is installed and may override raspi-config settings" 20 60 2 - fi - whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2 - RET=$? - else - RET=$1 - fi if [ "$RET" -eq "$CURRENT" ]; then ASK_TO_REBOOT=1 fi @@ -727,9 +723,7 @@ update_labwc_keyboard() { VARIANT=$(grep XKBVARIANT /etc/default/keyboard | cut -d= -f2 | tr -d '"') OPTIONS=$(grep XKBOPTIONS /etc/default/keyboard | cut -d= -f2 | tr -d '"') UFILE=$LABWCENV_FILE - ensure_user_conf_dir - mkdir -p "$HOMEDIR/.config/labwc/" - chown -R $USER:$USER "$HOMEDIR/.config/labwc/" + ensure_user_labwc_dir if [ -e $UFILE ] ; then if grep -q XKB_DEFAULT_MODEL $UFILE ; then sed -i s/XKB_DEFAULT_MODEL.*/XKB_DEFAULT_MODEL=$MODEL/ $UFILE ; else echo XKB_DEFAULT_MODEL=$MODEL >> $UFILE ; fi if grep -q XKB_DEFAULT_LAYOUT $UFILE ; then sed -i s/XKB_DEFAULT_LAYOUT.*/XKB_DEFAULT_LAYOUT=$LAYOUT/ $UFILE ; else echo XKB_DEFAULT_LAYOUT=$LAYOUT >> $UFILE ; fi @@ -935,7 +929,11 @@ do_wifi_country() { IFS="/" #shellcheck disable=2086 REGDOMAIN=$(whiptail --menu "Select the country in which the Pi is to be used" 20 60 10 ${value} 3>&1 1>&2 2>&3) + RET=$? IFS="$oIFS" + if [ $RET -eq 1 ]; then # user selected Cancel + return 0 + fi else REGDOMAIN=$1 fi @@ -1059,20 +1057,20 @@ See https://www.raspberrypi.org/documentation/configuration/config-txt/overclock clear_overclock ;; Modest) - set_overclock Modest 800 250 400 0 + set_overclock $OVERCLOCK 800 250 400 0 ;; Medium) - set_overclock Medium 900 250 450 2 + set_overclock $OVERCLOCK 900 250 450 2 ;; High) if is_pione; then - set_overclock High 950 250 450 6 + set_overclock $OVERCLOCK 950 250 450 6 else - set_overclock High 1000 500 500 2 + set_overclock $OVERCLOCK 1000 500 500 2 fi ;; Turbo) - set_overclock Turbo 1000 500 600 6 + set_overclock $OVERCLOCK 1000 500 600 6 ;; *) whiptail --msgbox "Programmer error, unrecognised overclock preset" 20 60 2 @@ -2056,7 +2054,7 @@ do_network_install_ui() { true ;; *) - whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 + whiptail --msgbox "Programmer error, unrecognised network install option" 20 60 2 return 1 ;; esac @@ -2096,11 +2094,7 @@ do_libliftoff() { whiptail --msgbox "Unknown user home directory" 20 60 2 return 1 fi - LABWC_DIR="$HOMEDIR/.config/labwc" - if [ ! -e $LABWC_DIR ]; then - mkdir -p $LABWC_DIR - chown $USER:$USER $HOMEDIR/.config $LABWC_DIR - fi + ensure_user_labwc_dir if [ ! -e $LABWCENV_FILE ]; then touch $LABWCENV_FILE chown $USER:$USER $LABWCENV_FILE @@ -2160,7 +2154,7 @@ do_power_off_on_halt() { true ;; *) - whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 + whiptail --msgbox "Programmer error, unrecognised shutdown option" 20 60 2 return 1 ;; esac @@ -2221,7 +2215,7 @@ do_boot_order() { STATUS="Network" ;; *) - whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 + whiptail --msgbox "Programmer error, unrecognised boot order option" 20 60 2 return 1 ;; esac @@ -2620,7 +2614,7 @@ do_gldriver() { STATUS="The full KMS GL driver is enabled." ;; *) - whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 + whiptail --msgbox "Programmer error, unrecognised GL driver option" 20 60 2 return 1 ;; esac @@ -2760,7 +2754,7 @@ do_wayland() { STATUS="Labwc on Wayland" ;; *) - whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 + whiptail --msgbox "Programmer error, unrecognised Wayland option" 20 60 2 return 1 ;; esac @@ -3934,7 +3928,7 @@ do_interface_menu() { 3>&1 1>&2 2>&3) else FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Interfacing Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ - "I2 SSH" "Enable/disable remote command line access using SSH" \ + "I1 SSH" "Enable/disable remote command line access using SSH" \ 3>&1 1>&2 2>&3) fi RET=$? @@ -4009,7 +4003,20 @@ do_internationalisation_menu() { } do_advanced_menu() { - if gpu_has_mmu ; then + if is_pifour ; then + FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ + "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ + "A3 Network Proxy Settings" "Configure network proxy settings" \ + "A4 Boot Order" "Choose boot device priority (SD/net/USB/NVMe)" \ + "A5 Bootloader Version" "Select bootloader (latest/factory default)" \ + "A6 Wayland" "Switch between X and Wayland backends" \ + "A7 Audio Config" "Set audio control system" \ + "A9 Network Install UI" "Select display of bootloader network install UI" \ + "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ + "A11 Shutdown Behaviour" "Configure shutdown behavior" \ + 3>&1 1>&2 2>&3) + elif is_pifive ; then FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ From b5a1b4cf703dcc8985f7acc2bd86b8f5c87f7331 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 12:14:25 +0000 Subject: [PATCH 04/10] Wrap `whiptail --msgbox` in a `wt_msgbox` function for consistency and reduced boilerplate --- raspi-config | 230 +++++++++++++++++++++++++++------------------------ 1 file changed, 123 insertions(+), 107 deletions(-) diff --git a/raspi-config b/raspi-config index 150758c..bc99b61 100755 --- a/raspi-config +++ b/raspi-config @@ -276,6 +276,9 @@ calc_wt_size() { # stderr is a tty and so only gives default 80, 24 values WT_HEIGHT=18 WT_WIDTH=$(tput cols) + WT_BOX_HEIGHT=20 + WT_BOX_WIDTH=60 + WT_BOX_WIDTH_WIDE=70 if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then WT_WIDTH=80 @@ -286,15 +289,28 @@ calc_wt_size() { WT_MENU_HEIGHT=$((WT_HEIGHT - 7)) } +wt_msgbox() { + if [ -z $2 ]; then + MSGBOX_WIDTH=$WT_BOX_WIDTH + else + MSGBOX_WIDTH=$2 + fi + whiptail --msgbox "$1" $WT_BOX_HEIGHT $MSGBOX_WIDTH +} + +wt_msgbox_wide() { + wt_msgbox "$1" $WT_BOX_WIDTH_WIDE +} + do_about() { - whiptail --msgbox "\ + wt_msgbox_wide "\ This tool provides a straightforward way of doing initial configuration of the Raspberry Pi. Although it can be run at any time, some of the options may have difficulties if you have heavily customised your installation. $(dpkg -s raspi-config 2> /dev/null | grep Version)\ -" 20 70 1 +" return 0 } @@ -325,7 +341,7 @@ do_expand_rootfs() { LAST_PART_NUM=$(parted "$ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:) if [ "$LAST_PART_NUM" -ne "$PART_NUM" ]; then - whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2 + wt_msgbox "$ROOT_PART is not the last partition. Don't know how to expand" return 0 fi @@ -380,7 +396,7 @@ EOF chmod +x /etc/init.d/resize2fs_once && update-rc.d resize2fs_once defaults && if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" 20 60 2 + wt_msgbox "Root partition has been resized.\nThe filesystem will be enlarged upon the next reboot" fi } @@ -490,7 +506,7 @@ do_overscan() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Display overscan compensation is $STATUS" 20 60 1 + wt_msgbox "Display overscan compensation is $STATUS" fi } @@ -561,7 +577,7 @@ do_overscan_kms() { sed /usr/share/dispsetup.sh -i -e "s#exit#if [ -e /usr/share/ovscsetup.sh ] ; then\n. /usr/share/ovscsetup.sh\nfi\nexit#" fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Display overscan compensation for HDMI-$DEV is $STATUS" 20 60 1 + wt_msgbox "Display overscan compensation for HDMI-$DEV is $STATUS" fi } @@ -599,7 +615,7 @@ do_blanking() { if [ "$INTERACTIVE" = True ]; then if ! is_wayland ; then if [ "$(dpkg -l xscreensaver | tail -n 1 | cut -d ' ' -f 1)" = "ii" ]; then - whiptail --msgbox "Warning: xscreensaver is installed and may override raspi-config settings" 20 60 2 + wt_msgbox "Warning: xscreensaver is installed and may override raspi-config settings" fi fi whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2 @@ -670,14 +686,14 @@ do_blanking() { fi fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Screen blanking is $STATUS" 20 60 1 + wt_msgbox "Screen blanking is $STATUS" fi } do_change_pass() { - whiptail --msgbox "You will now be asked to enter a new password for the $USER user" 20 60 1 + wt_msgbox "You will now be asked to enter a new password for the $USER user" passwd $USER && - whiptail --msgbox "Password changed successfully" 20 60 1 + wt_msgbox "Password changed successfully" } update_wayfire_keyboard() { @@ -939,7 +955,7 @@ do_wifi_country() { fi if ! grep -q "^${REGDOMAIN}[[:space:]]" /usr/share/zoneinfo/iso3166.tab; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "$REGDOMAIN is not a valid ISO/IEC 3166-1 alpha2 code" 20 60 + wt_msgbox "$REGDOMAIN is not a valid ISO/IEC 3166-1 alpha2 code" fi return 1 fi @@ -978,7 +994,7 @@ do_wifi_country() { done fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Wireless LAN country set to $REGDOMAIN" 20 60 1 + wt_msgbox "Wireless LAN country set to $REGDOMAIN" fi if ! ischroot && pgrep wf-panel-pi > /dev/null; then wfpanelctl netman cset @@ -994,13 +1010,13 @@ get_hostname() { do_hostname() { if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "\ + wt_msgbox_wide "\ Please note: RFCs mandate that a hostname's labels \ may contain only the ASCII letters 'a' through 'z' (case-insensitive), the digits '0' through '9', and the hyphen. Hostname labels cannot begin or end with a hyphen. No other symbols, punctuation characters, or blank spaces are permitted.\ -" 20 70 1 +" fi CURRENT_HOSTNAME=$(get_hostname) if [ "$INTERACTIVE" = True ]; then @@ -1022,17 +1038,17 @@ No other symbols, punctuation characters, or blank spaces are permitted.\ do_overclock() { if ! is_pione && ! is_pitwo; then - whiptail --msgbox "Only Pi 1 or Pi 2 can be overclocked with this tool." 20 60 2 + wt_msgbox "Only Pi 1 or Pi 2 can be overclocked with this tool." return 1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "\ + wt_msgbox_wide "\ Be aware that overclocking may reduce the lifetime of your Raspberry Pi. If overclocking at a certain level causes system instability, try a more modest overclock. Hold down shift during boot to temporarily disable overclock. See https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md for more information.\ -" 20 70 1 +" if is_pione; then OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \ "None" "700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ @@ -1073,7 +1089,7 @@ See https://www.raspberrypi.org/documentation/configuration/config-txt/overclock set_overclock $OVERCLOCK 1000 500 600 6 ;; *) - whiptail --msgbox "Programmer error, unrecognised overclock preset" 20 60 2 + wt_msgbox "Programmer error, unrecognised overclock preset" return 1 ;; esac @@ -1087,7 +1103,7 @@ set_overclock() { set_config_var sdram_freq $4 $CONFIG && set_config_var over_voltage $5 $CONFIG && if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Set overclock to preset '$1'" 20 60 2 + wt_msgbox "Set overclock to preset '$1'" fi } @@ -1097,7 +1113,7 @@ clear_overclock () { clear_config_var sdram_freq $CONFIG && clear_config_var over_voltage $CONFIG && if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Set overclock to preset 'None'" 20 60 2 + wt_msgbox "Set overclock to preset 'None'" fi } @@ -1111,7 +1127,7 @@ get_ssh() { do_ssh() { if [ -e /var/log/regen_ssh_keys.log ] && ! grep -q "^finished" /var/log/regen_ssh_keys.log; then - whiptail --msgbox "Initial ssh key generation still running. Please wait and try again." 20 60 2 + wt_msgbox "Initial ssh key generation still running. Please wait and try again." return 1 fi DEFAULT=--defaultno @@ -1139,7 +1155,7 @@ do_ssh() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The SSH server is $STATUS" 20 60 1 + wt_msgbox "The SSH server is $STATUS" fi } @@ -1176,7 +1192,7 @@ do_vnc() { if is_installed wayvnc; then wayvnc_version="$(get_package_version wayvnc)" if dpkg --compare-versions "$wayvnc_version" lt 0.8; then - whiptail --msgbox "WayVNC version 0.8 or greater is required (have $wayvnc_version)" 20 60 1 + wt_msgbox "WayVNC version 0.8 or greater is required (have $wayvnc_version)" return 1 fi @@ -1222,7 +1238,7 @@ do_vnc() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The VNC Server is $STATUS" 20 60 1 + wt_msgbox "The VNC Server is $STATUS" fi } @@ -1302,7 +1318,7 @@ do_rpi_connect() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "$STATUS" 20 60 1 + wt_msgbox "$STATUS" fi } @@ -1343,7 +1359,7 @@ do_spi() { dtparam spi=$SETTING if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The SPI interface is $STATUS" 20 60 1 + wt_msgbox "The SPI interface is $STATUS" fi } @@ -1389,7 +1405,7 @@ do_i2c() { modprobe i2c-dev if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The ARM I2C interface is $STATUS" 20 60 1 + wt_msgbox "The ARM I2C interface is $STATUS" fi } @@ -1501,7 +1517,7 @@ do_serial() { else return $RET fi - whiptail --msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" 20 60 1 + wt_msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" } do_serial_pi5() { @@ -1545,7 +1561,7 @@ do_serial_pi5() { else return $RET fi - whiptail --msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" 20 60 1 + wt_msgbox "The serial login shell is $SSTATUS\nThe serial interface is $HSTATUS" } get_pci() { @@ -1583,7 +1599,7 @@ do_pci() { fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "PCIe Gen 3 is $STATUS" 20 60 1 + wt_msgbox "PCIe Gen 3 is $STATUS" fi } @@ -1664,7 +1680,7 @@ do_pi4video() { ASK_TO_REBOOT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "4Kp60 is $STATUS" 20 60 1 + wt_msgbox "4Kp60 is $STATUS" fi } @@ -1704,7 +1720,7 @@ do_composite() { ASK_TO_REBOOT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Composite video output is $STATUS" 20 60 1 + wt_msgbox "Composite video output is $STATUS" fi } @@ -1724,7 +1740,7 @@ do_leds() { CURRENT=$(get_leds) if [ $CURRENT -eq -1 ] ; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The LED behaviour cannot be changed on this model of Raspberry Pi" 20 60 1 + wt_msgbox "The LED behaviour cannot be changed on this model of Raspberry Pi" fi return 1 fi @@ -1753,7 +1769,7 @@ do_leds() { fi echo $LEDSET | tee /sys/class/leds/ACT/trigger > /dev/null if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The power LED will $STATUS" 20 60 1 + wt_msgbox "The power LED will $STATUS" fi } @@ -1805,13 +1821,13 @@ do_fan() { fi if ! echo "$GPIO" | grep -q "^[[:digit:]]*$" ; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "GPIO must be a number between 2 and 27" 20 60 1 + wt_msgbox "GPIO must be a number between 2 and 27" fi return 1 fi if [ "$GPIO" -lt 2 ] || [ "$GPIO" -gt 27 ] ; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "GPIO must be a number between 2 and 27" 20 60 1 + wt_msgbox "GPIO must be a number between 2 and 27" fi return 1 fi @@ -1829,13 +1845,13 @@ do_fan() { fi if ! echo "$TIN" | grep -q "^[[:digit:]]*$" ; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Temperature must be a number between 60 and 120" 20 60 1 + wt_msgbox "Temperature must be a number between 60 and 120" fi return 1 fi if [ "$TIN" -lt 60 ] || [ "$TIN" -gt 120 ] ; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Temperature must be a number between 60 and 120" 20 60 1 + wt_msgbox "Temperature must be a number between 60 and 120" fi return 1 fi @@ -1852,7 +1868,7 @@ do_fan() { fi ASK_TO_REBOOT=1 if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The fan on GPIO $GPIO is enabled and will turn on at $TIN degrees Celsius" 20 60 1 + wt_msgbox "The fan on GPIO $GPIO is enabled and will turn on at $TIN degrees Celsius" fi else if grep -q "^dtoverlay=gpio-fan" $CONFIG ; then @@ -1860,7 +1876,7 @@ do_fan() { fi sed $CONFIG -i -e "/^.*dtoverlay=gpio-fan.*/d" if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The fan is disabled" 20 60 1 + wt_msgbox "The fan is disabled" fi fi } @@ -1895,7 +1911,7 @@ do_browser() { sudo -u $2 xdg-settings set default-web-browser $BROWSER.desktop fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Default browser set to $BSTRING" 20 60 1 + wt_msgbox "Default browser set to $BSTRING" fi fi } @@ -1929,7 +1945,7 @@ do_journald_storage() { REPLACEMENT="$([ ! -z $JSTRING ] && echo "Storage=$JSTRING" || echo "#Storage=auto")" sed --in-place -E "s/^#?Storage=.*/${REPLACEMENT}/" /etc/systemd/journald.conf if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Logging location set to ${JSTRING:-default}" 20 60 1 + wt_msgbox "Logging location set to ${JSTRING:-default}" fi fi } @@ -1955,12 +1971,12 @@ do_boot_behaviour() { if [ -e /etc/init.d/lightdm ]; then systemctl --quiet set-default graphical.target else - whiptail --msgbox "Do 'sudo apt-get install lightdm' to allow configuration of boot to desktop" 20 60 2 + wt_msgbox "Do 'sudo apt-get install lightdm' to allow configuration of boot to desktop" return 1 fi ;; *) - whiptail --msgbox "Programmer error, unrecognised boot option" 20 60 2 + wt_msgbox "Programmer error, unrecognised boot option" return 1 ;; esac @@ -2054,7 +2070,7 @@ do_network_install_ui() { true ;; *) - whiptail --msgbox "Programmer error, unrecognised network install option" 20 60 2 + wt_msgbox "Programmer error, unrecognised network install option" return 1 ;; esac @@ -2084,14 +2100,14 @@ do_libliftoff() { STATUS="enabled" ;; *) - whiptail --msgbox "Programmer error, unrecognised libliftoff option" 20 60 2 + wt_msgbox "Programmer error, unrecognised libliftoff option" return 1 ;; esac # Create the config dir and/or environment file, if needed if [ -z $HOMEDIR ]; then - whiptail --msgbox "Unknown user home directory" 20 60 2 + wt_msgbox "Unknown user home directory" return 1 fi ensure_user_labwc_dir @@ -2113,7 +2129,7 @@ do_libliftoff() { return 0 fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "libliftoff is $STATUS" 20 60 1 + wt_msgbox "libliftoff is $STATUS" fi } @@ -2154,7 +2170,7 @@ do_power_off_on_halt() { true ;; *) - whiptail --msgbox "Programmer error, unrecognised shutdown option" 20 60 2 + wt_msgbox "Programmer error, unrecognised shutdown option" return 1 ;; esac @@ -2215,7 +2231,7 @@ do_boot_order() { STATUS="Network" ;; *) - whiptail --msgbox "Programmer error, unrecognised boot order option" 20 60 2 + wt_msgbox "Programmer error, unrecognised boot order option" return 1 ;; esac @@ -2230,7 +2246,7 @@ do_boot_order() { rpi-eeprom-config --apply $EECFG $FILNAME ASK_TO_REBOOT=1 if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "$STATUS is default boot device" 20 60 1 + wt_msgbox "$STATUS is default boot device" fi fi } @@ -2257,7 +2273,7 @@ do_boot_rom() { EETYPE="Factory default" ;; *) - whiptail --msgbox "Programmer error, unrecognised bootloader option" 20 60 2 + wt_msgbox "Programmer error, unrecognised bootloader option" return 1 ;; esac @@ -2278,11 +2294,11 @@ do_boot_rom() { fi rpi-eeprom-update -d -f $FILNAME if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Bootloader reset to default configuration" 20 60 2 + wt_msgbox "Bootloader reset to default configuration" fi else if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Bootloader not reset to defaults" 20 60 2 + wt_msgbox "Bootloader not reset to defaults" fi fi ASK_TO_REBOOT=1 @@ -2308,7 +2324,7 @@ get_boot_splash() { do_boot_splash() { if [ ! -e /usr/share/plymouth/themes/pix/pix.script ]; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The splash screen is not installed so cannot be activated" 20 60 2 + wt_msgbox "The splash screen is not installed so cannot be activated" fi return 1 fi @@ -2354,7 +2370,7 @@ do_boot_splash() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Splash screen at boot is $STATUS" 20 60 1 + wt_msgbox "Splash screen at boot is $STATUS" fi } @@ -2396,7 +2412,7 @@ EOF systemctl restart pigpiod fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Remote access to the GPIO server is $STATUS" 20 60 1 + wt_msgbox "Remote access to the GPIO server is $STATUS" fi } @@ -2424,7 +2440,7 @@ get_camera() { do_camera() { if [ $(deb_ver) -le 10 ] && [ ! -e /boot${FIRMWARE}/start_x.elf ]; then - whiptail --msgbox "Your firmware appears to be out of date (no start_x.elf). Please update" 20 60 2 + wt_msgbox "Your firmware appears to be out of date (no start_x.elf). Please update" return 1 fi sed $CONFIG -i -e "s/^startx/#startx/" @@ -2468,7 +2484,7 @@ do_camera() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The camera interface is $STATUS" 20 60 1 + wt_msgbox "The camera interface is $STATUS" fi } @@ -2509,7 +2525,7 @@ do_onewire() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The one-wire interface is $STATUS" 20 60 1 + wt_msgbox "The one-wire interface is $STATUS" fi } @@ -2570,13 +2586,13 @@ do_legacy() { STATUS="Legacy camera support is disabled." fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "$STATUS" 20 60 1 + wt_msgbox "$STATUS" fi } do_gldriver() { if [ ! -e /boot${FIRMWARE}/overlays/vc4-kms-v3d.dtbo ]; then - whiptail --msgbox "Driver and kernel not present on your system. Please update" 20 60 2 + wt_msgbox "Driver and kernel not present on your system. Please update" return 1 fi for package in gldriver-test libgl1-mesa-dri; do @@ -2585,7 +2601,7 @@ do_gldriver() { fi done if [ -n "$missing_packages" ] && ! apt-get install $missing_packages; then - whiptail --msgbox "Required packages not found, please install: ${missing_packages}" 20 60 2 + wt_msgbox "Required packages not found, please install: ${missing_packages}" return 1 fi GLOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "GL Driver" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ @@ -2614,14 +2630,14 @@ do_gldriver() { STATUS="The full KMS GL driver is enabled." ;; *) - whiptail --msgbox "Programmer error, unrecognised GL driver option" 20 60 2 + wt_msgbox "Programmer error, unrecognised GL driver option" return 1 ;; esac else return 0 fi - whiptail --msgbox "$STATUS" 20 60 1 + wt_msgbox "$STATUS" } do_xcompmgr() { @@ -2660,7 +2676,7 @@ EOF return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The xcompmgr composition manager is $STATUS" 20 60 1 + wt_msgbox "The xcompmgr composition manager is $STATUS" fi } @@ -2693,7 +2709,7 @@ do_glamor() { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Glamor acceleration is $STATUS" 20 60 1 + wt_msgbox "Glamor acceleration is $STATUS" fi } @@ -2754,7 +2770,7 @@ do_wayland() { STATUS="Labwc on Wayland" ;; *) - whiptail --msgbox "Programmer error, unrecognised Wayland option" 20 60 2 + wt_msgbox "Programmer error, unrecognised Wayland option" return 1 ;; esac @@ -2763,7 +2779,7 @@ do_wayland() { return 0 fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "$STATUS is active" 20 60 1 + wt_msgbox "$STATUS is active" fi } @@ -2778,7 +2794,7 @@ do_audioconf() { DEFAULT=2 fi if ! is_installed pulseaudio && ! is_installed pipewire-pulse ; then - whiptail --msgbox "No audio systems installed" 20 60 1 + wt_msgbox "No audio systems installed" RET=1 else if is_installed pulseaudio ; then @@ -2824,7 +2840,7 @@ do_audioconf() { fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "$AUDCON is active" 20 60 1 + wt_msgbox "$AUDCON is active" fi } @@ -2867,7 +2883,7 @@ do_net_names () { return $RET fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Predictable network interface names are $STATUS" 20 60 1 + wt_msgbox "Predictable network interface names are $STATUS" fi } @@ -2888,7 +2904,7 @@ do_audio() { IFS="/" AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 ${list} 3>&1 1>&2 2>&3) else - whiptail --msgbox "No internal audio devices found" 20 60 1 + wt_msgbox "No internal audio devices found" return 1 fi else @@ -2934,7 +2950,7 @@ do_audio() { n=$(( n+1 )) done if [ $n -eq 0 ] ; then - whiptail --msgbox "No audio devices found" 20 60 1 + wt_msgbox "No audio devices found" false else oIFS="$IFS" @@ -3025,9 +3041,9 @@ do_resolution() { fi if [ "$INTERACTIVE" = True ]; then if [ $MODE -eq 0 ] ; then - whiptail --msgbox "The resolution is set to default" 20 60 1 + wt_msgbox "The resolution is set to default" else - whiptail --msgbox "The resolution is set to $GRS mode $MODE" 20 60 1 + wt_msgbox "The resolution is set to $GRS mode $MODE" fi fi if [ $MODE -eq 0 ] ; then @@ -3109,7 +3125,7 @@ Exec=sh -c "if ! (xrandr | grep -q -w connected) ; then /usr/bin/xrandr --fb $FU EOF fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The resolution is set to $FUN" 20 60 1 + wt_msgbox "The resolution is set to $FUN" ASK_TO_REBOOT=1 fi fi @@ -3137,20 +3153,20 @@ do_wifi_ssid_passphrase() { if [ -z "$IFACE" ]; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "No wireless interface found" 20 60 + wt_msgbox "No wireless interface found" fi return 1 fi if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60 + wt_msgbox "Could not communicate with wpa_supplicant" fi return 1 fi elif ! systemctl -q is-active NetworkManager; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "No supported network connection manager found" 20 60 + wt_msgbox "No supported network connection manager found" fi return 1 fi @@ -3160,7 +3176,7 @@ do_wifi_ssid_passphrase() { if ! SSID=$(whiptail --inputbox "Please enter SSID" 20 60 3>&1 1>&2 2>&3); then return 0 elif [ -z "$SSID" ]; then - whiptail --msgbox "SSID cannot be empty. Please try again." 20 60 + wt_msgbox "SSID cannot be empty. Please try again." fi done @@ -3224,7 +3240,7 @@ do_wifi_ssid_passphrase() { else wpa_cli -i "$IFACE" remove_network "$ID" > /dev/null 2>&1 if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Failed to set SSID or passphrase" 20 60 + wt_msgbox "Failed to set SSID or passphrase" fi fi wpa_cli -i "$IFACE" save_config > /dev/null 2>&1 @@ -3355,7 +3371,7 @@ is_uname_current() { enable_overlayfs() { if [ "$(awk '/MemTotal/{print $2; exit}' /proc/meminfo)" -le 262144 ]; then if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "At least 512MB of RAM is recommended for overlay filesystem" 20 60 1 + wt_msgbox "At least 512MB of RAM is recommended for overlay filesystem" else echo "At least 512MB of RAM is recommended for overlay filesystem" fi @@ -3429,7 +3445,7 @@ do_overlayfs() { STATUS="disabled" if [ "$INTERACTIVE" = True ] && ! is_uname_current; then - whiptail --msgbox "Could not find modules for the running kernel ($(uname -r))." 20 60 1 + wt_msgbox "Could not find modules for the running kernel ($(uname -r))." return 1 fi @@ -3464,7 +3480,7 @@ do_overlayfs() { fi fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The overlay file system is $STATUS." 20 60 1 + wt_msgbox "The overlay file system is $STATUS." fi if [ $(get_overlay_now) -eq 0 ] ; then if [ $(get_bootro_conf) -eq 0 ] ; then @@ -3473,7 +3489,7 @@ do_overlayfs() { BPRO="writable" fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The boot partition is currently $BPRO. This cannot be changed while an overlay file system is enabled." 20 60 1 + wt_msgbox "The boot partition is currently $BPRO. This cannot be changed while an overlay file system is enabled." fi else DEFAULT=--defaultno @@ -3510,7 +3526,7 @@ do_overlayfs() { fi fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The boot partition is $STATUS." 20 60 1 + wt_msgbox "The boot partition is $STATUS." fi fi } @@ -3573,7 +3589,7 @@ do_proxy() { fi done if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Proxy settings $STATUS" 20 60 1 + wt_msgbox "Proxy settings $STATUS" fi } @@ -3609,7 +3625,7 @@ do_usb_current() { if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The USB current limit is $STATUS" 20 60 1 + wt_msgbox "The USB current limit is $STATUS" fi } @@ -3700,7 +3716,7 @@ EOF ;; esac if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The onscreen keyboard is $STATUS" 20 60 1 + wt_msgbox "The onscreen keyboard is $STATUS" fi } @@ -3740,7 +3756,7 @@ do_squeek_output() { $PREFIX sbout > /dev/null 2> /dev/null & fi if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "The onscreen keyboard is on $OPT" 20 60 1 + wt_msgbox "The onscreen keyboard is on $OPT" fi } @@ -3849,8 +3865,8 @@ do_system_menu() { S7\ *) do_leds ;; S8\ *) do_browser ;; S9\ *) do_journald_storage ;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" fi } @@ -3909,8 +3925,8 @@ do_display_menu() { D5\ *) do_pi4video ;; D6\ *) do_squeekboard ;; D7\ *) do_squeek_output ;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" fi } @@ -3944,8 +3960,8 @@ do_interface_menu() { I6\ *) if is_pifive ; then do_serial_pi5 ; else do_serial ; fi ;; I7\ *) do_onewire ;; I8\ *) do_rgpio ;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" fi } @@ -3976,8 +3992,8 @@ do_performance_menu() { P2\ *) do_overlayfs ;; P3\ *) do_fan ;; P4\ *) do_usb_current ;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" fi } @@ -3997,8 +4013,8 @@ do_internationalisation_menu() { L2\ *) do_change_timezone ;; L3\ *) do_configure_keyboard ;; L4\ *) do_wifi_country ;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" fi } @@ -4064,8 +4080,8 @@ do_advanced_menu() { A9\ *) do_network_install_ui ;; A10\ *) do_libliftoff ;; A11\ *) do_power_off_on_halt ;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" fi } @@ -4089,8 +4105,8 @@ do_proxy_menu() { P4\ *) do_proxy ftp ;; P5\ *) do_proxy rsync ;; P6\ *) do_proxy no;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" fi } @@ -4150,8 +4166,8 @@ if [ "$INTERACTIVE" = True ]; then 6\ *) do_advanced_menu ;; 8\ *) do_update ;; 9\ *) do_about ;; - *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; - esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 + *) wt_msgbox "Programmer error: unrecognized option" ;; + esac || wt_msgbox "There was an error running option $FUN" else exit 1 fi From 11acddcb8d7f67ffae62d3a7f15c48255100e195 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 12:23:12 +0000 Subject: [PATCH 05/10] Wrap `whiptail --yesno` in a `wt_yesno` function for consistency and reduced boilerplate --- raspi-config | 84 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/raspi-config b/raspi-config index bc99b61..866f526 100755 --- a/raspi-config +++ b/raspi-config @@ -302,6 +302,24 @@ wt_msgbox_wide() { wt_msgbox "$1" $WT_BOX_WIDTH_WIDE } +wt_yesno() { + if [ -z $2 ] || [ "$2" = "" ]; then + YESNO_DEFAULT= + else + YESNO_DEFAULT="$2" + fi + if [ -z $3 ]; then + YESNO_WIDTH=$WT_BOX_WIDTH + else + YESNO_WIDTH=$3 + fi + whiptail --yesno "$1" $YESNO_DEFAULT $WT_BOX_HEIGHT $YESNO_WIDTH 3>&1 1>&2 2>&3 +} + +wt_yesno_wide() { + wt_yesno "$1" "$2" $WT_BOX_WIDTH_WIDE +} + do_about() { wt_msgbox_wide "\ This tool provides a straightforward way of doing initial @@ -487,7 +505,7 @@ do_overscan() { CURRENT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable compensation for displays with overscan?" $DEFAULT 20 60 2 + wt_yesno "Would you like to enable compensation for displays with overscan?" $DEFAULT RET=$? else RET=$1 @@ -540,7 +558,7 @@ do_overscan_kms() { else DEFAULT= fi - if whiptail --yesno "Would you like to enable overscan compensation for HDMI-$DEV?" $DEFAULT 20 60 2 ; then + if wt_yesno "Would you like to enable overscan compensation for HDMI-$DEV?" $DEFAULT ; then PIX=16 STATUS="enabled" else @@ -618,7 +636,7 @@ do_blanking() { wt_msgbox "Warning: xscreensaver is installed and may override raspi-config settings" fi fi - whiptail --yesno "Would you like to enable screen blanking?" $DEFAULT 20 60 2 + wt_yesno "Would you like to enable screen blanking?" $DEFAULT RET=$? else RET=$1 @@ -1135,9 +1153,7 @@ do_ssh() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno \ - "Would you like the SSH server to be enabled?\n\nCaution: Default and weak passwords are a security risk when SSH is enabled!" \ - $DEFAULT 20 60 2 + wt_yesno "Would you like the SSH server to be enabled?\n\nCaution: Default and weak passwords are a security risk when SSH is enabled!" $DEFAULT RET=$? else RET=$1 @@ -1182,7 +1198,7 @@ do_vnc() { fi APT_GET_FLAGS="" if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the VNC Server to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the VNC Server to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -1261,7 +1277,7 @@ do_rpi_connect() { fi APT_GET_FLAGS="" if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable screen sharing over Raspberry Pi Connect?" --defaultno 20 60 2 + wt_yesno "Would you like to enable screen sharing over Raspberry Pi Connect?" --defaultno RET=$? else APT_GET_FLAGS="-y" @@ -1285,7 +1301,7 @@ do_rpi_connect() { fi elif [ $RET -eq 1 ]; then if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable remote shell access over Raspberry Pi Connect?" --defaultno 20 60 2 + wt_yesno "Would you like to enable remote shell access over Raspberry Pi Connect?" --defaultno RET=$? fi if [ $RET -eq 0 ]; then @@ -1336,7 +1352,7 @@ do_spi() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the SPI interface to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the SPI interface to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -1377,7 +1393,7 @@ do_i2c() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the ARM I2C interface to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the ARM I2C interface to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -1487,7 +1503,7 @@ do_serial() { DEFAULTH= CURRENTH=1 fi - whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS 20 60 2 + wt_yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS RET=$? if [ $RET -eq $CURRENTS ]; then ASK_TO_REBOOT=1 @@ -1500,7 +1516,7 @@ do_serial() { elif [ $RET -eq 1 ]; then do_serial_cons 1 SSTATUS=disabled - whiptail --yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH 20 60 2 + wt_yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH RET=$? if [ $RET -eq $CURRENTH ]; then ASK_TO_REBOOT=1 @@ -1533,7 +1549,7 @@ do_serial_pi5() { DEFAULTH= CURRENTH=1 fi - whiptail --yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS 20 60 2 + wt_yesno "Would you like a login shell to be accessible over serial?" $DEFAULTS RET=$? if [ $RET -eq $CURRENTS ]; then ASK_TO_REBOOT=1 @@ -1547,7 +1563,7 @@ do_serial_pi5() { else return $RET fi - whiptail --yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH 20 60 2 + wt_yesno "Would you like the serial port hardware to be enabled?" $DEFAULTH RET=$? if [ $RET -eq $CURRENTH ]; then ASK_TO_REBOOT=1 @@ -1580,7 +1596,7 @@ do_pci() { CURRENT=0 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like PCIe Gen 3 to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like PCIe Gen 3 to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -1655,7 +1671,7 @@ do_pi4video() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable 4Kp60 output on HDMI0?" $DEFAULT 20 60 2 + wt_yesno "Would you like to enable 4Kp60 output on HDMI0?" $DEFAULT RET=$? else RET=$1 @@ -1699,7 +1715,7 @@ do_composite() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like composite video output to be enabled? Warning - this will disable the HDMI outputs." $DEFAULT 20 60 2 + wt_yesno "Would you like composite video output to be enabled? Warning - this will disable the HDMI outputs." $DEFAULT RET=$? else RET=$1 @@ -1749,7 +1765,7 @@ do_leds() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the power LED to flash during disk activity?" $DEFAULT 20 60 2 + wt_yesno "Would you like the power LED to flash during disk activity?" $DEFAULT RET=$? else RET=$1 @@ -1801,7 +1817,7 @@ do_fan() { GNOW=$(get_fan_gpio) TNOW=$(get_fan_temp) if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable fan temperature control?" $DEFAULT 20 60 2 + wt_yesno "Would you like to enable fan temperature control?" $DEFAULT RET=$? else RET=$1 @@ -2029,7 +2045,7 @@ get_bootloader_filename() { done if [ $EXACT_MATCH != 1 ]; then if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Current EEPROM version $(date -d $CURDATE +%Y-%m-%d) or newer not found.\n\nTry updating the rpi-eeprom APT package.\n\nInstall latest local $(basename $FILNAME) anyway?" 20 70 3 + wt_yesno_wide "Current EEPROM version $(date -d $CURDATE +%Y-%m-%d) or newer not found.\n\nTry updating the rpi-eeprom APT package.\n\nInstall latest local $(basename $FILNAME) anyway?" DEFAULTS=$? if [ "$DEFAULTS" -ne 0 ]; then FILNAME="none" # no @@ -2278,7 +2294,7 @@ do_boot_rom() { ;; esac if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "$EETYPE bootloader selected - will be loaded at next reboot.\n\nReset bootloader to default configuration?" 20 60 2 + wt_yesno "$EETYPE bootloader selected - will be loaded at next reboot.\n\nReset bootloader to default configuration?" DEFAULTS=$? else DEFAULTS=$2 @@ -2333,7 +2349,7 @@ do_boot_splash() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to show the splash screen at boot?" $DEFAULT 20 60 2 + wt_yesno "Would you like to show the splash screen at boot?" $DEFAULT RET=$? else RET=$1 @@ -2388,7 +2404,7 @@ do_rgpio() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the GPIO server to be accessible over the network?" $DEFAULT 20 60 2 + wt_yesno "Would you like the GPIO server to be accessible over the network?" $DEFAULT RET=$? else RET=$1 @@ -2453,7 +2469,7 @@ do_camera() { CURRENT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the camera interface to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the camera interface to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -2504,7 +2520,7 @@ do_onewire() { CURRENT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the one-wire interface to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the one-wire interface to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -2545,7 +2561,7 @@ do_legacy() { CURRENT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable legacy camera support?" $DEFAULT 20 60 2 + wt_yesno "Would you like to enable legacy camera support?" $DEFAULT RET=$? else RET=$1 @@ -2648,7 +2664,7 @@ do_xcompmgr() { CURRENT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the xcompmgr composition manager to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the xcompmgr composition manager to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -2688,7 +2704,7 @@ do_glamor() { CURRENT=0 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like glamor acceleration to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like glamor acceleration to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -2862,7 +2878,7 @@ do_net_names () { CURRENT=1 fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like to enable predictable network interface names?" $DEFAULT 20 60 2 + wt_yesno "Would you like to enable predictable network interface names?" $DEFAULT RET=$? else RET=$1 @@ -3263,7 +3279,7 @@ do_wifi_ssid_passphrase() { do_finish() { disable_raspi_config_at_boot if [ $ASK_TO_REBOOT -eq 1 ]; then - whiptail --yesno "Would you like to reboot now?" 20 60 2 + wt_yesno "Would you like to reboot now?" if [ $? -eq 0 ]; then # yes sync reboot @@ -3455,7 +3471,7 @@ do_overlayfs() { STATUS="enabled" fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the overlay file system to be enabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the overlay file system to be enabled?" $DEFAULT RET=$? else RET=$1 @@ -3501,7 +3517,7 @@ do_overlayfs() { STATUS="read-only" fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the boot partition to be write-protected?" $DEFAULT 20 60 2 + wt_yesno "Would you like the boot partition to be write-protected?" $DEFAULT RET=$? else RET=$1 @@ -3608,7 +3624,7 @@ do_usb_current() { DEFAULT= fi if [ "$INTERACTIVE" = True ]; then - whiptail --yesno "Would you like the USB current limit to be disabled?" $DEFAULT 20 60 2 + wt_yesno "Would you like the USB current limit to be disabled?" $DEFAULT RET=$? else RET=$1 From ff7a252b3a9f9e8498852aa504a31e4c87df7df6 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 12:43:58 +0000 Subject: [PATCH 06/10] Add wt_inputbox and wt_passwordbox wrapper functions --- raspi-config | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/raspi-config b/raspi-config index 866f526..81afad4 100755 --- a/raspi-config +++ b/raspi-config @@ -320,6 +320,14 @@ wt_yesno_wide() { wt_yesno "$1" "$2" $WT_BOX_WIDTH_WIDE } +wt_inputbox() { + whiptail --inputbox "$1" $WT_BOX_HEIGHT $WT_BOX_WIDTH "$2" 3>&1 1>&2 2>&3 +} + +wt_passwordbox() { + whiptail --passwordbox "$1" $WT_BOX_HEIGHT $WT_BOX_WIDTH 3>&1 1>&2 2>&3 +} + do_about() { wt_msgbox_wide "\ This tool provides a straightforward way of doing initial @@ -1038,7 +1046,7 @@ No other symbols, punctuation characters, or blank spaces are permitted.\ fi CURRENT_HOSTNAME=$(get_hostname) if [ "$INTERACTIVE" = True ]; then - NEW_HOSTNAME=$(whiptail --inputbox "Please enter a hostname" 20 60 "$CURRENT_HOSTNAME" 3>&1 1>&2 2>&3) + NEW_HOSTNAME=$(wt_inputbox "Please enter a hostname" "$CURRENT_HOSTNAME") else NEW_HOSTNAME="$1" true @@ -1824,7 +1832,7 @@ do_fan() { fi if [ $RET -eq 0 ] ; then if [ "$INTERACTIVE" = True ]; then - GPIO=$(whiptail --inputbox "To which GPIO is the fan connected?" 20 60 "$GNOW" 3>&1 1>&2 2>&3) + GPIO=$(wt_inputbox "To which GPIO is the fan connected?" "$GNOW") else if [ -z $2 ]; then GPIO=14 @@ -1848,7 +1856,7 @@ do_fan() { return 1 fi if [ "$INTERACTIVE" = True ]; then - TIN=$(whiptail --inputbox "At what temperature in degrees Celsius should the fan turn on?" 20 60 "$TNOW" 3>&1 1>&2 2>&3) + TIN=$(wt_inputbox "At what temperature in degrees Celsius should the fan turn on?" "$TNOW") else if [ -z $3 ]; then TIN=80 @@ -3189,7 +3197,7 @@ do_wifi_ssid_passphrase() { SSID="$1" while [ -z "$SSID" ] && [ "$INTERACTIVE" = True ]; do - if ! SSID=$(whiptail --inputbox "Please enter SSID" 20 60 3>&1 1>&2 2>&3); then + if ! SSID=$(wt_inputbox "Please enter SSID"); then return 0 elif [ -z "$SSID" ]; then wt_msgbox "SSID cannot be empty. Please try again." @@ -3198,7 +3206,7 @@ do_wifi_ssid_passphrase() { PASSPHRASE="$2" while [ "$INTERACTIVE" = True ]; do - if ! PASSPHRASE=$(whiptail --passwordbox "Please enter passphrase. Leave it empty if none." 20 60 3>&1 1>&2 2>&3); then + if ! PASSPHRASE=$(wt_passwordbox "Please enter passphrase. Leave it empty if none."); then return 0 else break @@ -3572,7 +3580,7 @@ do_proxy() { else STRING="Please enter proxy address.\\nEg: http://user:pass@proxy:8080" fi - if ! ADDRESS="$(whiptail --inputbox "$STRING" 20 60 "$CURRENT" 3>&1 1>&2 2>&3)"; then + if ! ADDRESS="$(wt_inputbox "$STRING" "$CURRENT")"; then return 0 fi fi @@ -4133,7 +4141,7 @@ if [ "$INTERACTIVE" = True ]; then [ -e $CONFIG ] || touch $CONFIG calc_wt_size while [ "$USER" = "root" ] || [ -z "$USER" ]; do - if ! USER=$(whiptail --inputbox "raspi-config could not determine the default user.\\n\\nWhat user should these settings apply to?" 20 60 pi 3>&1 1>&2 2>&3); then + if ! USER=$(wt_inputbox "raspi-config could not determine the default user.\\n\\nWhat user should these settings apply to?" "pi"); then return 0 fi done From 31cf244cf59d128ed8bbba3aefff85a2d44eb614 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 16:35:48 +0000 Subject: [PATCH 07/10] Add wt_menu, wt_sub_menu and wt_top_menu wrapper functions --- raspi-config | 186 +++++++++++++++++++++++++++------------------------ 1 file changed, 100 insertions(+), 86 deletions(-) diff --git a/raspi-config b/raspi-config index 81afad4..c49e161 100755 --- a/raspi-config +++ b/raspi-config @@ -328,6 +328,20 @@ wt_passwordbox() { whiptail --passwordbox "$1" $WT_BOX_HEIGHT $WT_BOX_WIDTH 3>&1 1>&2 2>&3 } +wt_menu() { + MENU_TITLE="$1" + shift + whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "$MENU_TITLE" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT "$@" 3>&1 1>&2 2>&3 +} + +wt_sub_menu() { + wt_menu "$@" --cancel-button Back --ok-button Select +} + +wt_top_menu() { + wt_menu "$@" --cancel-button Finish --ok-button Select +} + do_about() { wt_msgbox_wide "\ This tool provides a straightforward way of doing initial @@ -551,10 +565,10 @@ do_overscan_kms() { if [ "$INTERACTIVE" = True ]; then NDEVS=$(xrandr -q | grep -c connected) if [ $NDEVS -gt 1 ] ; then - DEV=$(whiptail --menu "Select the output for which overscan compensation is to be set" 20 60 10 \ + DEV=$(wt_menu "Select the output for which overscan compensation is to be set" \ "1" "HDMI-1" \ "2" "HDMI-2" \ - 3>&1 1>&2 2>&3) + ) if [ $? -eq 1 ] ; then return fi @@ -970,7 +984,7 @@ do_wifi_country() { oIFS="$IFS" IFS="/" #shellcheck disable=2086 - REGDOMAIN=$(whiptail --menu "Select the country in which the Pi is to be used" 20 60 10 ${value} 3>&1 1>&2 2>&3) + REGDOMAIN=$(wt_menu "Select the country in which the Pi is to be used" ${value}) RET=$? IFS="$oIFS" if [ $RET -eq 1 ]; then # user selected Cancel @@ -1076,18 +1090,18 @@ shift during boot to temporarily disable overclock. See https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md for more information.\ " if is_pione; then - OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \ + OVERCLOCK=$(wt_menu "Choose overclock preset" \ "None" "700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ "Modest" "800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ "Medium" "900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt" \ "High" "950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt" \ "Turbo" "1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt" \ - 3>&1 1>&2 2>&3) + ) elif is_pitwo; then - OVERCLOCK=$(whiptail --menu "Choose overclock preset" 20 60 10 \ + OVERCLOCK=$(wt_menu "Choose overclock preset" \ "None" "900MHz ARM, 250MHz core, 450MHz SDRAM, 0 overvolt" \ "High" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" \ - 3>&1 1>&2 2>&3) + ) fi else OVERCLOCK=$1 @@ -1911,10 +1925,10 @@ get_browser() { do_browser() { if [ "$INTERACTIVE" = True ]; then - RES=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Select Browser" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + RES=$(wt_menu "Select Browser" \ "1" "Chromium" \ "2" "Firefox" \ - 3>&1 1>&2 2>&3) + ) else RES="" BROWSER=$1 @@ -1942,13 +1956,13 @@ do_browser() { do_journald_storage() { if [ "$INTERACTIVE" = True ]; then - RES=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Select Log Location" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + RES=$(wt_menu "Select Log Location" \ "1" "Default" \ "2" "Volatile" \ "3" "Persistent" \ "4" "Auto" \ "5" "None" \ - 3>&1 1>&2 2>&3) + ) else RES="" true @@ -1976,12 +1990,12 @@ do_journald_storage() { do_boot_behaviour() { if [ "$INTERACTIVE" = True ]; then - BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Boot Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + BOOTOPT=$(wt_menu "Boot Options" \ "B1 Console" "Text console, requiring user to login" \ "B2 Console Autologin" "Text console, automatically logged in as '$USER' user" \ "B3 Desktop" "Desktop GUI, requiring user to login" \ "B4 Desktop Autologin" "Desktop GUI, automatically logged in as '$USER' user" \ - 3>&1 1>&2 2>&3) + ) else BOOTOPT=$1 true @@ -2064,10 +2078,10 @@ get_bootloader_filename() { do_network_install_ui() { if [ "$INTERACTIVE" = True ]; then - BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Bootloader network install UI" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + BOOTOPT=$(wt_menu "Bootloader network install UI" \ "B1 Always" "Always display the UI for a few seconds after power on." \ "B2 On demand" "Display the UI if the SHIFT key is presssed or if an error occurs." \ - 3>&1 1>&2 2>&3) + ) else BOOTOPT=$1 true @@ -2105,10 +2119,10 @@ do_network_install_ui() { do_libliftoff() { if [ "$INTERACTIVE" = True ]; then - RET=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "libliftoff Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + RET=$(wt_menu "libliftoff Options" \ "L1 Disable" "Disable libliftoff hardware overlays" \ "L2 Enable" "Enable libliftoff hardware overlays (experimental)" \ - 3>&1 1>&2 2>&3) + ) else RET=$1 true @@ -2160,10 +2174,10 @@ do_libliftoff() { # shellcheck disable=SC2120 do_power_off_on_halt() { if [ "$INTERACTIVE" = True ]; then - BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Configure shutdown behaviour." "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" \ + BOOTOPT=$(wt_menu "Configure shutdown behaviour." \ "B1 Full power off" "Switch off Pi power management (PMIC) outputs on Pi4 / Pi5 (recommended)." \ "B2 VPU sleep mode" "Compatibility mode for HATs (e.g. POE HAT) and GPIO power buttons (Pi4)." \ - 3>&1 1>&2 2>&3) + ) else BOOTOPT=$1 true @@ -2205,11 +2219,11 @@ do_power_off_on_halt() { do_boot_order() { if [ "$INTERACTIVE" = True ]; then - BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Boot Device Order" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + BOOTOPT=$(wt_menu "Boot Device Order" \ "B1 SD Card Boot " "Boot from SD Card before trying NVMe and then USB (RECOMMENDED)" \ "B2 NVMe/USB Boot" "Boot from NVMe before trying USB and then SD Card" \ "B3 Network Boot " "Boot from Network unless override by SD Card" \ - 3>&1 1>&2 2>&3) + ) else BOOTOPT=$1 true @@ -2278,10 +2292,10 @@ do_boot_order() { do_boot_rom() { if [ "$INTERACTIVE" = True ]; then - BOOTOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Bootloader Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + BOOTOPT=$(wt_menu "Bootloader Options" \ "E1 Latest" "Use the latest bootloader image" \ "E2 Default" "Use the factory default bootloader image" \ - 3>&1 1>&2 2>&3) + ) else BOOTOPT=$1 true @@ -2628,10 +2642,10 @@ do_gldriver() { wt_msgbox "Required packages not found, please install: ${missing_packages}" return 1 fi - GLOPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "GL Driver" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + GLOPT=$(wt_menu "GL Driver" \ "G1 Legacy" "Original non-GL desktop driver" \ "G2 GL (Full KMS)" "OpenGL desktop driver with full KMS" \ - 3>&1 1>&2 2>&3) + ) if [ $? -eq 0 ]; then case "$GLOPT" in G1*) @@ -2740,16 +2754,16 @@ do_glamor() { do_wayland() { if [ "$INTERACTIVE" = True ]; then if [ -f /usr/bin/labwc ]; then - RET=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Wayland Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + RET=$(wt_menu "Wayland Options" \ "W1 X11" "Openbox window manager with X11 backend" \ "W2 Wayfire" "Wayfire window manager with Wayland backend" \ "W3 Labwc" "Labwc window manager with Wayland backend" \ - 3>&1 1>&2 2>&3) + ) else - RET=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Wayland Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + RET=$(wt_menu "Wayland Options" \ "W1 X11" "Openbox window manager with X11 backend" \ "W2 Wayfire" "Wayfire window manager with Wayland backend" \ - 3>&1 1>&2 2>&3) + ) fi else RET=$1 @@ -2828,7 +2842,7 @@ do_audioconf() { OPTIONS="$OPTIONS 2 Pipewire" fi #shellcheck disable=2086 - PPOPT=$(whiptail --menu "Select the audio configuration to use" 20 60 10 $OPTIONS --default-item "$DEFAULT" 3>&1 1>&2 2>&3) + PPOPT=$(wt_menu "Select the audio configuration to use" $OPTIONS --default-item $DEFAULT) RET="$?" fi else @@ -2926,7 +2940,7 @@ do_audio() { list=$(sudo -u $USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID LANG=C pactl list sinks | grep -e "Sink #" -e "alsa.card_name" | sed s/*//g | sed s/^[' '\\t]*//g | sed s/'Sink #'//g | sed s/'alsa.card_name = '//g | sed s/'bcm2835 '//g | sed s/\"//g | tr '\n' '/') if [ -n "$list" ] ; then IFS="/" - AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 ${list} 3>&1 1>&2 2>&3) + AUDIO_OUT=$(wt_menu "Choose the audio output" ${list}) else wt_msgbox "No internal audio devices found" return 1 @@ -2942,11 +2956,11 @@ do_audio() { else if aplay -l | grep -q "bcm2835 ALSA"; then if [ "$INTERACTIVE" = True ]; then - AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 \ + AUDIO_OUT=$(wt_menu "Choose the audio output" \ "0" "Auto" \ "1" "Force 3.5mm ('headphone') jack" \ "2" "Force HDMI" \ - 3>&1 1>&2 2>&3) + ) else AUDIO_OUT=$1 fi @@ -2979,7 +2993,7 @@ do_audio() { else oIFS="$IFS" IFS="/" - AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 ${array} 3>&1 1>&2 2>&3) + AUDIO_OUT=$(wt_menu "Choose the audio output" ${array}) IFS="$oIFS" fi else @@ -3034,7 +3048,7 @@ do_resolution() { value=$value$(tvservice -m CEA | grep progressive | cut -b 12- | sed 's/mode \([0-9]\+\): \([0-9]\+\)x\([0-9]\+\) @ \([0-9]\+\)Hz \([0-9]\+\):\([0-9]\+\), clock:[0-9]\+MHz progressive/CEA Mode \1\/\2x\3 \4Hz \5:\6/' | tr '\n' '/') value=$value$(tvservice -m DMT | grep progressive | cut -b 12- | sed 's/mode \([0-9]\+\): \([0-9]\+\)x\([0-9]\+\) @ \([0-9]\+\)Hz \([0-9]\+\):\([0-9]\+\), clock:[0-9]\+MHz progressive/DMT Mode \1\/\2x\3 \4Hz \5:\6/' | tr '\n' '/') fi - RES=$(whiptail --default-item $CSET --menu "Choose screen resolution" 20 60 10 ${value} 3>&1 1>&2 2>&3) + RES=$(wt_menu "Choose screen resolution" ${value} --default-item $CSET) STATUS=$? IFS="$oIFS" if [ $STATUS -eq 0 ] ; then @@ -3107,7 +3121,7 @@ do_vnc_resolution() { if [ "$CUR" = "" ] ; then CUR=640x480 fi - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --default-item $CUR --menu "Set VNC Resolution" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_menu "Set VNC Resolution" "640x480" "" \ "720x480" "" \ "800x600" "" \ @@ -3116,7 +3130,8 @@ do_vnc_resolution() { "1280x1024" "" \ "1600x1200" "" \ "1920x1080" "" \ - 3>&1 1>&2 2>&3) + --default-item $CUR \ + ) RET=$? else FUN=$1 @@ -3669,11 +3684,11 @@ get_squeekboard() { do_squeekboard() { if [ "$INTERACTIVE" = True ]; then - OPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "On-screen Keyboard" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ + OPT=$(wt_menu "On-screen Keyboard" \ "S1 Always On" "On-screen keyboard always enabled" \ "S2 Autodetect" "On-screen keyboard enabled if touch device found" \ "S3 Always Off" "On-screen keyboard disabled" \ - 3>&1 1>&2 2>&3) + ) else OPT=$1 true @@ -3761,9 +3776,7 @@ do_squeek_output() { menu=$($PREFIX wlr-randr | grep -v ^' ' | cut -d ' ' -f 1 | tr '\n' '/' | sed 's#/#//#g') oIFS="$IFS" IFS="/" - OPT=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Select where the on-screen keyboard is to be shown" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT \ - ${menu} \ - 3>&1 1>&2 2>&3) + OPT=$(wt_menu "Select where the on-screen keyboard is to be shown" ${menu}) IFS="$oIFS" else OPT=$1 @@ -3848,7 +3861,7 @@ fi do_system_menu() { if is_pi ; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "System Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "System Options" \ "S1 Wireless LAN" "Enter SSID and passphrase" \ "S2 Audio" "Select audio out through HDMI or 3.5mm jack" \ "S3 Password" "Change password for the '$USER' user" \ @@ -3858,22 +3871,22 @@ do_system_menu() { "S7 Power LED" "Set behaviour of power LED" \ "S8 Browser" "Choose default web browser" \ "S9 Logging" "Set storage location for logs" \ - 3>&1 1>&2 2>&3) + ) elif is_live ; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "System Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "System Options" \ "S1 Wireless LAN" "Enter SSID and passphrase" \ "S3 Password" "Change password for the '$USER' user" \ "S4 Hostname" "Set name for this computer on a network" \ "S5 Boot / Auto Login" "Select boot into desktop or to command line" \ - 3>&1 1>&2 2>&3) + ) else - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "System Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "System Options" \ "S1 Wireless LAN" "Enter SSID and passphrase" \ "S3 Password" "Change password for the '$USER' user" \ "S4 Hostname" "Set name for this computer on a network" \ "S5 Boot / Auto Login" "Select boot into desktop or to command line" \ "S6 Splash Screen" "Choose graphical splash screen or text boot" \ - 3>&1 1>&2 2>&3) + ) fi RET=$? if [ $RET -eq 1 ]; then @@ -3898,44 +3911,44 @@ do_display_menu() { if is_pi ; then if is_wayland; then if is_pifour; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Display Options" \ "D2 Screen Blanking" "Enable/disable screen blanking" \ "D4 Composite" "Enable/disable composite output" \ "D5 4Kp60 HDMI" "Enable 4Kp60 resolution on HDMI0" \ "D6 Onscreen Keyboard" "Enable on-screen keyboard" \ "D7 Keyboard Output" "Select monitor used for on-screen keyboard" \ - 3>&1 1>&2 2>&3) + ) else - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Display Options" \ "D2 Screen Blanking" "Enable/disable screen blanking" \ "D4 Composite" "Enable/disable composite output" \ "D6 Onscreen Keyboard" "Enable on-screen keyboard" \ "D7 Keyboard Output" "Select monitor used for on-screen keyboard" \ - 3>&1 1>&2 2>&3) + ) fi else if is_pifour; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Display Options" \ "D1 Underscan" "Remove black border around screen" \ "D2 Screen Blanking" "Enable/disable screen blanking" \ "D3 VNC Resolution" "Set resolution for headless use" \ "D4 Composite" "Enable/disable composite output" \ "D5 4Kp60 HDMI" "Enable 4Kp60 resolution on HDMI0" \ - 3>&1 1>&2 2>&3) + ) else - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Display Options" \ "D1 Underscan" "Remove black border around screen" \ "D2 Screen Blanking" "Enable/disable screen blanking" \ "D3 VNC Resolution" "Set resolution for headless use" \ "D4 Composite" "Enable/disable composite output" \ - 3>&1 1>&2 2>&3) + ) fi fi else - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Display Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Display Options" \ "D1 Underscan" "Remove black border around screen" \ "D2 Screen Blanking" "Enable/disable screen blanking" \ - 3>&1 1>&2 2>&3) + ) fi RET=$? if [ $RET -eq 1 ]; then @@ -3956,7 +3969,7 @@ do_display_menu() { do_interface_menu() { if is_pi ; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Interfacing Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Interfacing Options" \ "I1 SSH" "Enable/disable remote command line access using SSH" \ "I2 RPi Connect" "Enable/disable Raspberry Pi Connect" \ "I3 VNC" "Enable/disable graphical remote desktop access" \ @@ -3965,11 +3978,11 @@ do_interface_menu() { "I6 Serial Port" "Enable/disable shell messages on the serial connection" \ "I7 1-Wire" "Enable/disable one-wire interface" \ "I8 Remote GPIO" "Enable/disable remote access to GPIO pins" \ - 3>&1 1>&2 2>&3) + ) else - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Interfacing Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Interfacing Options" \ "I1 SSH" "Enable/disable remote command line access using SSH" \ - 3>&1 1>&2 2>&3) + ) fi RET=$? if [ $RET -eq 1 ]; then @@ -3991,21 +4004,21 @@ do_interface_menu() { do_performance_menu() { case "$(get_pi_type)" in - [03]) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + [03]) FUN=$(wt_sub_menu "Performance Options" \ "P2 Overlay File System" "Enable/disable read-only file system" \ - 3>&1 1>&2 2>&3) ;; - [12]) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + ) ;; + [12]) FUN=$(wt_sub_menu "Performance Options" \ "P1 Overclock" "Configure CPU overclocking" \ "P2 Overlay File System" "Enable/disable read-only file system" \ - 3>&1 1>&2 2>&3) ;; - 4) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + ) ;; + 4) FUN=$(wt_sub_menu "Performance Options" \ "P2 Overlay File System" "Enable/disable read-only file system" \ "P3 Fan" "Set behaviour of GPIO case fan" \ - 3>&1 1>&2 2>&3) ;; - *) FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Performance Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + ) ;; + *) FUN=$(wt_sub_menu "Performance Options" \ "P2 Overlay File System" "Enable/disable read-only file system" \ "P4 USB Current" "Set USB current limit" \ - 3>&1 1>&2 2>&3) ;; + ) ;; esac RET=$? if [ $RET -eq 1 ]; then @@ -4022,12 +4035,12 @@ do_performance_menu() { } do_internationalisation_menu() { - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Localisation Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Localisation Options" \ "L1 Locale" "Configure language and regional settings" \ "L2 Timezone" "Configure time zone" \ "L3 Keyboard" "Set keyboard layout to match your keyboard" \ "L4 WLAN Country" "Set legal wireless channels for your country" \ - 3>&1 1>&2 2>&3) + ) RET=$? if [ $RET -eq 1 ]; then return 0 @@ -4044,7 +4057,7 @@ do_internationalisation_menu() { do_advanced_menu() { if is_pifour ; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Advanced Options" \ "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ "A3 Network Proxy Settings" "Configure network proxy settings" \ @@ -4055,9 +4068,9 @@ do_advanced_menu() { "A9 Network Install UI" "Select display of bootloader network install UI" \ "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ "A11 Shutdown Behaviour" "Configure shutdown behavior" \ - 3>&1 1>&2 2>&3) + ) elif is_pifive ; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Advanced Options" \ "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ "A3 Network Proxy Settings" "Configure network proxy settings" \ @@ -4069,24 +4082,24 @@ do_advanced_menu() { "A9 Network Install UI" "Select display of bootloader network install UI" \ "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ "A11 Shutdown Behaviour" "Configure shutdown behavior" \ - 3>&1 1>&2 2>&3) + ) elif is_pi ; then - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Advanced Options" \ "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ "A3 Network Proxy Settings" "Configure network proxy settings" \ "A6 Wayland" "Switch between X and Wayland backends" \ "A7 Audio Config" "Set audio control system" \ "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ - 3>&1 1>&2 2>&3) + ) else - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Advanced Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Advanced Options" \ "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ "A3 Network Proxy Settings" "Configure network proxy settings" \ "A6 Wayland" "Switch between X and Wayland backends" \ "A7 Audio Config" "Set audio control system" \ "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ - 3>&1 1>&2 2>&3) + ) fi RET=$? if [ $RET -eq 1 ]; then @@ -4110,14 +4123,14 @@ do_advanced_menu() { } do_proxy_menu() { - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Network Proxy Settings" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Back --ok-button Select \ + FUN=$(wt_sub_menu "Network Proxy Settings" \ "P1 All" "Set the same proxy for all schemes" \ "P2 HTTP" "Set the HTTP proxy" \ "P3 HTTPS" "Set the HTTPS/SSL proxy" \ "P4 FTP" "Set the FTP proxy" \ "P5 RSYNC" "Set the RSYNC proxy" \ "P6 Exceptions" "Set addresses for which a proxy server should not be used" \ - 3>&1 1>&2 2>&3) + ) RET=$? if [ $RET -eq 1 ]; then return 0 @@ -4156,7 +4169,7 @@ if [ "$INTERACTIVE" = True ]; then fi MENU_BACKTITLE="$(cat /proc/device-tree/model), ${FMEMSIZE}" fi - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --backtitle "$MENU_BACKTITLE" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \ + FUN=$(wt_top_menu "Setup Options" \ "1 System Options" "Configure system settings" \ "2 Display Options" "Configure display settings" \ "3 Interface Options" "Configure connections to peripherals" \ @@ -4165,9 +4178,10 @@ if [ "$INTERACTIVE" = True ]; then "6 Advanced Options" "Configure advanced settings" \ "8 Update" "Update this tool to the latest version" \ "9 About raspi-config" "Information about this configuration tool" \ - 3>&1 1>&2 2>&3) + --backtitle "$MENU_BACKTITLE" \ + ) else - FUN=$(whiptail --title "Raspberry Pi Software Configuration Tool (raspi-config)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \ + FUN=$(wt_top_menu "Setup Options" \ "1 System Options" "Configure system settings" \ "2 Display Options" "Configure display settings" \ "3 Interface Options" "Configure connections to peripherals" \ @@ -4175,7 +4189,7 @@ if [ "$INTERACTIVE" = True ]; then "6 Advanced Options" "Configure advanced settings" \ "8 Update" "Update this tool to the latest version" \ "9 About raspi-config" "Information about this configuration tool" \ - 3>&1 1>&2 2>&3) + ) fi RET=$? if [ $RET -eq 1 ]; then From 862464e8db356507db447f2c39022f14322fa723 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 17:57:59 +0000 Subject: [PATCH 08/10] Some small shellcheck fixes --- raspi-config | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/raspi-config b/raspi-config index c49e161..22ae0d1 100755 --- a/raspi-config +++ b/raspi-config @@ -803,7 +803,7 @@ update_labwc_keyboard() { if grep -q XKB_DEFAULT_OPTIONS $UFILE ; then sed -i s/XKB_DEFAULT_OPTIONS.*/XKB_DEFAULT_OPTIONS=$OPTIONS/ $UFILE ; else echo XKB_DEFAULT_OPTIONS=$OPTIONS >> $UFILE ; fi fi if is_labwc ; then - kill -HUP `pgrep -x labwc` # does the equivalent of labwc --reconfigure, but works as sudo... + kill -HUP $(pgrep -x labwc) # does the equivalent of labwc --reconfigure, but works as sudo... fi } @@ -822,7 +822,7 @@ update_squeekboard() { else GSET=$GSET"+$VARIANT1')" fi - if ! [ -z "$LAYOUT2" ] ; then + if [ -n "$LAYOUT2" ] ; then GSET=$GSET", ('xkb', '$LAYOUT2" if [ -z "$VARIANT2" ] ; then GSET=$GSET"')" @@ -1920,7 +1920,7 @@ do_fan() { } get_browser() { - echo $(update-alternatives --display x-www-browser | grep currently | cut -d " " -f 7 | cut -d / -f 4) + update-alternatives --display x-www-browser | grep currently | cut -d " " -f 7 | cut -d / -f 4 } do_browser() { @@ -1980,7 +1980,7 @@ do_journald_storage() { *) JSTRING="" ;; esac - REPLACEMENT="$([ ! -z $JSTRING ] && echo "Storage=$JSTRING" || echo "#Storage=auto")" + REPLACEMENT="$([ -n "$JSTRING" ] && echo "Storage=$JSTRING" || echo "#Storage=auto")" sed --in-place -E "s/^#?Storage=.*/${REPLACEMENT}/" /etc/systemd/journald.conf if [ "$INTERACTIVE" = True ]; then wt_msgbox "Logging location set to ${JSTRING:-default}" @@ -3302,8 +3302,7 @@ do_wifi_ssid_passphrase() { do_finish() { disable_raspi_config_at_boot if [ $ASK_TO_REBOOT -eq 1 ]; then - wt_yesno "Would you like to reboot now?" - if [ $? -eq 0 ]; then # yes + if wt_yesno "Would you like to reboot now?" ; then # yes sync reboot fi @@ -3376,7 +3375,7 @@ do_apply_os_config() { do_change_locale "$DEBLANGUAGE" fi - if [ -n "$NOOBSKEYBOARD" -a "$NOOBSKEYBOARD" != "gb" ]; then + if [ -n "$NOOBSKEYBOARD" ] && [ "$NOOBSKEYBOARD" != "gb" ]; then printf "Setting keyboard layout to %s based on os_config.json from NOOBS. May take a while\n" "$NOOBSKEYBOARD" do_configure_keyboard "$NOOBSKEYBOARD" fi @@ -3761,7 +3760,7 @@ EOF get_squeek_output (){ if [ -e /usr/share/squeekboard/output ] ; then - echo `grep SQUEEKBOARD_PREFERRED_OUTPUT /usr/share/squeekboard/output | cut -d = -f 2` + grep SQUEEKBOARD_PREFERRED_OUTPUT /usr/share/squeekboard/output | cut -d = -f 2 else echo "" fi @@ -4165,7 +4164,7 @@ if [ "$INTERACTIVE" = True ]; then if [ $MEMSIZE -lt 1024 ]; then FMEMSIZE="${MEMSIZE}MB" else - FMEMSIZE="$(expr $MEMSIZE / 1024)GB" + FMEMSIZE="$((MEMSIZE / 1024))GB" fi MENU_BACKTITLE="$(cat /proc/device-tree/model), ${FMEMSIZE}" fi From 5e92a7a21cfa63ca92430a9fb0f9ac30738fc59e Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 19:17:57 +0000 Subject: [PATCH 09/10] Build some of the menus dynamically, for more flexibility and less repetition --- raspi-config | 294 +++++++++++++++++++++------------------------------ 1 file changed, 122 insertions(+), 172 deletions(-) diff --git a/raspi-config b/raspi-config index 22ae0d1..a9e2a85 100755 --- a/raspi-config +++ b/raspi-config @@ -1090,19 +1090,18 @@ shift during boot to temporarily disable overclock. See https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md for more information.\ " if is_pione; then - OVERCLOCK=$(wt_menu "Choose overclock preset" \ + set -- \ "None" "700MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ "Modest" "800MHz ARM, 250MHz core, 400MHz SDRAM, 0 overvolt" \ "Medium" "900MHz ARM, 250MHz core, 450MHz SDRAM, 2 overvolt" \ "High" "950MHz ARM, 250MHz core, 450MHz SDRAM, 6 overvolt" \ - "Turbo" "1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt" \ - ) + "Turbo" "1000MHz ARM, 500MHz core, 600MHz SDRAM, 6 overvolt" elif is_pitwo; then - OVERCLOCK=$(wt_menu "Choose overclock preset" \ + set -- \ "None" "900MHz ARM, 250MHz core, 450MHz SDRAM, 0 overvolt" \ - "High" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" \ - ) + "High" "1000MHz ARM, 500MHz core, 500MHz SDRAM, 2 overvolt" fi + OVERCLOCK=$(wt_menu "Choose overclock preset" "$@") else OVERCLOCK=$1 true @@ -2753,18 +2752,14 @@ do_glamor() { do_wayland() { if [ "$INTERACTIVE" = True ]; then + set -- \ + "W1 X11" "Openbox window manager with X11 backend" \ + "W2 Wayfire" "Wayfire window manager with Wayland backend" if [ -f /usr/bin/labwc ]; then - RET=$(wt_menu "Wayland Options" \ - "W1 X11" "Openbox window manager with X11 backend" \ - "W2 Wayfire" "Wayfire window manager with Wayland backend" \ - "W3 Labwc" "Labwc window manager with Wayland backend" \ - ) - else - RET=$(wt_menu "Wayland Options" \ - "W1 X11" "Openbox window manager with X11 backend" \ - "W2 Wayfire" "Wayfire window manager with Wayland backend" \ - ) + set -- "$@" \ + "W3 Labwc" "Labwc window manager with Wayland backend" fi + RET=$(wt_menu "Wayland Options" "$@") else RET=$1 true @@ -2835,14 +2830,17 @@ do_audioconf() { wt_msgbox "No audio systems installed" RET=1 else + set -- if is_installed pulseaudio ; then - OPTIONS="1 PulseAudio" + set -- "$@" \ + "1" "PulseAudio" fi if is_installed pipewire-pulse ; then - OPTIONS="$OPTIONS 2 Pipewire" + set -- "$@" \ + "2" "Pipewire" fi #shellcheck disable=2086 - PPOPT=$(wt_menu "Select the audio configuration to use" $OPTIONS --default-item $DEFAULT) + PPOPT=$(wt_menu "Select the audio configuration to use" "$@" --default-item $DEFAULT) RET="$?" fi else @@ -3859,34 +3857,30 @@ if [ -n "${OPT_MEMORY_SPLIT:-}" ]; then fi do_system_menu() { + set -- \ + "S1 Wireless LAN" "Enter SSID and passphrase" if is_pi ; then - FUN=$(wt_sub_menu "System Options" \ - "S1 Wireless LAN" "Enter SSID and passphrase" \ - "S2 Audio" "Select audio out through HDMI or 3.5mm jack" \ - "S3 Password" "Change password for the '$USER' user" \ - "S4 Hostname" "Set name for this computer on a network" \ - "S5 Boot / Auto Login" "Select boot into desktop or to command line" \ - "S6 Splash Screen" "Choose graphical splash screen or text boot" \ - "S7 Power LED" "Set behaviour of power LED" \ + set -- "$@" \ + "S2 Audio" "Select audio out through HDMI or 3.5mm jack" + fi + set -- "$@" \ + "S3 Password" "Change password for the '$USER' user" \ + "S4 Hostname" "Set name for this computer on a network" \ + "S5 Boot / Auto Login" "Select boot into desktop or to command line" + if ! is_live ; then + set -- "$@" \ + "S6 Splash Screen" "Choose graphical splash screen or text boot" + fi + if is_pi ; then + if [ $(get_leds) -ne -1 ]; then + set -- "$@" \ + "S7 Power LED" "Set behaviour of power LED" + fi + set -- "$@" \ "S8 Browser" "Choose default web browser" \ - "S9 Logging" "Set storage location for logs" \ - ) - elif is_live ; then - FUN=$(wt_sub_menu "System Options" \ - "S1 Wireless LAN" "Enter SSID and passphrase" \ - "S3 Password" "Change password for the '$USER' user" \ - "S4 Hostname" "Set name for this computer on a network" \ - "S5 Boot / Auto Login" "Select boot into desktop or to command line" \ - ) - else - FUN=$(wt_sub_menu "System Options" \ - "S1 Wireless LAN" "Enter SSID and passphrase" \ - "S3 Password" "Change password for the '$USER' user" \ - "S4 Hostname" "Set name for this computer on a network" \ - "S5 Boot / Auto Login" "Select boot into desktop or to command line" \ - "S6 Splash Screen" "Choose graphical splash screen or text boot" \ - ) + "S9 Logging" "Set storage location for logs" fi + FUN=$(wt_sub_menu "System Options" "$@") RET=$? if [ $RET -eq 1 ]; then return 0 @@ -3907,48 +3901,27 @@ do_system_menu() { } do_display_menu() { + set -- + if ! is_pi || ! is_wayland ; then + set -- "$@" \ + "D1 Underscan" "Remove black border around screen" + fi + set -- "$@" \ + "D2 Screen Blanking" "Enable/disable screen blanking" if is_pi ; then + set -- "$@" \ + "D4 Composite" "Enable/disable composite output" + if is_pifour; then + set -- "$@" \ + "D5 4Kp60 HDMI" "Enable 4Kp60 resolution on HDMI0" + fi if is_wayland; then - if is_pifour; then - FUN=$(wt_sub_menu "Display Options" \ - "D2 Screen Blanking" "Enable/disable screen blanking" \ - "D4 Composite" "Enable/disable composite output" \ - "D5 4Kp60 HDMI" "Enable 4Kp60 resolution on HDMI0" \ - "D6 Onscreen Keyboard" "Enable on-screen keyboard" \ - "D7 Keyboard Output" "Select monitor used for on-screen keyboard" \ - ) - else - FUN=$(wt_sub_menu "Display Options" \ - "D2 Screen Blanking" "Enable/disable screen blanking" \ - "D4 Composite" "Enable/disable composite output" \ - "D6 Onscreen Keyboard" "Enable on-screen keyboard" \ - "D7 Keyboard Output" "Select monitor used for on-screen keyboard" \ - ) - fi - else - if is_pifour; then - FUN=$(wt_sub_menu "Display Options" \ - "D1 Underscan" "Remove black border around screen" \ - "D2 Screen Blanking" "Enable/disable screen blanking" \ - "D3 VNC Resolution" "Set resolution for headless use" \ - "D4 Composite" "Enable/disable composite output" \ - "D5 4Kp60 HDMI" "Enable 4Kp60 resolution on HDMI0" \ - ) - else - FUN=$(wt_sub_menu "Display Options" \ - "D1 Underscan" "Remove black border around screen" \ - "D2 Screen Blanking" "Enable/disable screen blanking" \ - "D3 VNC Resolution" "Set resolution for headless use" \ - "D4 Composite" "Enable/disable composite output" \ - ) - fi + set -- "$@" \ + "D6 Onscreen Keyboard" "Enable on-screen keyboard" \ + "D7 Keyboard Output" "Select monitor used for on-screen keyboard" fi - else - FUN=$(wt_sub_menu "Display Options" \ - "D1 Underscan" "Remove black border around screen" \ - "D2 Screen Blanking" "Enable/disable screen blanking" \ - ) fi + FUN=$(wt_sub_menu "Display Options" "$@") RET=$? if [ $RET -eq 1 ]; then return 0 @@ -3967,22 +3940,19 @@ do_display_menu() { } do_interface_menu() { + set -- \ + "I1 SSH" "Enable/disable remote command line access using SSH" if is_pi ; then - FUN=$(wt_sub_menu "Interfacing Options" \ - "I1 SSH" "Enable/disable remote command line access using SSH" \ + set -- "$@" \ "I2 RPi Connect" "Enable/disable Raspberry Pi Connect" \ "I3 VNC" "Enable/disable graphical remote desktop access" \ "I4 SPI" "Enable/disable automatic loading of SPI kernel module" \ "I5 I2C" "Enable/disable automatic loading of I2C kernel module" \ "I6 Serial Port" "Enable/disable shell messages on the serial connection" \ "I7 1-Wire" "Enable/disable one-wire interface" \ - "I8 Remote GPIO" "Enable/disable remote access to GPIO pins" \ - ) - else - FUN=$(wt_sub_menu "Interfacing Options" \ - "I1 SSH" "Enable/disable remote command line access using SSH" \ - ) + "I8 Remote GPIO" "Enable/disable remote access to GPIO pins" fi + FUN=$(wt_sub_menu "Interfacing Options" "$@") RET=$? if [ $RET -eq 1 ]; then return 0 @@ -4002,23 +3972,22 @@ do_interface_menu() { } do_performance_menu() { - case "$(get_pi_type)" in - [03]) FUN=$(wt_sub_menu "Performance Options" \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - ) ;; - [12]) FUN=$(wt_sub_menu "Performance Options" \ - "P1 Overclock" "Configure CPU overclocking" \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - ) ;; - 4) FUN=$(wt_sub_menu "Performance Options" \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - "P3 Fan" "Set behaviour of GPIO case fan" \ - ) ;; - *) FUN=$(wt_sub_menu "Performance Options" \ - "P2 Overlay File System" "Enable/disable read-only file system" \ - "P4 USB Current" "Set USB current limit" \ - ) ;; - esac + set -- + if is_pione || is_pitwo ; then + set -- "$@" \ + "P1 Overclock" "Configure CPU overclocking" + fi + set -- "$@" \ + "P2 Overlay File System" "Enable/disable read-only file system" + if is_pifour ; then + set -- "$@" \ + "P3 Fan" "Set behaviour of GPIO case fan" + fi + if is_pifive ; then + set -- "$@" \ + "P4 USB Current" "Set USB current limit" + fi + FUN=$(wt_sub_menu "Performance Options" "$@") RET=$? if [ $RET -eq 1 ]; then return 0 @@ -4055,51 +4024,37 @@ do_internationalisation_menu() { } do_advanced_menu() { - if is_pifour ; then - FUN=$(wt_sub_menu "Advanced Options" \ - "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ - "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ - "A3 Network Proxy Settings" "Configure network proxy settings" \ - "A4 Boot Order" "Choose boot device priority (SD/net/USB/NVMe)" \ - "A5 Bootloader Version" "Select bootloader (latest/factory default)" \ - "A6 Wayland" "Switch between X and Wayland backends" \ - "A7 Audio Config" "Set audio control system" \ - "A9 Network Install UI" "Select display of bootloader network install UI" \ - "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ - "A11 Shutdown Behaviour" "Configure shutdown behavior" \ - ) - elif is_pifive ; then - FUN=$(wt_sub_menu "Advanced Options" \ - "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ - "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ - "A3 Network Proxy Settings" "Configure network proxy settings" \ - "A4 Boot Order" "Choose boot device priority (SD/net/USB/NVMe)" \ - "A5 Bootloader Version" "Select bootloader (latest/factory default)" \ - "A6 Wayland" "Switch between X and Wayland backends" \ - "A7 Audio Config" "Set audio control system" \ - "A8 PCIe Speed" "Set PCIe x1 port speed" \ - "A9 Network Install UI" "Select display of bootloader network install UI" \ - "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ - "A11 Shutdown Behaviour" "Configure shutdown behavior" \ - ) - elif is_pi ; then - FUN=$(wt_sub_menu "Advanced Options" \ - "A1 Expand Filesystem" "Ensures that all of the SD card is available" \ - "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ - "A3 Network Proxy Settings" "Configure network proxy settings" \ - "A6 Wayland" "Switch between X and Wayland backends" \ - "A7 Audio Config" "Set audio control system" \ - "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ - ) - else - FUN=$(wt_sub_menu "Advanced Options" \ - "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ - "A3 Network Proxy Settings" "Configure network proxy settings" \ - "A6 Wayland" "Switch between X and Wayland backends" \ - "A7 Audio Config" "Set audio control system" \ - "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" \ - ) + set -- + if is_pi ; then + set -- "$@" \ + "A1 Expand Filesystem" "Ensures that all of the SD card is available" + fi + set -- "$@" \ + "A2 Network Interface Names" "Enable/disable predictable network i/f names" \ + "A3 Network Proxy Settings" "Configure network proxy settings" + if gpu_has_mmu ; then + set -- "$@" \ + "A4 Boot Order" "Choose boot device priority (SD/net/USB/NVMe)" \ + "A5 Bootloader Version" "Select bootloader (latest/factory default)" + fi + set -- "$@" \ + "A6 Wayland" "Switch between X and Wayland backends" \ + "A7 Audio Config" "Set audio control system" + if is_pifive ; then + set -- "$@" \ + "A8 PCIe Speed" "Set PCIe x1 port speed" fi + if gpu_has_mmu ; then + set -- "$@" \ + "A9 Network Install UI" "Select display of bootloader network install UI" + fi + set -- "$@" \ + "A10 Libliftoff" "Enable/disable libliftoff hardware overlays" + if gpu_has_mmu ; then + set -- "$@" \ + "A11 Shutdown Behaviour" "Configure shutdown behavior" + fi + FUN=$(wt_sub_menu "Advanced Options" "$@") RET=$? if [ $RET -eq 1 ]; then return 0 @@ -4158,6 +4113,19 @@ if [ "$INTERACTIVE" = True ]; then fi done while true; do + set -- \ + "1 System Options" "Configure system settings" \ + "2 Display Options" "Configure display settings" \ + "3 Interface Options" "Configure connections to peripherals" + if is_pi ; then + set -- "$@" \ + "4 Performance Options" "Configure performance settings" + fi + set -- "$@" \ + "5 Localisation Options" "Configure language and regional settings" \ + "6 Advanced Options" "Configure advanced settings" \ + "8 Update" "Update this tool to the latest version" \ + "9 About raspi-config" "Information about this configuration tool" if is_pi ; then if [ -z "$MENU_BACKTITLE" ]; then MEMSIZE=$(vcgencmd get_config total_mem|cut -d= -f2) @@ -4168,28 +4136,10 @@ if [ "$INTERACTIVE" = True ]; then fi MENU_BACKTITLE="$(cat /proc/device-tree/model), ${FMEMSIZE}" fi - FUN=$(wt_top_menu "Setup Options" \ - "1 System Options" "Configure system settings" \ - "2 Display Options" "Configure display settings" \ - "3 Interface Options" "Configure connections to peripherals" \ - "4 Performance Options" "Configure performance settings" \ - "5 Localisation Options" "Configure language and regional settings" \ - "6 Advanced Options" "Configure advanced settings" \ - "8 Update" "Update this tool to the latest version" \ - "9 About raspi-config" "Information about this configuration tool" \ - --backtitle "$MENU_BACKTITLE" \ - ) - else - FUN=$(wt_top_menu "Setup Options" \ - "1 System Options" "Configure system settings" \ - "2 Display Options" "Configure display settings" \ - "3 Interface Options" "Configure connections to peripherals" \ - "5 Localisation Options" "Configure language and regional settings" \ - "6 Advanced Options" "Configure advanced settings" \ - "8 Update" "Update this tool to the latest version" \ - "9 About raspi-config" "Information about this configuration tool" \ - ) + set -- "$@" \ + --backtitle "$MENU_BACKTITLE" fi + FUN=$(wt_top_menu "Setup Options" "$@") RET=$? if [ $RET -eq 1 ]; then do_finish From dc784b17eed8c8bbee9d563a0a95d914960ad810 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Thu, 13 Feb 2025 19:19:06 +0000 Subject: [PATCH 10/10] Don't display composite-video option on Pi 400 or Pi 500 --- raspi-config | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/raspi-config b/raspi-config index a9e2a85..c268cc5 100755 --- a/raspi-config +++ b/raspi-config @@ -67,7 +67,7 @@ else CMDLINE=/proc/cmdline fi -# tests for Pi 1, 2, 0 and CM5 all test for specific boards... +# tests for Pi 1, 2, 0, CM5 and x00 all test for specific boards... is_pione() { if [ -z "$IS_PIONE" ]; then @@ -106,6 +106,14 @@ is_cmfive() { return $IS_CMFIVE } +is_pihundred() { + if [ -z "$IS_PIHUNDRED" ]; then + grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]1[39][0-9a-fA-F]$" /proc/cpuinfo + IS_PIHUNDRED=$? + fi + return $IS_PIHUNDRED +} + # ...while tests for Pi 3, 4 and 5 just test processor type, so will also find CM3, CM4, Zero 2 etc. is_pithree() { @@ -3909,8 +3917,10 @@ do_display_menu() { set -- "$@" \ "D2 Screen Blanking" "Enable/disable screen blanking" if is_pi ; then - set -- "$@" \ - "D4 Composite" "Enable/disable composite output" + if ! is_pihundred ; then + set -- "$@" \ + "D4 Composite" "Enable/disable composite output" + fi if is_pifour; then set -- "$@" \ "D5 4Kp60 HDMI" "Enable 4Kp60 resolution on HDMI0"