91 lines
2.4 KiB
Bash
Executable file
91 lines
2.4 KiB
Bash
Executable file
#!/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"
|
|
|
|
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:" 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)
|
|
|
|
clear
|
|
|
|
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..."
|
|
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
|