Files

46 lines
1.2 KiB
Bash

#!/usr/bin/env bash
# install-client.sh -- deploy NUT network-slave config
# Usage: sudo ./install-client.sh <MASTER_IP>
# ASCII only.
set -euo pipefail
SRC="$(cd "$(dirname "$0")" && pwd)/client/etc/nut"
DST="/etc/nut"
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: run as root (sudo)." >&2
exit 1
fi
MASTER_IP="${1:-}"
if [ -z "$MASTER_IP" ]; then
echo "Usage: sudo $0 <MASTER_IP>" >&2
exit 1
fi
echo "== Installing NUT (if missing) =="
if command -v apt-get >/dev/null 2>&1; then
apt-get update && apt-get install -y nut
elif command -v dnf >/dev/null 2>&1; then
dnf install -y nut
else
echo "WARN: unknown package manager, install 'nut' manually." >&2
fi
echo "== Copying client config to ${DST} =="
install -d "$DST"
cp -v "$SRC/nut.conf" "$DST/nut.conf"
sed "s/MASTER_IP/${MASTER_IP}/" "$SRC/upsmon.conf" > "$DST/upsmon.conf"
chown root:nut "$DST/upsmon.conf" 2>/dev/null || true
chmod 640 "$DST/upsmon.conf"
echo
echo "NEXT STEPS (manual):"
echo " 1. Edit ${DST}/upsmon.conf -- replace CHANGE_ME_SLAVE with the master's monslave password."
echo " 2. Enable the monitor service:"
echo " systemctl enable --now nut-monitor"
echo " 3. Verify connectivity to the master:"
echo " upsc ups@${MASTER_IP}"