From 0c6d4263d484261c18f65d792db30f34e1da2a05 Mon Sep 17 00:00:00 2001 From: Ed Nielsen Date: Wed, 18 Mar 2026 20:09:29 +0100 Subject: [PATCH] Add UI demo --- README.md | 8 +- update-manager-ui.sh | 203 +++++++++++++++---------------------------- 2 files changed, 75 insertions(+), 136 deletions(-) diff --git a/README.md b/README.md index f0286cf..373c626 100644 --- a/README.md +++ b/README.md @@ -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 ``` --- diff --git a/update-manager-ui.sh b/update-manager-ui.sh index 97bb29c..aa4f823 100755 --- a/update-manager-ui.sh +++ b/update-manager-ui.sh @@ -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 - if [[ -f "$HOSTS_FILE" ]]; then - cat "$HOSTS_FILE" - else - echo "Hosts file not found: $HOSTS_FILE" - fi - echo - read -rp "Press Enter to continue..." -} - -edit_hosts() { - nano "$HOSTS_FILE" -} - -add_host() { - echo - 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 - nl -w2 -s'. ' "$HOSTS_FILE" - echo - read -rp "Enter line number 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..." - fi -} - -follow_log() { - local log_file - log_file="$(get_log_file)" - - echo - if [[ -f "$log_file" ]]; then - echo "Following log: $log_file" - echo "Press Ctrl+C to stop." - echo - tail -f "$log_file" - else - echo "Log file not found: $log_file" - fi - - echo - 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 - read -rp "Press Enter to continue..." -} - -show_menu() { 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" + case "$choice" in + 1) + bash "$UPDATE_MANAGER_SCRIPT" check + read -rp "Press Enter to continue..." + ;; + 2) + if [[ -f "$HOSTS_FILE" ]]; then + less "$HOSTS_FILE" + else + echo "Hosts file not found: $HOSTS_FILE" read -rp "Press Enter to continue..." - ;; - esac - done -} - -main + fi + ;; + 3) + nano "$HOSTS_FILE" + ;; + 4) + read -rp "Name: " name + read -rp "IP: " ip + read -rp "User: " user + echo "$name $ip $user" >> "$HOSTS_FILE" + echo "Host added." + read -rp "Press Enter to continue..." + ;; + 5) + if [[ -f "$HOSTS_FILE" ]]; then + nl -w2 -s'. ' "$HOSTS_FILE" + read -rp "Line to remove: " line + sed -i "${line}d" "$HOSTS_FILE" + echo "Host removed." + else + echo "Hosts file not found: $HOSTS_FILE" + fi + read -rp "Press Enter to continue..." + ;; + 6) + less "$(get_log_file)" + ;; + 7) + echo "Following log: $(get_log_file)" + echo "Press Ctrl+C to stop." + tail -f "$(get_log_file)" + read -rp "Press Enter to continue..." + ;; + 8) + echo "Log file:" + echo "$(get_log_file)" + read -rp "Press Enter to continue..." + ;; + 0|"") + clear + exit 0 + ;; + esac +done