Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding style fix: replace whiptail with a wrapper function #168

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/armbian-configng/config.ng.jobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 10 additions & 10 deletions lib/armbian-configng/config.ng.network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
10 changes: 5 additions & 5 deletions lib/armbian-configng/config.ng.software.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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+=(
Expand All @@ -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+=(
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions lib/armbian-configng/config.ng.system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <space> to toggle functions and save them.\nExit when you are done.\n " \
0 0 0 "${options[@]}" 3>&1 1>&2 2>&3)
exit_status=$?
Expand All @@ -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
Expand Down
Loading