From ca8c468254ab5f3e3fa73760a7ea52c9a24efad2 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Tue, 8 Oct 2024 12:49:52 +0200 Subject: [PATCH] Coding style fix: replace whiptail with a wrapper function --- lib/armbian-configng/config.ng.jobs.json | 2 +- lib/armbian-configng/config.ng.network.sh | 20 ++++++++++---------- lib/armbian-configng/config.ng.software.sh | 10 +++++----- lib/armbian-configng/config.ng.system.sh | 6 +++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/armbian-configng/config.ng.jobs.json b/lib/armbian-configng/config.ng.jobs.json index a4a47b621..37fcf939f 100644 --- a/lib/armbian-configng/config.ng.jobs.json +++ b/lib/armbian-configng/config.ng.jobs.json @@ -576,7 +576,7 @@ "id": "L04", "description": "Change System Hostname", "command": [ - "NEW_HOSTNAME=$(whiptail --title \"Enter new hostnane\" --inputbox \"\" 7 50 3>&1 1>&2 2>&3)", + "NEW_HOSTNAME=$($DIALOG --title \"Enter new hostnane\" --inputbox \"\" 7 50 3>&1 1>&2 2>&3)", "[ $? -eq 0 ] && [ -n \"${NEW_HOSTNAME}\" ] && hostnamectl set-hostname \"${NEW_HOSTNAME}\"" ], "status": "Preview", diff --git a/lib/armbian-configng/config.ng.network.sh b/lib/armbian-configng/config.ng.network.sh index 35c395399..039e84491 100644 --- a/lib/armbian-configng/config.ng.network.sh +++ b/lib/armbian-configng/config.ng.network.sh @@ -164,7 +164,7 @@ function network_config() { fi done LIST_LENGTH=$((${#LIST[@]} / 2)) - adapter=$(whiptail --title "Select interface" --menu "" $((${LIST_LENGTH} + 8)) 60 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) + adapter=$($DIALOG --title "Select interface" --menu "" $((${LIST_LENGTH} + 8)) 60 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) if [[ -n $adapter && $? == 0 ]]; then # # Wireless networking @@ -174,7 +174,7 @@ function network_config() { LIST=("sta" "Connect to access point") LIST+=("ap" "Become an access point") LIST_LENGTH=$((${#LIST[@]} / 2)) - wifimode=$(whiptail --title "Select wifi mode" --menu "" $((${LIST_LENGTH} + 8)) 60 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) + wifimode=$($DIALOG --title "Select wifi mode" --menu "" $((${LIST_LENGTH} + 8)) 60 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) if [[ "${wifimode}" == "sta" && $? == 0 ]]; then ip link set ${adapter} up systemctl stop hostapd 2> /dev/null @@ -183,9 +183,9 @@ function network_config() { LIST=($(iw dev ${adapter} scan 2> /dev/null | grep 'SSID\|^BSS' | cut -d" " -f2 | sed "s/(.*//g" | xargs -n2 -d'\n' | awk '{print $2,$1}')) sleep 2 LIST_LENGTH=$((${#LIST[@]} / 2)) - SELECTED_SSID=$(whiptail --title "Select SSID" --menu "rf" $((${LIST_LENGTH} + 6)) 50 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) + SELECTED_SSID=$($DIALOG --title "Select SSID" --menu "rf" $((${LIST_LENGTH} + 6)) 50 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) if [[ -n $SELECTED_SSID ]]; then - SELECTED_PASSWORD=$(whiptail --title "Enter new password for $SELECTED_SSID" --passwordbox "" 7 50 3>&1 1>&2 2>&3) + SELECTED_PASSWORD=$($DIALOG --title "Enter new password for $SELECTED_SSID" --passwordbox "" 7 50 3>&1 1>&2 2>&3) if [[ -n $SELECTED_PASSWORD ]]; then # connect to AP netplan set --origin-hint ${yamlfile} renderer=${renderer} @@ -199,9 +199,9 @@ function network_config() { check_if_installed hostapd && debconf-apt-progress -- apt-get -y --no-install-recommends hostapd - SELECTED_SSID=$(whiptail --title "Enter SSID for AP" --inputbox "" 7 50 3>&1 1>&2 2>&3) + SELECTED_SSID=$($DIALOG --title "Enter SSID for AP" --inputbox "" 7 50 3>&1 1>&2 2>&3) if [[ -n "${SELECTED_SSID}" && $? == 0 ]]; then - SELECTED_PASSWORD=$(whiptail --title "Enter new password for $SELECTED_SSID" --passwordbox "" 7 50 3>&1 1>&2 2>&3) + SELECTED_PASSWORD=$($DIALOG --title "Enter new password for $SELECTED_SSID" --passwordbox "" 7 50 3>&1 1>&2 2>&3) if [[ -n "${SELECTED_PASSWORD}" && $? == 0 ]]; then # start bridged AP netplan set --origin-hint ${yamlfile} renderer=${renderer} @@ -242,7 +242,7 @@ function network_config() { # LIST=("dhcp" "Auto IP assigning") LIST+=("static" "Set IP manually") - wiredmode=$(whiptail --title "Select IP mode" --menu "" $((${LIST_LENGTH} + 8)) 60 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) + wiredmode=$($DIALOG --title "Select IP mode" --menu "" $((${LIST_LENGTH} + 8)) 60 $((${LIST_LENGTH})) "${LIST[@]}" 3>&1 1>&2 2>&3) if [[ "${wiredmode}" == "dhcp" && $? == 0 ]]; then netplan set --origin-hint ${yamlfile} renderer=${renderer} netplan set --origin-hint ${yamlfile} ethernets.$adapter.dhcp4=no @@ -254,13 +254,13 @@ function network_config() { elif [[ "${wiredmode}" == "static" ]]; then address=$(ip -br addr show dev $adapter | awk '{print $3}') [[ -z "${address}" ]] && address="1.2.3.4/5" - address=$(whiptail --title "Enter IP for $adapter" --inputbox "\nValid format: $address" 9 40 "$address" 3>&1 1>&2 2>&3) + address=$($DIALOG --title "Enter IP for $adapter" --inputbox "\nValid format: $address" 9 40 "$address" 3>&1 1>&2 2>&3) if [[ -n $address && $? == 0 ]]; then defaultroute=$(ip route show default | grep "$adapter" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]" | head 1 | xargs) - defaultroute=$(whiptail --title "Enter IP for default route" --inputbox "\nValid format: $defaultroute" 9 40 "$defaultroute" 3>&1 1>&2 2>&3) + defaultroute=$($DIALOG --title "Enter IP for default route" --inputbox "\nValid format: $defaultroute" 9 40 "$defaultroute" 3>&1 1>&2 2>&3) if [[ -n $defaultroute && $? == 0 ]]; then nameservers="9.9.9.9,1.1.1.1" - nameservers=$(whiptail --title "Enter DNS server" --inputbox "\nValid format: $nameservers" 9 40 "$nameservers" 3>&1 1>&2 2>&3) + nameservers=$($DIALOG --title "Enter DNS server" --inputbox "\nValid format: $nameservers" 9 40 "$nameservers" 3>&1 1>&2 2>&3) fi if [[ -n $nameservers && $? == 0 ]]; then netplan set --origin-hint ${yamlfile} renderer=${renderer} diff --git a/lib/armbian-configng/config.ng.software.sh b/lib/armbian-configng/config.ng.software.sh index 162e96687..4f72b0352 100644 --- a/lib/armbian-configng/config.ng.software.sh +++ b/lib/armbian-configng/config.ng.software.sh @@ -43,7 +43,7 @@ install_plexmediaserver() { wget -qO- https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor | sudo tee /usr/share/keyrings/plexmediaserver.gpg > /dev/null 2>&1 apt_install_wrapper apt-get update apt_install_wrapper apt-get -y install plexmediaserver - whiptail --msgbox "To test that Plex Media Server has installed successfully\nIn a web browser go to http://localhost:32400/web or \nhttp://127.0.0.1:32400/web on this computer." 9 70 + $DIALOG --msgbox "To test that Plex Media Server has installed successfully\nIn a web browser go to http://localhost:32400/web or \nhttp://127.0.0.1:32400/web on this computer." 9 70 } module_options+=( @@ -62,10 +62,10 @@ install_embyserver() { grep "/emby-server-deb.*$(dpkg --print-architecture).deb" | cut -d : -f 2,3 | tr -d '"') cd ~/ wget -O "emby-server.deb" $URL 2>&1 | stdbuf -oL awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' | - whiptail --gauge "Please wait\nDownloading ${URL##*/}" 8 70 0 + $DIALOG --gauge "Please wait\nDownloading ${URL##*/}" 8 70 0 apt_install_wrapper apt-get -y install ~/emby-server.deb unlink emby-server.deb - whiptail --msgbox "To test that Emby Server has installed successfully\nIn a web browser go to http://localhost:8096 or \nhttp://127.0.0.1:8096 on this computer." 9 70 + $DIALOG --msgbox "To test that Emby Server has installed successfully\nIn a web browser go to http://localhost:8096 or \nhttp://127.0.0.1:8096 on this computer." 9 70 } module_options+=( @@ -100,10 +100,10 @@ install_docker() { fi systemctl enable docker.service > /dev/null 2>&1 systemctl enable containerd.service > /dev/null 2>&1 - whiptail --msgbox "To test that Docker has installed successfully\nrun the following command: docker run hello-world" 9 70 + $DIALOG --msgbox "To test that Docker has installed successfully\nrun the following command: docker run hello-world" 9 70 fi else - whiptail --msgbox "ERROR ! ${DISTRO} $DISTROID distribution not found in repository!" 7 70 + $DIALOG --msgbox "ERROR ! ${DISTRO} $DISTROID distribution not found in repository!" 7 70 fi } diff --git a/lib/armbian-configng/config.ng.system.sh b/lib/armbian-configng/config.ng.system.sh index 9fa0d638c..ec519c098 100644 --- a/lib/armbian-configng/config.ng.system.sh +++ b/lib/armbian-configng/config.ng.system.sh @@ -329,7 +329,7 @@ function adjust_motd() { done INLIST=($(grep THIS_SCRIPT= /etc/update-motd.d/* | cut -d"=" -f2 | sed "s/\"//g")) - CHOICES=$(whiptail --separate-output --nocancel --title "Adjust welcome screen" --checklist "" 11 50 5 "${LIST[@]}" 3>&1 1>&2 2>&3) + CHOICES=$($DIALOG --separate-output --nocancel --title "Adjust welcome screen" --checklist "" 11 50 5 "${LIST[@]}" 3>&1 1>&2 2>&3) INSERT="$(echo "${INLIST[@]}" "${CHOICES[@]}" | tr ' ' '\n' | sort | uniq -u | tr '\n' ' ' | sed 's/ *$//')" # adjust motd config sed -i "s/^MOTD_DISABLE=.*/MOTD_DISABLE=\"$INSERT\"/g" /etc/default/armbian-motd @@ -363,7 +363,7 @@ function manage_dtoverlays () { grep '^fdt_overlays' ${overlayconf} | grep -qw ${overlay} && status=ON options+=( "$overlay" "" "$status") done - selection=$(whiptail --title "Manage devicetree overlays" --cancel-button "Back" \ + selection=$($DIALOG --title "Manage devicetree overlays" --cancel-button "Back" \ --ok-button "Save" --checklist "\nUse to toggle functions and save them.\nExit when you are done.\n " \ 0 0 0 "${options[@]}" 3>&1 1>&2 2>&3) exit_status=$? @@ -377,7 +377,7 @@ function manage_dtoverlays () { ;; 1) if [[ "$changes" == "true" ]]; then - whiptail --title " Reboot required " --yes-button "Reboot" \ + $DIALOG --title " Reboot required " --yes-button "Reboot" \ --no-button "Cancel" --yesno "A reboot is required to apply the changes. Shall we reboot now?" 7 34 if [[ $? = 0 ]]; then reboot