152 lines
2.9 KiB
Bash
Executable file
152 lines
2.9 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
|
|
}
|
|
|
|
run_check() {
|
|
echo
|
|
bash "$UPDATE_MANAGER_SCRIPT" check
|
|
echo
|
|
read -rp "Press Enter to continue..."
|
|
}
|
|
|
|
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"
|
|
read -rp "Press Enter to continue..."
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
main
|