140 lines
3.8 KiB
Bash
Executable file
140 lines
3.8 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"
|
|
elif [[ -f "$fallback" ]]; then
|
|
echo "$fallback"
|
|
else
|
|
echo ""
|
|
fi
|
|
}
|
|
|
|
show_log_menu() {
|
|
while true; do
|
|
log_choice=$(dialog --clear \
|
|
--backtitle "Update Manager" \
|
|
--title "Log menu" \
|
|
--menu "Select log action:" 18 60 10 \
|
|
1 "View full log" \
|
|
2 "Follow log live" \
|
|
3 "Show log location" \
|
|
4 "Show last 20 log lines" \
|
|
0 "Back" \
|
|
3>&1 1>&2 2>&3)
|
|
|
|
clear
|
|
|
|
case "$log_choice" in
|
|
1)
|
|
log_file="$(get_log_file)"
|
|
if [[ -n "$log_file" ]]; then
|
|
less "$log_file"
|
|
else
|
|
echo "No log file found yet."
|
|
read -rp "Press Enter to continue..."
|
|
fi
|
|
;;
|
|
2)
|
|
log_file="$(get_log_file)"
|
|
if [[ -n "$log_file" ]]; then
|
|
echo "Press Ctrl+C to stop"
|
|
tail -n 20 -f "$log_file"
|
|
else
|
|
echo "No log file found yet."
|
|
fi
|
|
read -rp "Press Enter to continue..."
|
|
;;
|
|
3)
|
|
log_file="$(get_log_file)"
|
|
if [[ -n "$log_file" ]]; then
|
|
echo "Log file:"
|
|
echo "$log_file"
|
|
else
|
|
echo "No log file found yet."
|
|
fi
|
|
read -rp "Press Enter to continue..."
|
|
;;
|
|
4)
|
|
log_file="$(get_log_file)"
|
|
if [[ -n "$log_file" ]]; then
|
|
tail -n 20 "$log_file"
|
|
else
|
|
echo "No log file found yet."
|
|
fi
|
|
read -rp "Press Enter to continue..."
|
|
;;
|
|
0|"")
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
while true; do
|
|
choice=$(dialog --clear \
|
|
--backtitle "Update Manager" \
|
|
--title "Choose an action" \
|
|
--menu "Select option:" 20 60 10 \
|
|
1 "Check all hosts" \
|
|
2 "View hosts file" \
|
|
3 "Edit hosts file" \
|
|
4 "Add host" \
|
|
5 "Remove host" \
|
|
6 "Log menu" \
|
|
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
|
|
if [[ -z "$name" || -z "$ip" || -z "$user" ]]; then
|
|
echo "All fields are required."
|
|
else
|
|
echo "$name $ip $user" >> "$HOSTS_FILE"
|
|
echo "Host added."
|
|
fi
|
|
read -rp "Press Enter to continue..."
|
|
;;
|
|
5)
|
|
nl -w2 -s'. ' "$HOSTS_FILE"
|
|
read -rp "Line to remove: " line
|
|
if [[ "$line" =~ ^[0-9]+$ ]]; then
|
|
sed -i "${line}d" "$HOSTS_FILE"
|
|
echo "Host removed."
|
|
else
|
|
echo "Invalid line number."
|
|
fi
|
|
read -rp "Press Enter to continue..."
|
|
;;
|
|
6)
|
|
show_log_menu
|
|
;;
|
|
0|"")
|
|
clear
|
|
exit 0
|
|
;;
|
|
esac
|
|
done
|