Add ttyd service management to menu

This commit is contained in:
nagumii 2025-02-04 20:01:02 +02:00
parent 60f8b583b7
commit 9012d9f6e5
2 changed files with 82 additions and 20 deletions

View file

@ -191,12 +191,13 @@ utilities() {
5 "Run USB configuration tool" "" \
6 "Run OEM luckfox-config" "" \
7 "Process viewer/manager" "" \
8 "Disable/enable logging" "" \
9 "Disable/enable activity LED" "" \
10 "Reboot" "" \
11 "Shutdown" "" \
8 "Disable/enable web terminal" "" \
9 "Disable/enable logging" "" \
10 "Disable/enable activity LED" "" \
11 "Reboot" "" \
12 "Shutdown" "" \
" " "" "" \
12 "Back to main menu" "" 3>&1 1>&2 2>&3)
13 "Back to main menu" "" 3>&1 1>&2 2>&3)
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $utilities_choice in
@ -287,9 +288,32 @@ $(ingest_data "femto-meshtasticd-config.sh -i" 15)" 0 0
;;
6) luckfox-config ;;
7) htop ;;
8) # logging)
8)
choice="" # zero the choice before loading the submenu
while true; do
echo "Checking web terminal status..."
ttyd_state=$(replace_colors "$(femto-utils.sh -t "check")")
choice=$(dialog --no-collapse --colors --title "Web Terminal" --cancel-label "Back" --default-item "$choice" --item-help --menu "Web terminal available at \Zuhttp://$(hostname)local:7681\Zn\nCurrent state: $ttyd_state" 14 57 2 \
$(if ! echo "$ttyd_state" | grep -q 'enabled and running'; then echo "Enable and start (default) x  "; fi) \
$(if echo "$ttyd_state" | grep -q 'enabled'; then echo "Disable and stop x  "; fi) \
$(if echo "$ttyd_state" | grep -q 'enabled'; then echo "Start/restart ttyd service x  "; fi) \
$(if echo "$ttyd_state" | grep -q 'enabled'; then echo "View detailed service status x  "; fi) \
" " "" "" \
"Return to previous menu" "x" "" 3>&1 1>&2 2>&3)
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
case $choice in
"Enable and start (default)") femto-utils.sh -t "enable" ;;
"Disable and stop") femto-utils.sh -t "disable" ;;
"Start/restart ttyd service") femto-utils.sh -t "start" ;;
"View detailed service status") dialog --no-collapse --title "ttyd service status" --msgbox "$(systemctl status ttyd)" 0 0 ;;
"Return to previous menu") break ;;
esac
done
;;
9) # logging)
choice="" # zero the choice before loading the submenu
while true; do
echo "Checking current logging status..."
choice=$(dialog --no-collapse --colors --title "Logging" --cancel-label "Back" --default-item "$choice" --item-help --menu "Before deploying a Femtofox, it is advisable to disable logging to reduce SD card wear.\nCurrent state: $(replace_colors "$(femto-utils.sh -l "check")")" 14 50 2 \
1 "Enable (default)" "" \
2 "Disable" "" \
@ -303,9 +327,10 @@ $(ingest_data "femto-meshtasticd-config.sh -i" 15)" 0 0
esac
done
;;
9) # logging)
10) # activity LED)
choice="" # zero the choice before loading the submenu
while true; do
echo "Checking current activity LED status..."
choice=$(dialog --no-collapse --colors --title "Logging" --cancel-label "Back" --default-item "$choice" --item-help --menu "Before deploying a Femtofox, it is advisable to disable the Activity LED to save power.\nCurrent state: $(replace_colors "$(femto-utils.sh -a "check")")" 14 50 2 \
1 "Enable (default)" "" \
2 "Disable" "" \
@ -319,21 +344,21 @@ $(ingest_data "femto-meshtasticd-config.sh -i" 15)" 0 0
esac
done
;;
10) # reboot)
11) # reboot)
dialog --no-collapse --title "$title" --yesno "Reboot now?\n\nTip: Reboot can also be triggered by long-pressing the BOOT button on the luckfox." 10 45
if [ $? -eq 0 ]; then #unless cancel/no
loading "Rebooting..."
femto-utils.sh -r
fi
;;
11) # shutdown)
12) # shutdown)
dialog --no-collapse --colors --title "$title" --yesno "Shut down now?\n\nTo power system back on, disconnect/reconnect power.\n\nThe system shutdown command prevents damage to the filesystem from power interrupts, but does not stop power consumption.\n\nTip: You can also shut down the Femtofox by pressing the BOOT button for 5 seconds or by running \`\Zusudo halt\Zn\`." 14 60
if [ $? -eq 0 ]; then #unless cancel/no
loading "Shutting down...\n\nPower consumption will not stop."
femto-utils.sh -s
fi
;;
12) return ;;
13) return ;;
esac
done
}
@ -538,7 +563,7 @@ meshtastic_settings() {
dialog --no-collapse --title "Meshtastic Connectivity Test" --yesno "Will send \"test\" to channel 0 and wait for acknowledgement. Will try up to 3 times.\n\nPerform test?" 10 45
if [ $? -eq 0 ]; then #unless cancel/no
dialog --no-collapse --infobox "Performing mesh connectivity test.\n\nThis may take a while..." 6 45
dialog --no-collapse --colors --title "Meshtasticd service status" --msgbox "$(replace_colors "$(femto-meshtasticd-config.sh -w)")" 0 0
dialog --no-collapse --colors --title "Meshtasticd connectivity test" --msgbox "$(replace_colors "$(femto-meshtasticd-config.sh -w)")" 0 0
fi
;;
7) #manage meshtasticd service)

View file

@ -18,6 +18,8 @@ Options are:
-n Networking info
-o OS info
-S Storage & RAM info
-t "enable" Enable/disable/start/stop/check ttyd (http based terminal). Options: "enable" "disable" "start" "stop" "check"
EOF
)
@ -89,20 +91,22 @@ Mnted drives:$mounted_drives"
os_info() {
local os_version="Foxbuntu v$(grep -oP 'major=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'minor=\K[0-9]+' /etc/foxbuntu-release)$(output=$(grep -o 'patch=[1-9][0-9]*' /etc/foxbuntu-release | cut -d= -f2) && [ -n "$output" ] && echo ".$output")$(grep -oP 'hotfix=\K[a-z]+' /etc/foxbuntu-release) ($(lsb_release -d | awk -F'\t' '{print $2}') $(lsb_release -c | awk -F'\t' '{print $2}'))"
local system_uptime="$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')"
local logging_enabled="$(logging "check" | sed 's/\x1b\[[0-9;]*m//g')"
local act_led="$(femto-utils.sh -a "check" | sed -r 's/\x1B\[[0-9;]*[mK]//g')" #remove color from output
local kernel_active_modules="$(lsmod | awk 'NR>1 {print $1}' | tr '\n' ' ' && echo)"
local kernel_boot_modules="$(modules=$(sed -n '6,$p' /etc/modules | sed ':a;N;$!ba;s/\n/, /g;s/, $//'); [ -z "$modules" ] && echo "none" || echo "$modules")"
local ttyd_enabled="$(ttyd "check" | sed 's/\x1b\[[0-9;]*m//g')"
local logging_enabled="$(logging "check" | sed 's/\x1b\[[0-9;]*m//g')"
local act_led="$(femto-utils.sh -a "check" | sed -r 's/\x1B\[[0-9;]*[mK]//g')" #remove color from output
echo -e "\
OS:$os_version\n\
Kernel ver:$(uname -r)\n\
Uptime:$system_uptime\n\
Logging:$logging_enabled\n\
Activity LED:$act_led\n\
System time:$(date)\n\
K mods active:$kernel_active_modules\n\
K boot mods:$kernel_boot_modules"
K boot mods:$kernel_boot_modules\n\
Web terminal:$ttyd_enabled\n\
Logging:$logging_enabled\n\
Activity LED:$act_led"
}
networking_info() {
@ -195,7 +199,41 @@ logging() {
fi
}
while getopts ":harsl:ipcnoS" opt; do
ttyd() {
if [ "$1" = "disable" ]; then
systemctl disable ttyd
systemctl stop ttyd
echo "Disabled ttyd service."
exit 0
elif [ "$1" = "enable" ]; then
systemctl enable ttyd
echo "Enabled ttyd service."
systemctl start ttyd
exit 0
elif [ "$1" = "check" ]; then
if systemctl is-enabled ttyd &>/dev/null; then
if echo "$(systemctl status ttyd)" | grep -q "active (running)"; then
echo -e "\033[4m\033[0;34menabled and running\033[0m"
elif echo "$(systemctl status ttyd)" | grep -q "inactive (dead)"; then
echo -e "\033[4m\033[0;31menabled but not running\033[0m"
exit 1
else
echo "unknown"
fi
else
echo -e "\033[4m\033[0;31mdisabled\033[0m"
exit 1
fi
elif [ "$1" = "start" ]; then
echo "Starting/restarting ttyd service..."
systemctl restart ttyd
elif [ "$1" = "stop" ]; then
echo "Stopping ttyd service..."
systemctl stop ttyd
fi
}
while getopts ":harsl:ipcnoSt:" opt; do
case ${opt} in
h) # Option -h (help)
echo -e $help
@ -213,15 +251,14 @@ while getopts ":harsl:ipcnoS" opt; do
logger "User requested system halt"
halt
;;
l) # Option -l (Logging enable/disable/check)
logging $OPTARG
;;
l) logging $OPTARG ;; # Option -l (Logging enable/disable/check)
i) all_system_info ;; # Option -i (sysinfo)
p) peripherals_info ;; # Option -p (Peripherals info)
c) cpu_info ;; # Option -c (CPU info)
n) networking_info ;; # Option -n (Networing info)
o) os_info ;; # Option -o (OS info)
S) storage_info ;; # Option -S (Storage & RAM info)
t) ttyd $OPTARG ;; # Option -t (ttyd)
\?) # Unknown option)
echo -e "Unknown argument $1.\n$help"
;;