Skip to content

Instantly share code, notes, and snippets.

@reitermarkus
Last active August 22, 2023 08:49
Show Gist options
  • Save reitermarkus/2ba6a653beeaf9408d39f731376e2ce1 to your computer and use it in GitHub Desktop.
Save reitermarkus/2ba6a653beeaf9408d39f731376e2ce1 to your computer and use it in GitHub Desktop.
brew install nut
brew tap reitermarkus/tap
brew install nut-notify
cat <<EOF > /usr/local/etc/nut/nut.conf
MODE=netclient
EOF
cat <<EOF > /usr/local/etc/nut/upsmon.conf
MONITOR [email protected] 1 upsmon_remote KMdyQNBbEVkNBz23 slave
SHUTDOWNCMD "/usr/libexec/upsshutdown WaitForUPS"
NOTIFYCMD /usr/local/etc/nut/notify.sh
EOF
sudo brew services restart nut
apt update
apt-get install -y nut
cat <<EOF | tee /etc/nut/nut.conf
MODE=netserver
EOF
cat <<EOF | tee /etc/nut/ups.conf
[ups]
driver = blazer_usb
port = auto
desc = "V7 3000VA"
runtimecal = 222,100,708,50
EOF
cat <<EOF | tee /etc/nut/upsd.conf
LISTEN 127.0.0.1 3493
LISTEN 0.0.0.0 3493
LISTEN ::1 3493
LISTEN ::0 3493
EOF
cat <<EOF | tee /etc/nut/upsd.users
[admin]
password = KMdyQNBbEVkNBz23
actions = SET FSD
instcmds = ALL
[upsmon_local]
password = KMdyQNBbEVkNBz23
upsmon master
[upsmon_remote]
password = KMdyQNBbEVkNBz23
upsmon slave
EOF
cat <<EOF | tee /etc/nut/upsmon.conf
MONITOR ups@localhost 1 upsmon_local KMdyQNBbEVkNBz23 master
POWERDOWNFLAG /etc/killpower
EOF
systemctl enable --now nut-server
systemctl enable --now nut-monitor
sudo apt-get install -y nut
cat <<EOF | sudo tee /etc/nut/nut.conf
MODE=netserver
EOF
cat <<EOF | sudo tee /etc/nut/ups.conf
[ups]
driver = blazer_usb
port = auto
desc = "PowerWalker VI 3000 CW"
runtimecal = 138,100,540,50
chargetime = 16000
EOF
cat <<EOF | sudo tee /etc/nut/upsd.conf
LISTEN 127.0.0.1 3493
LISTEN 0.0.0.0 3493
LISTEN ::1 3493
LISTEN ::0 3493
EOF
cat <<EOF | sudo tee /etc/nut/upsd.users
[admin]
password = KMdyQNBbEVkNBz23
actions = SET FSD
instcmds = ALL
[upsmon_local]
password = KMdyQNBbEVkNBz23
upsmon master
[upsmon_remote]
password = KMdyQNBbEVkNBz23
upsmon slave
EOF
cat <<EOF | sudo tee /etc/nut/upsmon.conf
MONITOR ups@localhost 1 upsmon_local KMdyQNBbEVkNBz23 master
SHUTDOWNCMD "/sbin/shutdown -h +0"
POWERDOWNFLAG /etc/killpower
EOF
sudo systemctl enable --now nut-driver-enumerator
sudo systemctl enable --now nut-server
sudo systemctl enable --now nut-monitor
# Build a custom version of NUT with support for the Legrand KEOR PDU:
# - https://github.com/networkupstools/nut/issues/616#issuecomment-902109561
# - https://github.com/networkupstools/nut/wiki/Building-NUT-on-Debian,-Raspbian-and-Ubuntu
sudo sed -i -E 's/^#\s*(deb-src)/\1/' /etc/apt/sources.list
sudo apt update
sudo apt-get install -y nut
sudo apt-get build-dep -y nut
sudo apt-get install -y git
mkdir -p legrand
pushd legrand
curl -O -L https://github.com/networkupstools/nut/releases/download/v2.8.0/nut-2.8.0.tar.gz
tar -xf nut-2.8.0.tar.gz --strip-components=1
./configure \
--prefix=/usr \
--includedir=/usr/include \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--sysconfdir=/etc/nut \
--localstatedir=/var \
--libexecdir=/usr/lib/nut \
--srcdir=. \
--enable-maintainer-mode \
--disable-silent-rules \
--libdir="/usr/lib/$(gcc -print-multiarch)" \
--with-ssl \
--with-nss \
--with-cgi \
--with-dev \
--enable-static \
--with-statepath=/var/run/nut \
--with-altpidpath=/var/run/nut \
--with-drvpath=/lib/nut \
--with-cgipath=/usr/lib/cgi-bin/nut \
--with-htmlpath=/usr/share/nut/www \
--with-pidpath=/var/run/nut \
--datadir=/usr/share/nut \
--with-pkgconfig-dir="/usr/lib/$(gcc -print-multiarch)/pkgconfig" \
--with-user=nut \
--with-group=nut \
--with-udev-dir=/lib/udev \
--with-systemdsystemunitdir=/lib/systemd/system \
--with-usb \
--disable-dependency-tracking
make
sudo make install
popd
rm -rf legrand
cat <<EOF | sudo tee /etc/nut/nut.conf
MODE=netserver
EOF
cat <<EOF | sudo tee /etc/nut/ups.conf
[ups]
driver = usbhid-ups
pollonly
port = auto
desc = "Legrand KEOR PDU 800"
EOF
cat <<EOF | sudo tee /etc/nut/upsd.conf
LISTEN 127.0.0.1 3493
LISTEN 0.0.0.0 3493
LISTEN ::1 3493
LISTEN ::0 3493
EOF
cat <<EOF | sudo tee /etc/nut/upsd.users
[admin]
password = KMdyQNBbEVkNBz23
actions = SET FSD
instcmds = ALL
[upsmon_local]
password = KMdyQNBbEVkNBz23
upsmon master
[upsmon_remote]
password = KMdyQNBbEVkNBz23
upsmon slave
EOF
cat <<EOF | sudo tee /etc/nut/upsmon.conf
MONITOR ups@localhost 1 upsmon_local KMdyQNBbEVkNBz23 master
SHUTDOWNCMD "/sbin/shutdown -r +0"
POWERDOWNFLAG /etc/killpower
EOF
sudo systemctl enable --now nut-driver-enumerator
sudo systemctl enable --now nut-server
sudo systemctl enable --now nut-monitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment