Tweak return values and error trapping for whiptail menu array; fix reboot prompt bug in WLAN country setting

This commit is contained in:
Simon Long 2020-10-12 15:04:47 +01:00
parent 1a4671f109
commit 39b2604ae9

View File

@ -549,10 +549,9 @@ do_wifi_country() {
oIFS="$IFS" oIFS="$IFS"
if [ "$INTERACTIVE" = True ]; then if [ "$INTERACTIVE" = True ]; then
IFS="/"
value=$(cat /usr/share/zoneinfo/iso3166.tab | tail -n +26 | tr '\t' '/' | tr '\n' '/') value=$(cat /usr/share/zoneinfo/iso3166.tab | tail -n +26 | tr '\t' '/' | tr '\n' '/')
IFS="/"
COUNTRY=$(whiptail --menu "Select the country in which the Pi is to be used" 20 60 10 ${value} 3>&1 1>&2 2>&3) COUNTRY=$(whiptail --menu "Select the country in which the Pi is to be used" 20 60 10 ${value} 3>&1 1>&2 2>&3)
IFS=$oIFS
else else
COUNTRY=$1 COUNTRY=$1
true true
@ -560,7 +559,7 @@ do_wifi_country() {
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
wpa_cli -i "$IFACE" set country "$COUNTRY" wpa_cli -i "$IFACE" set country "$COUNTRY"
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1 wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
if ! iw reg set "$COUNTRY" 2> /dev/null; then if iw reg set "$COUNTRY" 2> /dev/null; then
ASK_TO_REBOOT=1 ASK_TO_REBOOT=1
fi fi
if hash rfkill 2> /dev/null; then if hash rfkill 2> /dev/null; then
@ -575,6 +574,7 @@ do_wifi_country() {
whiptail --msgbox "Wireless LAN country set to $COUNTRY" 20 60 1 whiptail --msgbox "Wireless LAN country set to $COUNTRY" 20 60 1
fi fi
fi fi
IFS=$oIFS
} }
get_hostname() { get_hostname() {
@ -1872,21 +1872,24 @@ do_update() {
do_audio() { do_audio() {
if is_pulseaudio ; then if is_pulseaudio ; then
if [ "$INTERACTIVE" = True ]; then
oIFS="$IFS" oIFS="$IFS"
IFS="/" if [ "$INTERACTIVE" = True ]; then
list=$(sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pacmd list-sinks | grep -e index -e alsa.name | sed s/*//g | sed s/^[' '\\t]*//g | sed s/'index: '//g | sed s/'alsa.name = '//g | sed s/'bcm2835 '//g | sed s/\"//g | tr '\n' '/') list=$(sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pacmd list-sinks | grep -e index -e alsa.name | sed s/*//g | sed s/^[' '\\t]*//g | sed s/'index: '//g | sed s/'alsa.name = '//g | sed s/'bcm2835 '//g | sed s/\"//g | tr '\n' '/')
if ! [ -z "$list" ] ; then if ! [ -z "$list" ] ; then
IFS="/"
AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 ${list} 3>&1 1>&2 2>&3) AUDIO_OUT=$(whiptail --menu "Choose the audio output" 20 60 10 ${list} 3>&1 1>&2 2>&3)
else else
whiptail --msgbox "No internal audio devices found" 20 60 1 whiptail --msgbox "No internal audio devices found" 20 60 1
return 1 return 1
fi fi
IFS=$oIFS
else else
AUDIO_OUT=$1 AUDIO_OUT=$1
true
fi fi
if [ $? -eq 0 ]; then
sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pactl set-default-sink $AUDIO_OUT sudo -u $SUDO_USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pactl set-default-sink $AUDIO_OUT
fi
IFS=$oIFS
else else
if aplay -l | grep -q "bcm2835 ALSA"; then if aplay -l | grep -q "bcm2835 ALSA"; then
if [ "$INTERACTIVE" = True ]; then if [ "$INTERACTIVE" = True ]; then