hassio-addons/upsmon/run.sh
2018-11-08 22:05:44 +01:00

32 lines
695 B
Bash

#!/bin/bash
set -e
CONFIG_PATH=/data/options.json
UPSNAME=$(jq --raw-output ".ups.upsname" $CONFIG_PATH)
HOST=$(jq --raw-output ".ups.host" $CONFIG_PATH)
USER=$(jq --raw-output ".credentials.user" $CONFIG_PATH)
PASS=$(jq --raw-output ".credentials.pass" $CONFIG_PATH)
DELAY=$(jq --raw-output ".delay" $CONFIG_PATH)
echo "
MONITOR ${UPSNAME}@${HOST} 1 ${USER} ${PASS} slave
MINSUPPLIES 1
SHUTDOWNCMD \"/sbin/shutdown -h +0\"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY ${DELAY}
" > /etc/nut/upsmon.conf
echo "MODE=netclient" > /etc/nut/nut.conf
# change perms on config files
chmod 660 /etc/nut/*
upsmon -D