update-manager/update-manager.sh

79 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
UPDATE_MANAGER_SCRIPT="$HOME/update-manager/update-manager.sh"
HOSTS_FILE="/opt/update-manager/hosts.conf"
get_log_file() {
local primary="/opt/update-manager/log/update-manager.log"
local fallback="$HOME/update-manager/log/update-manager.log"
if [[ -f "$primary" ]]; then
echo "$primary"
else
echo "$fallback"
fi
}
while true; do
choice=$(dialog --clear \
--backtitle "Update Manager" \
--title "Choose an action" \
--menu "Select option:" 15 50 10 \
1 "Check all hosts" \
2 "View hosts file" \
3 "Edit hosts file" \
4 "Add host" \
5 "Remove host" \
6 "View log" \
7 "Follow log live" \
8 "Show log location" \
0 "Exit" \
3>&1 1>&2 2>&3)
clear
case $choice in
1)
bash "$UPDATE_MANAGER_SCRIPT" check
read -rp "Press Enter to continue..."
;;
2)
less "$HOSTS_FILE"
;;
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)
nl -w2 -s'. ' "$HOSTS_FILE"
read -rp "Line to remove: " line
sed -i "${line}d" "$HOSTS_FILE"
echo "Host removed."
read -rp "Press Enter to continue..."
;;
6)
less "$(get_log_file)"
;;
7)
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