Initial commit: update manager with examples and README

This commit is contained in:
Ed Nielsen 2026-03-18 13:09:14 +01:00
commit 7e5662ced4
5 changed files with 142 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
hosts.conf
update-manager.conf
*.log

31
README.md Normal file
View file

@ -0,0 +1,31 @@
# Update Manager
Lightweight SSH-based update manager for Linux systems.
## Features
- Check for updates across multiple hosts
- Run upgrades remotely via SSH
- Run autoremove
- Simple inventory file
- No external dependencies
## Usage
./lanx-update.sh check
./lanx-update.sh update
./lanx-update.sh autoremove
./lanx-update.sh full
## Hosts file format
name|ip|ssh_user
Example:
server1|192.168.1.10|user
## Config
HOSTS_FILE="/opt/lanx/hosts.conf"
NTFY_URL=""

3
hosts.conf.example Normal file
View file

@ -0,0 +1,3 @@
# name|ip|ssh_user
server1|192.168.1.10|user
server2|192.168.1.20|user

103
lanx-update.sh Executable file
View file

@ -0,0 +1,103 @@
#!/usr/bin/env bash
HOSTS_FILE="/opt/lanx/hosts.conf"
check_host() {
local name="$1"
local ip="$2"
local user="$3"
local result
echo "===== $name ($ip) ====="
result=$(ssh -n -o BatchMode=yes -o ConnectTimeout=5 "${user}@${ip}" \
"apt-get -s upgrade 2>/dev/null | grep '^Inst'")
if [[ -z "$result" ]]; then
echo "[OK] Up-to-date"
else
echo "[UPDATES]"
echo "$result"
fi
echo
}
update_host() {
local name="$1"
local ip="$2"
local user="$3"
echo "===== $name ($ip) ====="
ssh -n -o BatchMode=yes -o ConnectTimeout=5 "${user}@${ip}" \
"sudo -n apt-get update && sudo -n apt-get upgrade -y" || {
echo "[FEJL] kunne ikke opdatere"
}
echo
}
autoremove_host() {
local name="$1"
local ip="$2"
local user="$3"
echo "===== $name ($ip) ====="
ssh -n -o BatchMode=yes -o ConnectTimeout=5 "${user}@${ip}" \
"sudo -n apt-get autoremove -y" || {
echo "[FEJL] kunne ikke køre autoremove"
}
echo
}
full_host() {
local name="$1"
local ip="$2"
local user="$3"
echo "===== $name ($ip) ====="
ssh -n -o BatchMode=yes -o ConnectTimeout=5 "${user}@${ip}" \
"sudo -n apt-get update && sudo -n apt-get upgrade -y && sudo -n apt-get autoremove -y" || {
echo "[FEJL] kunne ikke køre full maintenance"
}
echo
}
run_action() {
local action="$1"
if [[ ! -f "$HOSTS_FILE" ]]; then
echo "FEJL: hosts-fil findes ikke: $HOSTS_FILE"
exit 1
fi
while IFS='|' read -r name ip user || [[ -n "$name" ]]; do
[[ -z "$name" || "$name" =~ ^# ]] && continue
case "$action" in
check)
check_host "$name" "$ip" "$user"
;;
update)
update_host "$name" "$ip" "$user"
;;
autoremove)
autoremove_host "$name" "$ip" "$user"
;;
full)
full_host "$name" "$ip" "$user"
;;
*)
echo "Brug: $0 {check|update|autoremove|full}"
exit 1
;;
esac
done < "$HOSTS_FILE"
}
run_action "$1"

View file

@ -0,0 +1,2 @@
HOSTS_FILE="/opt/lanx/hosts.conf"
NTFY_URL=""