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
sudo apt update
sudo apt install dialog openssh-client
sudo apt install -y dialog openssh-client
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-ui.sh
sudo ln -s /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.sh /usr/local/bin/update-manager
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
export DIALOGRC="/opt/update-manager/dialogrc"
UPDATE_MANAGER_SCRIPT="$HOME/update-manager/update-manager.sh"
HOSTS_FILE="/opt/update-manager/hosts.conf"
@ -14,139 +16,76 @@ get_log_file() {
fi
}
run_check() {
echo
bash "$UPDATE_MANAGER_SCRIPT" check
echo
read -rp "Press Enter to continue..."
}
while true; do
choice=$(dialog --clear \
--backtitle "Update Manager" \
--title "Choose an action" \
--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() {
echo
clear
case "$choice" in
1)
bash "$UPDATE_MANAGER_SCRIPT" check
read -rp "Press Enter to continue..."
;;
2)
if [[ -f "$HOSTS_FILE" ]]; then
cat "$HOSTS_FILE"
less "$HOSTS_FILE"
else
echo "Hosts file not found: $HOSTS_FILE"
fi
echo
read -rp "Press Enter to continue..."
}
edit_hosts() {
fi
;;
3)
nano "$HOSTS_FILE"
}
add_host() {
echo
;;
4)
read -rp "Name: " name
read -rp "IP: " ip
read -rp "User: " user
echo "$name $ip $user" >> "$HOSTS_FILE"
echo "Host added."
echo
read -rp "Press Enter to continue..."
}
remove_host() {
echo
;;
5)
if [[ -f "$HOSTS_FILE" ]]; then
nl -w2 -s'. ' "$HOSTS_FILE"
echo
read -rp "Enter line number to remove: " line
read -rp "Line to remove: " line
sed -i "${line}d" "$HOSTS_FILE"
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
echo "Log file not found: $log_file"
read -rp "Press Enter to continue..."
echo "Hosts file not found: $HOSTS_FILE"
fi
}
follow_log() {
local log_file
log_file="$(get_log_file)"
echo
if [[ -f "$log_file" ]]; then
echo "Following log: $log_file"
read -rp "Press Enter to continue..."
;;
6)
less "$(get_log_file)"
;;
7)
echo "Following log: $(get_log_file)"
echo "Press Ctrl+C to stop."
echo
tail -f "$log_file"
else
echo "Log file not found: $log_file"
fi
echo
tail -f "$(get_log_file)"
read -rp "Press Enter to continue..."
}
show_log_location() {
local log_file
log_file="$(get_log_file)"
echo
echo "Log file location:"
echo "$log_file"
echo
;;
8)
echo "Log file:"
echo "$(get_log_file)"
read -rp "Press Enter to continue..."
}
show_menu() {
;;
0|"")
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
;;
*)
echo "Invalid choice"
read -rp "Press Enter to continue..."
;;
esac
done
}
main
done