Add logging, dialog UI, README updates and initial release
This commit is contained in:
parent
15d3f0b2d6
commit
ab945b1caf
4 changed files with 339 additions and 118 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
# 🖥️ Update Manager
|
# 🖥️ Update Manager - Version: 1.0.0
|
||||||
|
|
||||||
Simple CLI tool to check and manage updates across multiple Ubuntu systems over SSH.
|
Simple CLI tool to check and manage updates across multiple Ubuntu systems over SSH.
|
||||||
|
|
||||||
|
|
|
||||||
117
log/update-manager.sh
Normal file
117
log/update-manager.sh
Normal file
|
|
@ -0,0 +1,117 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
UPDATE_MANAGER_SCRIPT="/opt/update-manager/update-manager.sh"
|
||||||
|
|
||||||
|
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_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"
|
||||||
|
echo
|
||||||
|
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) Run update check"
|
||||||
|
echo "2) View full log"
|
||||||
|
echo "3) Follow log live"
|
||||||
|
echo "4) Show log location"
|
||||||
|
echo "0) Exit"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
if [[ ! -f "$UPDATE_MANAGER_SCRIPT" ]]; then
|
||||||
|
echo "Update manager script not found: $UPDATE_MANAGER_SCRIPT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
show_menu
|
||||||
|
read -rp "Choose an option: " choice
|
||||||
|
|
||||||
|
case "$choice" in
|
||||||
|
1)
|
||||||
|
run_check
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
view_log
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
follow_log
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
show_log_location
|
||||||
|
;;
|
||||||
|
0)
|
||||||
|
echo
|
||||||
|
echo "Bye."
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo
|
||||||
|
echo "Invalid choice."
|
||||||
|
read -rp "Press Enter to continue..."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
||||||
152
update-manager-ui.sh
Executable file
152
update-manager-ui.sh
Executable file
|
|
@ -0,0 +1,152 @@
|
||||||
|
#!/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
|
||||||
|
|
@ -1,127 +1,79 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CONFIG_FILE="/etc/update-manager.conf"
|
UPDATE_MANAGER_SCRIPT="$HOME/update-manager/update-manager.sh"
|
||||||
[[ -f "$CONFIG_FILE" ]] || CONFIG_FILE="./update-manager.conf"
|
HOSTS_FILE="/opt/update-manager/hosts.conf"
|
||||||
|
|
||||||
if [[ -f "$CONFIG_FILE" ]]; then
|
get_log_file() {
|
||||||
# shellcheck disable=SC1090
|
local primary="/opt/update-manager/log/update-manager.log"
|
||||||
source "$CONFIG_FILE"
|
local fallback="$HOME/update-manager/log/update-manager.log"
|
||||||
fi
|
|
||||||
|
|
||||||
DEFAULT_HOSTS_FILE="${HOSTS_FILE:-/opt/update-manager/hosts.conf}"
|
if [[ -f "$primary" ]]; then
|
||||||
SSH_OPTIONS="${SSH_OPTIONS:--o BatchMode=yes -o ConnectTimeout=5}"
|
echo "$primary"
|
||||||
|
|
||||||
########################################
|
|
||||||
# Ensure hosts file exists
|
|
||||||
########################################
|
|
||||||
|
|
||||||
ensure_hosts_file() {
|
|
||||||
if [[ ! -f "$DEFAULT_HOSTS_FILE" ]]; then
|
|
||||||
echo "Creating example hosts file: $DEFAULT_HOSTS_FILE"
|
|
||||||
|
|
||||||
mkdir -p "$(dirname "$DEFAULT_HOSTS_FILE")"
|
|
||||||
|
|
||||||
cat > "$DEFAULT_HOSTS_FILE" <<'EOF'
|
|
||||||
# Example hosts file
|
|
||||||
# Format:
|
|
||||||
# name ip user
|
|
||||||
#
|
|
||||||
# server1 192.168.1.10 user
|
|
||||||
# server2 192.168.1.20 user
|
|
||||||
# server3 10.0.0.5 root
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
########################################
|
|
||||||
# Helpers
|
|
||||||
########################################
|
|
||||||
|
|
||||||
get_hosts_file() {
|
|
||||||
if [[ -n "$2" ]]; then
|
|
||||||
echo "$2"
|
|
||||||
else
|
else
|
||||||
echo "$DEFAULT_HOSTS_FILE"
|
echo "$fallback"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
while true; do
|
||||||
cat <<USAGE
|
choice=$(dialog --clear \
|
||||||
Usage:
|
--backtitle "Update Manager" \
|
||||||
$0 check [hosts_file]
|
--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)
|
||||||
|
|
||||||
Examples:
|
clear
|
||||||
$0 check
|
|
||||||
$0 check /path/to/hosts.conf
|
|
||||||
HOSTS_FILE=/path/to/hosts.conf $0 check
|
|
||||||
USAGE
|
|
||||||
}
|
|
||||||
|
|
||||||
########################################
|
case $choice in
|
||||||
# Check single host
|
1)
|
||||||
########################################
|
bash "$UPDATE_MANAGER_SCRIPT" check
|
||||||
|
read -rp "Press Enter to continue..."
|
||||||
check_host() {
|
;;
|
||||||
local name="$1"
|
2)
|
||||||
local ip="$2"
|
less "$HOSTS_FILE"
|
||||||
local user="$3"
|
;;
|
||||||
local result
|
3)
|
||||||
local rc
|
nano "$HOSTS_FILE"
|
||||||
|
;;
|
||||||
result=$(ssh -n $SSH_OPTIONS "${user}@${ip}" \
|
4)
|
||||||
"apt list --upgradable 2>/dev/null | sed '/^Listing/d'" 2>&1)
|
read -rp "Name: " name
|
||||||
rc=$?
|
read -rp "IP: " ip
|
||||||
|
read -rp "User: " user
|
||||||
printf "===== %s (%s) =====\n" "$name" "$ip"
|
echo "$name $ip $user" >> "$HOSTS_FILE"
|
||||||
|
echo "Host added."
|
||||||
if [[ $rc -ne 0 ]]; then
|
read -rp "Press Enter to continue..."
|
||||||
echo "❌ connection failed"
|
;;
|
||||||
echo "$result"
|
5)
|
||||||
echo
|
nl -w2 -s'. ' "$HOSTS_FILE"
|
||||||
return
|
read -rp "Line to remove: " line
|
||||||
fi
|
sed -i "${line}d" "$HOSTS_FILE"
|
||||||
|
echo "Host removed."
|
||||||
if [[ -z "$result" ]]; then
|
read -rp "Press Enter to continue..."
|
||||||
echo "Up-to-date"
|
;;
|
||||||
else
|
6)
|
||||||
echo "$result"
|
less "$(get_log_file)"
|
||||||
fi
|
;;
|
||||||
|
7)
|
||||||
echo
|
echo "Press Ctrl+C to stop"
|
||||||
}
|
tail -f "$(get_log_file)"
|
||||||
|
read -rp "Press Enter to continue..."
|
||||||
########################################
|
;;
|
||||||
# Check all hosts
|
8)
|
||||||
########################################
|
echo "Log file:"
|
||||||
|
echo "$(get_log_file)"
|
||||||
check_all() {
|
read -rp "Press Enter to continue..."
|
||||||
local hosts_file="$1"
|
;;
|
||||||
|
0)
|
||||||
ensure_hosts_file
|
clear
|
||||||
|
exit 0
|
||||||
while IFS= read -r line; do
|
;;
|
||||||
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
|
esac
|
||||||
|
done
|
||||||
local name ip user
|
|
||||||
read -r name ip user <<< "$line"
|
|
||||||
|
|
||||||
[[ -z "$name" || -z "$ip" || -z "$user" ]] && continue
|
|
||||||
|
|
||||||
check_host "$name" "$ip" "$user"
|
|
||||||
done < "$hosts_file"
|
|
||||||
}
|
|
||||||
|
|
||||||
########################################
|
|
||||||
# Main
|
|
||||||
########################################
|
|
||||||
|
|
||||||
case "${1:-}" in
|
|
||||||
check)
|
|
||||||
HOSTS_FILE_TO_USE="$(get_hosts_file "$@")"
|
|
||||||
check_all "$HOSTS_FILE_TO_USE"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue