-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-nut-netclient
61 lines (45 loc) · 2.55 KB
/
setup-nut-netclient
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# simple script to setup a NUT netclient config
# assumptions are Ubuntu 14.04.1, and that the nut server has only one UPS attached
# and is accessible by an already configured nut user+pass.
read -e -p "Do you wish to install and configure NUT from scratch (y/n): " -i "y" SETUP_NUT
echo
if [ ! "$SETUP_NUT" = "y" ]; then
echo "OK exiting script"
exit -1
fi
if ! dpkg -s nut >/dev/null; then
echo "installing nut package"
sudo apt-get install -q nut
# Get the ups and server name as well as the nut user credentials needed
echo "Pleae input the following info"
read -e -p "Nut SERVER NAME or IP ADDRESS (needed to construct the local MONITOR line): " -i "nutserver" NUT_SERVER
read -e -p "The nut UPS NAME you wish to monitor on the above server: " -i "ups" UPS_NAME
read -e -p "Nut servers MONITOR USER (defined in /etc/nut/upsd.users): " -i "monmaster" NUT_USER
read -e -p "and the monitor users PASSWORD: " -i "mmpass" USER_PASS
# most basic of sanity checks (are any of the above empty if so exit script
if [ -z "$NUT_SERVER" ]; then echo "No server name given. Exiting."; exit -1; fi
if [ -z "$UPS_NAME" ]; then echo "No ups name given. Exiting."; exit -1; fi
if [ -z "$NUT_USER" ]; then echo "No username given. Exiting."; exit -1; fi
if [ -z "$USER_PASS" ]; then echo "No password given. Exiting."; exit -1; fi
# now to construct the MONITOR line from the above info and put it on the end of /etc/nut/upsmon.conf
echo "MONITOR $UPS_NAME@$NUT_SERVER 1 $NUT_USER $USER_PASS slave" | sudo tee -a /etc/nut/upsmon.conf >/dev/null
# now to replace the MODE=none with MODE=netclient in nut.conf
sudo sed -i 's/MODE=none/MODE=netclient/g' /etc/nut/nut.conf
echo "starting nut-client"
sudo /etc/init.d/nut-client restart
# fsd is normally called when a ups is OB (On Battery) and LB (Low Battery)
# fsd = Full Shut Down
echo "the following command should list current information about your ups"
echo "upsc $UPS_NAME@$NUT_SERVER"
echo "To test this setup it is best to reboot first then execute the following command"
echo "sudo upsmon -c fsd"
echo "If all is functioning correctly this will simulate the ups being in both the following states:"
echo "On Battery (OB) & Low Battery (LB)"
echo "In that situation the system should perform an automatic power-fail shutdown"
else
echo "nut package already installed, please consider removing nut first"
echo "as this script expects to install and configure nut itself"
echo "sudo apt-get purge nut"
echo "N.B. WARNING this will remove all previous configurations"
fi