Add UI demo

This commit is contained in:
Ed Nielsen 2026-03-18 20:09:29 +01:00
parent 279c6ade30
commit 0c6d4263d4
2 changed files with 75 additions and 136 deletions

View file

@ -54,16 +54,16 @@ git clone https://github.com/YOUR-USER/update-manager.git
cd update-manager cd update-manager
sudo apt update sudo apt update
sudo apt install dialog openssh-client sudo apt install -y dialog openssh-client
sudo mkdir -p /opt/update-manager sudo mkdir -p /opt/update-manager
sudo cp update-manager.sh update-manager-ui.sh /opt/update-manager/ sudo cp update-manager.sh update-manager-ui.sh dialogrc /opt/update-manager/
sudo chmod +x /opt/update-manager/update-manager.sh sudo chmod +x /opt/update-manager/update-manager.sh
sudo chmod +x /opt/update-manager/update-manager-ui.sh sudo chmod +x /opt/update-manager/update-manager-ui.sh
sudo ln -s /opt/update-manager/update-manager.sh /usr/local/bin/update-manager sudo ln -sf /opt/update-manager/update-manager.sh /usr/local/bin/update-manager
sudo ln -s /opt/update-manager/update-manager-ui.sh /usr/local/bin/update-manager-ui sudo ln -sf /opt/update-manager/update-manager-ui.sh /usr/local/bin/update-manager-ui
``` ```
--- ---

View file

@ -1,5 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
export DIALOGRC="/opt/update-manager/dialogrc"
UPDATE_MANAGER_SCRIPT="$HOME/update-manager/update-manager.sh" UPDATE_MANAGER_SCRIPT="$HOME/update-manager/update-manager.sh"
HOSTS_FILE="/opt/update-manager/hosts.conf" HOSTS_FILE="/opt/update-manager/hosts.conf"
@ -14,139 +16,76 @@ get_log_file() {
fi fi
} }
run_check() { while true; do
echo choice=$(dialog --clear \
bash "$UPDATE_MANAGER_SCRIPT" check --backtitle "Update Manager" \
echo --title "Choose an action" \
read -rp "Press Enter to continue..." --menu "Select option:" 16 60 9 \
} 1 "Check all hosts" \
2 "View hosts file" \
3 "Edit hosts file" \
4 "Add host" \
5 "Remove host" \
6 "View full log" \
7 "Follow log live" \
8 "Show log location" \
0 "Exit" \
3>&1 1>&2 2>&3)
view_hosts() { clear
echo
case "$choice" in
1)
bash "$UPDATE_MANAGER_SCRIPT" check
read -rp "Press Enter to continue..."
;;
2)
if [[ -f "$HOSTS_FILE" ]]; then if [[ -f "$HOSTS_FILE" ]]; then
cat "$HOSTS_FILE" less "$HOSTS_FILE"
else else
echo "Hosts file not found: $HOSTS_FILE" echo "Hosts file not found: $HOSTS_FILE"
fi
echo
read -rp "Press Enter to continue..." read -rp "Press Enter to continue..."
} fi
;;
edit_hosts() { 3)
nano "$HOSTS_FILE" nano "$HOSTS_FILE"
} ;;
4)
add_host() {
echo
read -rp "Name: " name read -rp "Name: " name
read -rp "IP: " ip read -rp "IP: " ip
read -rp "User: " user read -rp "User: " user
echo "$name $ip $user" >> "$HOSTS_FILE" echo "$name $ip $user" >> "$HOSTS_FILE"
echo "Host added." echo "Host added."
echo
read -rp "Press Enter to continue..." read -rp "Press Enter to continue..."
} ;;
5)
remove_host() { if [[ -f "$HOSTS_FILE" ]]; then
echo
nl -w2 -s'. ' "$HOSTS_FILE" nl -w2 -s'. ' "$HOSTS_FILE"
echo read -rp "Line to remove: " line
read -rp "Enter line number to remove: " line
sed -i "${line}d" "$HOSTS_FILE" sed -i "${line}d" "$HOSTS_FILE"
echo "Host removed." echo "Host removed."
echo
read -rp "Press Enter to continue..."
}
view_log() {
local log_file
log_file="$(get_log_file)"
echo
if [[ -f "$log_file" ]]; then
less "$log_file"
else else
echo "Log file not found: $log_file" echo "Hosts file not found: $HOSTS_FILE"
read -rp "Press Enter to continue..."
fi fi
} read -rp "Press Enter to continue..."
;;
follow_log() { 6)
local log_file less "$(get_log_file)"
log_file="$(get_log_file)" ;;
7)
echo echo "Following log: $(get_log_file)"
if [[ -f "$log_file" ]]; then
echo "Following log: $log_file"
echo "Press Ctrl+C to stop." echo "Press Ctrl+C to stop."
echo tail -f "$(get_log_file)"
tail -f "$log_file"
else
echo "Log file not found: $log_file"
fi
echo
read -rp "Press Enter to continue..." read -rp "Press Enter to continue..."
} ;;
8)
show_log_location() { echo "Log file:"
local log_file echo "$(get_log_file)"
log_file="$(get_log_file)"
echo
echo "Log file location:"
echo "$log_file"
echo
read -rp "Press Enter to continue..." read -rp "Press Enter to continue..."
} ;;
0|"")
show_menu() {
clear clear
echo "=================================="
echo " Update Manager UI"
echo "=================================="
echo
echo "1) Check all hosts"
echo "2) View hosts file"
echo "3) Edit hosts file"
echo "4) Add host"
echo "5) Remove host"
echo "6) View full log"
echo "7) Follow log live"
echo "8) Show log location"
echo "0) Exit"
echo
}
main() {
while true; do
show_menu
read -rp "Choose an option: " choice
case "$choice" in
1) run_check ;;
2) view_hosts ;;
3) edit_hosts ;;
4) add_host ;;
5) remove_host ;;
6) view_log ;;
7) follow_log ;;
8) show_log_location ;;
0)
echo
echo "Bye."
exit 0 exit 0
;; ;;
*)
echo "Invalid choice"
read -rp "Press Enter to continue..."
;;
esac esac
done done
}
main