Improve wizard and set-time UX

This commit is contained in:
nagumii 2025-02-07 00:59:38 +02:00
parent a66a97e2a9
commit f5a7303046
3 changed files with 76 additions and 90 deletions

View file

@ -425,12 +425,48 @@ set_lora_radio() {
done
}
legacy_admin() {
choice="" # zero the choice before loading the submenu
while true; do
loading "Getting current legacy admin state..."
choice=$(dialog --no-collapse --colors --title "Legacy Admin" --default-item "$choice" --help-button --item-help --menu "If the node you Femtofox needs to administer or be administered by is running 2.4.x or earlier, you should set this to Enabled.\n\nCurrent state: $(replace_colors "$(femto-meshtasticd-config.sh -p)")" 16 65 5 \
1 "Enable" "" \
2 "Disable (default)" "" \
" " "" "" \
3 "Return to previous menu" "" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -eq 1 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
elif [ $exit_status -eq 2 ]; then # Help ("extra") button
dialog --no-collapse --colors --title "System info help" --msgbox "For Meshtastic versions 2.4.x and earlier, remote admin is achieved by creating a secondary channel named admin with a shared PSK. In this setup, messages exchanged on this channel are encrypted only with the channel's PSK, allowing any node in the channel to administer others.\n\nFor more information:\nhttps://meshtastic.org/docs/configuration/remote-admin/\n" 0 0
else
case $choice in
1) # enable legacy admin)
dialog --no-collapse --title "Legacy Admin" --yesno "Enable legacy admin channel?\n" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
loading "Sending command..."
dialog --no-collapse --colors --title "Legacy admin" --msgbox "$(femto-meshtasticd-config.sh -o "true" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
fi
;;
2) # disable legacy admin)
dialog --no-collapse --title "Legacy Admin" --yesno "Disable legacy admin channel?\n" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
loading "Sending command..."
dialog --no-collapse --colors --title "Legacy admin" --msgbox "$(femto-meshtasticd-config.sh -o "false" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
fi
;;
3) break ;;
esac
fi
done
}
# Function to handle Meshtasticd settings
meshtastic_settings() {
local title="Meshtastic Settings"
while true; do
echo "Checking Meshtasticd service state..."
meshtastic_choice=$(dialog --no-collapse --colors --title "$title" --cancel-label "Back" --default-item "$meshtastic_choice" --item-help --menu "Meshtasticd service is $(replace_colors "$(femto-meshtasticd-config.sh -S)")$(femto-meshtasticd-config.sh -k | grep -q 'simulated' && echo '\n\Z1Warning: using simulated radio\Zn')" 20 50 4 \
meshtastic_choice=$(dialog --no-collapse --colors --title "$title" --cancel-label "Back" --default-item "$meshtastic_choice" --item-help --menu "Meshtasticd service is $(replace_colors "$(femto-meshtasticd-config.sh -S)")$(femto-meshtasticd-config.sh -k | grep -q 'simulated' && echo '\n\Z1Warning: using simulated radio\Zn')" 19 50 4 \
1 "View node info" "" \
2 "View configuration URL & QR code" "" \
3 "Set new configuration URL" "" \
@ -532,33 +568,7 @@ meshtastic_settings() {
fi
;;
6) # legacy admin)
choice="" # zero the choice before loading the submenu
while true; do
loading "Getting current legacy admin state..."
choice=$(dialog --no-collapse --colors --title "Legacy Admin" --default-item "$choice" --item-help --menu "Current state: $(replace_colors "$(femto-meshtasticd-config.sh -p)")" 12 40 5 \
1 "Enable" "" \
2 "Disable (default)" "" \
" " "" "" \
3 "Return to previous menu" "" 3>&1 1>&2 2>&3)
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
1) # enable legacy admin)
dialog --no-collapse --title "Legacy Admin" --yesno "Enable legacy admin channel?\n" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
loading "Sending command..."
dialog --no-collapse --colors --title "Legacy admin" --msgbox "$(femto-meshtasticd-config.sh -o "true" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
fi
;;
2) # disable legacy admin)
dialog --no-collapse --title "Legacy Admin" --yesno "Disable legacy admin channel?\n" 0 0
if [ $? -eq 0 ]; then #unless cancel/no
loading "Sending command..."
dialog --no-collapse --colors --title "Legacy admin" --msgbox "$(femto-meshtasticd-config.sh -o "false" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
fi
;;
3) break ;;
esac
done
legacy_admin
;;
7) # return to previous menu)
break
@ -715,9 +725,10 @@ help="If script is run without arguments, femto-config menu will load.\n\
Options are:\n\
-h This message\n\
-l Set LoRa radio model menu\n\
-L Meshtastic legacy admin menu\n\
-w Set Wi-Fi config menu\
"
while getopts ":hlwL:i" opt; do
while getopts ":hlwLi" opt; do
case ${opt} in
h) # Option -h (help)
echo -e $help
@ -725,6 +736,9 @@ while getopts ":hlwL:i" opt; do
l) # Option -l (set lora radio)
set_lora_radio
;;
L) # Option -L (Meshtastic legacy admin menu)
legacy_admin
;;
w) # Option -w (Wi-Fi config)
wifi_config
;;

View file

@ -16,29 +16,32 @@ loading() {
title="Install Wizard"
wizard() {
femto-set-time.sh
dialog --title "$title" --cancel-label "Skip" --yesno "\nConfigure network settings?" 8 40
new_hostname=$(dialog --title "Hostname" --cancel-label "Skip" --inputbox "Enter hostname:" 8 40 $(hostname) 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then #unless cancel/no
femto-network-config.sh -n "$new_hostname"
dialog --title "Hostname" --msgbox "\nFemtofox is now reachable at\n$new_hostname.local" 8 40
fi
dialog --title "$title" --cancel-label "Skip" --yesno "Configure Wi-Fi settings?" 6 40
if [ $? -eq 0 ]; then #unless cancel/no
new_hostname=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter hostname:" 8 40 $(hostname) 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then #unless cancel/no
femto-network-config.sh -n "$new_hostname"
dialog --title "$title" --msgbox "\nFemtofox is now reachable at\n$new_hostname.local" 8 40
fi
femto-config -w
fi
dialog --title "$title" --cancel-label "Skip" --yesno "\nConfigure Meshtastic?" 8 40
dialog --title "$title" --cancel-label "Skip" --yesno "Configure Meshtastic?" 6 40
if [ $? -eq 0 ]; then #unless cancel/no
femto-config -l #set lora radio model
newurl=$(dialog --title "Meshtastic URL" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 60 3>&1 1>&2 2>&3)
newurl=$(dialog --title "Meshtastic URL" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 50 3>&1 1>&2 2>&3)
if [ -n "$newurl" ]; then #if a URL was entered
loading "Sending URL..."
dialog --no-collapse --colors --title "Meshtastic URL" --msgbox "$(femto-meshtasticd-config.sh -q "$newurl" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
fi
# public key
loading "Getting current public key..."
key=$(femto-meshtasticd-config.sh -u)
if [ -n "$key" ]; then
@ -54,6 +57,7 @@ wizard() {
dialog --no-collapse --colors --title "Meshtastic public key" --msgbox "\Z1Failed to communicate with Meshtasticd.\Zn\n\nIs the service running?\n" 0 0
fi
# private key
loading "Getting current private key..."
key=$(femto-meshtasticd-config.sh -u)
if [ -n "$key" ]; then
@ -69,55 +73,23 @@ wizard() {
dialog --no-collapse --colors --title "Meshtastic private key" --msgbox "\Z1Failed to communicate with Meshtasticd.\Zn\n\nIs the service running?\n" 0 0
fi
key=$(dialog --title "$title" --cancel-label "Skip" --inputbox "Enter Meshtastic admin key (optional). If 3 admin keys are already in Meshtastic, more will be ignored.\n(SHIFT+INS to paste):" 11 50 3>&1 1>&2 2>&3)
key=$(dialog --title "Meshtastic admin key" --cancel-label "Skip" --inputbox "Enter Meshtastic admin key (optional). If 3 admin keys are already in Meshtastic, more will be ignored.\n(SHIFT+INS to paste):" 11 50 3>&1 1>&2 2>&3)
if [ -n "$key" ]; then #if a URL was entered
loading "Sending key..."
dialog --no-collapse --colors --title "Meshtastic URL" --msgbox "$(femto-meshtasticd-config.sh -A "$key" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
fi
dialog --no-collapse --infobox "Getting current legacy admin state..." 5 45
state=$(sudo femto-meshtasticd-config.sh -p)
if echo "$state" | grep -q "enabled"; then # poor man's replace ansi colors
state="\Z4enabled\Zn"
elif echo "$state" | grep -q "disabled"; then
state="\Z1disabled\Zn"
elif echo "$state" | grep -q "error"; then
state="\Z1error\Zn"
fi
while true; do
choice=$(dialog --no-collapse --colors --cancel-label "Skip" --title "Meshtasticd Legacy Admin" --menu "Current state: $state" 12 40 5 \
1 "Enable" \
2 "Disable (default)" \
"" "" \
3 "Skip" 3>&1 1>&2 2>&3)
exit_status=$? # This line checks the exit status of the dialog command
if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog
break
fi
case $choice in
1) # enable legacy admin)
dialog --no-collapse --infobox "Sending command..." 5 45
dialog --no-collapse --colors --title "$title" --msgbox "$(femto-meshtasticd-config.sh -o "true" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
break
;;
2) # disable legacy admin)
dialog --no-collapse --infobox "Sending command..." 5 45
dialog --no-collapse --colors --title "$title" --msgbox "$(femto-meshtasticd-config.sh -o "false" && echo -e "\n\Z4Command successful!\Zn\n" || echo -e "\n\Z1Command failed.\Zn\n")" 0 0
break
;;
3) break ;;
esac
done
femto-config -L # legacy admin menu
fi
dialog --title "$title" --msgbox "\nSetup wizard complete!" 8 40
dialog --title "$title" --msgbox "Setup wizard complete!" 6 40
}
dialog --title "$title" --yesno "\
The install wizard will allow you to configure all the basic settings necessary to run your Femtofox.\n\
The install wizard will allow you to configure all the settings necessary to run your Femtofox.\n\
\n\
Running this wizard will overwrite some current settings.\n\n\
Proceed?" 13 50
The wizard takes several minutes to complete and will overwrite some current settings.\n\n\
Proceed?" 12 60
if [ $? -eq 0 ]; then #unless cancel/no
wizard
fi

View file

@ -19,15 +19,6 @@ If no argument is specified, a menu system will be used. Options are:
EOF
)
log_message() {
logger $1
if [ $arg_count -eq 0 ]; then
dialog --msgbox "$1" 12 50
else
echo -e $1
fi
}
set_timezone() {
echo "Setting time zone..."
ln -f -s /usr/share/zoneinfo/$1 /etc/localtime >/dev/null 2>&1
@ -68,7 +59,7 @@ done
if [ $arg_count -eq 0 ]; then # if the script was launched with no arguments, then load the UI.
echo "Loading current time settings..."
current_timezone=$(timedatectl show --property=Timezone --value)
dialog --no-collapse --title "$title" --yesno "Current system time: $(date +"%H:%M:%S")\nCurrent time zone: $current_timezone ($(date +"UTC%z" | sed -E 's/GMT([+-])0?([0-9]{1,2})00/GMT\1\2/'))\n$(hwclock >/dev/null 2>&1 && echo "RTC module found!" || echo "RTC module not found.")\n\nSet new time and timezone?" 10 60
dialog --no-collapse --title "System time" --yesno "Current system time: $(date +"%H:%M:%S")\nCurrent time zone: $current_timezone ($(date +"UTC%z" | sed -E 's/GMT([+-])0?([0-9]{1,2})00/GMT\1\2/'))\n$(hwclock >/dev/null 2>&1 && echo "RTC module found!" || echo "RTC module not found.")\n\nSet new time and timezone?" 10 60
if [ $? -eq 1 ]; then #unless cancel/no
exit 0
fi
@ -85,7 +76,7 @@ if [ $arg_count -eq 0 ]; then # if the script was launched with no arguments, th
options_str=$(printf '%s\n' "${options[@]}")
# Show timezone selection menu with preselection of current timezone
selected_timezone=$(dialog --title "Select Time Zone" \
selected_timezone=$(dialog --title "Set Time Zone" \
--default-item "$current_timezone" \
--menu "Current time zone: $current_timezone (UTC$(date +%z))" 20 60 10 \
$(printf "%s " "${options[@]}") 3>&1 1>&2 2>&3)
@ -97,7 +88,7 @@ if [ $arg_count -eq 0 ]; then # if the script was launched with no arguments, th
exit 1
fi
DATE=$(dialog --title "Select Date" --calendar "Current date: $(date "+%B %d, %Y") \nPress [TAB] to select." 0 0 $(date +%d) $(date +%m) $(date +%Y) 3>&1 1>&2 2>&3)
DATE=$(dialog --title "Set Date" --calendar "Current date: $(date "+%B %d, %Y") \nPress [TAB] to select." 0 0 $(date +%d) $(date +%m) $(date +%Y) 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then
exit 1
fi
@ -106,7 +97,16 @@ if [ $arg_count -eq 0 ]; then # if the script was launched with no arguments, th
if [ $? -eq 1 ]; then #if cancel/no
exit 1
fi
log_message "$(set_timestamp $(date -d "$DATE $TIME" +%s))"
exit $? #exit status matches set_timestamp exit status
msg="$(set_timestamp $(date -d "$DATE $TIME" +%s))"
exit_status=$?
logger $msg
if [ $arg_count -eq 0 ]; then
dialog --msgbox "$msg" 13 50
else
echo -e $msg
fi
exit $exit_status #exit status matches set_timestamp exit status
fi