#!/usr/bin/env bash ######################################## # Load config ######################################## CONFIG_FILE="/etc/update-manager.conf" [[ -f "$CONFIG_FILE" ]] || CONFIG_FILE="./update-manager.conf" if [[ -f "$CONFIG_FILE" ]]; then # shellcheck disable=SC1090 source "$CONFIG_FILE" fi HOSTS_FILE="${HOSTS_FILE:-./hosts.conf}" SSH_OPTIONS="${SSH_OPTIONS:--o BatchMode=yes -o ConnectTimeout=5}" ######################################## # Check hosts ######################################## check_host() { local name="$1" local ip="$2" local user="$3" local result count result=$(ssh $SSH_OPTIONS "$user@$ip" \ "apt list --upgradable 2>/dev/null | grep -v '^Listing'" 2>/dev/null) if [[ $? -ne 0 ]]; then printf "%-15s ❌ connection failed\n" "$name" return fi if [[ -z "$result" ]]; then printf "%-15s 🟢 up-to-date\n" "$name" else count=$(echo "$result" | wc -l) printf "%-15s 🔴 %d updates\n" "$name" "$count" fi } check_all() { while read -r name ip user; do [[ -z "$name" ]] && continue [[ "$name" =~ ^# ]] && continue check_host "$name" "$ip" "$user" done < "$HOSTS_FILE" } ######################################## # Install ######################################## install_update_manager() { echo "Installing update-manager..." local INSTALL_DIR="/opt/update-manager" # Opret mappe sudo mkdir -p "$INSTALL_DIR" # Kopiér filer sudo cp update-manager.sh "$INSTALL_DIR/" sudo cp hosts.conf "$INSTALL_DIR/" 2>/dev/null sudo cp update-manager.conf "$INSTALL_DIR/" 2>/dev/null # Gør eksekverbar sudo chmod +x "$INSTALL_DIR/update-manager.sh" # Global config (kun hvis ikke findes) if [[ -f update-manager.conf && ! -f /etc/update-manager.conf ]]; then sudo cp update-manager.conf /etc/update-manager.conf fi # Symlink → global kommando sudo ln -sf "$INSTALL_DIR/update-manager.sh" /usr/local/bin/update-manager echo "Done!" echo "Run: update-manager check" } ######################################## # Main ######################################## case "$1" in check) check_all ;; install) install_update_manager ;; *) echo "Usage: $0 {check|install}" ;; esac