fork unRAID NUT plugin

This commit is contained in:
dmacias72 2017-04-28 20:14:39 -06:00
parent 93227ee85c
commit 0540297384
28 changed files with 670 additions and 0 deletions

69
source/nut/etc/rc.d/rc.nut Executable file
View File

@ -0,0 +1,69 @@
#!/bin/sh
# Slackware startup script for Network UPS Tools
# Copyright 2010 V'yacheslav Stetskevych
# Edited for unRAID by macester macecapri@gmail.com
DPATH=/usr/bin
FILE=/boot/config/plugins/nut/nut.cfg
export PATH=$DPATH:$PATH
start_driver() {
/usr/sbin/upsdrvctl -u root start || exit 1
}
start_upsd() {
/usr/sbin/upsd -u root || exit 1
}
start_upsmon() {
/usr/sbin/upsmon -u root || exit 1
}
stop() {
echo "Stopping the UPS services... "
if pgrep upsd 2>&1 >/dev/null; then
/usr/sbin/upsd -c stop; fi
if pgrep upsmon 2>&1 >/dev/null; then
/usr/sbin/upsmon -c stop; fi
/usr/sbin/upsdrvctl stop
sleep 2
if [ -f /var/run/upsmon.pid ]; then
rm /var/run/upsmon.pid; fi
}
write_config() {
/usr/local/emhttp/plugins/nut/scripts/write_config.sh
}
case "$1" in
start) # starts everything (for a ups server box)
sleep 1
write_config
sleep 3
start_driver
start_upsd
start_upsmon
;;
start_upsmon) # starts upsmon only (for a ups client box)
start_upsmon
;;
stop) # stops all UPS-related daemons
stop
;;
shutdown) # shuts down the UPS
echo "Killing inverter..."
/usr/sbin/upsdrvctl shutdown
;;
reload)
write_config
/usr/sbin/upsd -c reload
/usr/sbin/upsmon -c reload
;;
write_config)
write_config
;;
*)
echo "Usage: $0 {start|start_upsmon|stop|shutdown|reload|restart|write_config}"
esac

1
source/nut/etc/ups/nut.conf Executable file
View File

@ -0,0 +1 @@
MODE=standalone

3
source/nut/etc/ups/ups.conf Executable file
View File

@ -0,0 +1,3 @@
[ups]
driver=none
port=auto

1
source/nut/etc/ups/upsd.conf Executable file
View File

@ -0,0 +1 @@
LISTEN 0.0.0.0

11
source/nut/etc/ups/upsd.users Executable file
View File

@ -0,0 +1,11 @@
[admin]
password=adminpass
actions=set
actions=fsd
instcmds=all
[monuser]
password=monpass
upsmon master
[slaveuser]
password=slavepass
upsmon slave

6
source/nut/etc/ups/upsmon.conf Executable file
View File

@ -0,0 +1,6 @@
MONITOR ups@localhost 1 monuser monpass master
SHUTDOWNCMD "/usr/local/sbin/powerdown"
POWERDOWNFLAG /etc/ups/flag/killpower
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYCMD "/etc/ups/notifycmd"

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,36 @@
Menu="NUTsettings"
Title="NUT Details"
---
<?PHP
/* Copyright 2005-2016, Lime Technology
* Copyright 2015, Dan Landon.
* Copyright 2015, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<script>
function getNUTstatus() {
$.get('/plugins/nut/include/nut_status.php',{all:'true'},function(data) {
if (data) {
data = data.split(/\n/);
$('#nut_summary').html(data[0]);
$('#nut_status').html(data[1]);
}
<?if ($update):?>
setTimeout(getUPSstatus,<?=max(abs($display['refresh']),15000)?>);
<?endif;?>
});
}
$(getNUTstatus);
</script>
<table class="tablesorter shift">
<thead><tr><th style="width:15%">Key</th><th style="width:35%">Value</th><th style="width:15%">Key</th><th style="width:35%">Value</th></tr></thead>
<tbody id="nut_status"><tr><td colspan="4" style="text-align:center"><i class="fa fa-spinner fa-spin icon"></i><em>Please wait, retrieving UPS information...</em></td></tr></tbody>
</table>

View File

@ -0,0 +1,185 @@
Menu="OtherSettings"
Type="xmenu"
Title="NUT Settings"
Icon="nut.png"
---
<?PHP
/* Copyright 2015, Dan Landon.
* Copyright 2015, Bergware International.
* Copyright 2015, Lime Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Modified by macester macecapri@gmail.com for NUT plugin
*
*/
?>
<?
$sName = "nut";
$cfg = parse_plugin_cfg($sName);
?>
<script>
function toggleCustomDriver(form) {
var readonly = form.DRIVER.value != 'custom';
form.SERIAL.readOnly = readonly;
if (readonly) form.SERIAL.value = '';
}
$(function() {
showStatus('upsmon');
});
</script>
<form markdown="1" name="nut_settings" method="POST" action="/update.php" target="progressFrame">
<input type="hidden" name="#file" value="<?=$sName?>/<?=$sName?>.cfg">
<input type="hidden" name="#include" value="/plugins/<?=$sName?>/include/update.nut.php">
<span style="float:right;margin-right:10px"><a href="http://www.networkupstools.org/docs/user-manual.chunked/" target="_blank" title="NUT UPS user manual"><i class="fa fa-file-text-o"></i> <u>Online Manual</u></a></span>
Start NUT UPS service:
: <select name="SERVICE" size="1">
<?=mk_option($cfg['SERVICE'], "disable", "No");?>
<?=mk_option($cfg['SERVICE'], "enable", "Yes");?>
</select>
> Set to 'Yes' to enable NUT and start the service, set to 'No' to disable NUT and stop the service.
> Setting 'Yes' will also enable NUT on unRAID boot.
UPS Driver:
: <select name="DRIVER" size="1" onChange="toggleCustomDriver(this.form)">
<?=mk_option($cfg['DRIVER'], "blazer_usb", "Blazer_usb");?>
<?=mk_option($cfg['DRIVER'], "blazer_ser", "Blazer_ser");?>
<?=mk_option($cfg['DRIVER'], "bcmxcp_usb", "Bcmxcp_usb");?>
<?=mk_option($cfg['DRIVER'], "richcomm_usb", "Richcomm_usb");?>
<?=mk_option($cfg['DRIVER'], "tripplite_usb", "Tripplite_usb");?>
<?=mk_option($cfg['DRIVER'], "usbhid-ups", "Usbhid-ups");?>
<?=mk_option($cfg['DRIVER'], "custom", "Custom");?>
</select>
> **Check the link below to find the driver matching your UPS**
>
> + <a href="http://www.networkupstools.org/stable-hcl.html" target="_blank">http://www.networkupstools.org/stable-hcl.html</a>
>
> For other devices set **Custom** and enter the driver manually below.
> Dont forget to match the port with your driver
Custom Driver:
: <input type="text" name="SERIAL" class="narrow" maxlength="40" value="<?=$cfg['SERIAL'];?>">
> Use the *Link* above to find which Driver to choose.
> Dont forget to match the port with your driver
UPS Port:
: <input type="text" name="PORT" class="narrow" maxlength="40" value="<?=$cfg['PORT'];?>">
> Enter the *port* which your UPS connects to.
>
> + **auto** - Set to "auto" if the ups is connected by usb.
> + **/dev/tty0** - Example, for seriall devices**
UPS Mode:
: <select name="MODE" size="1">
<?=mk_option($cfg['MODE'], "standalone", "Standalone");?>
<?=mk_option($cfg['MODE'], "netserver", "Netserver");?>
</select>
> Select the *mode* which mode your UPS will run in.
>
> + **standalone** - When the ups is only used by the local host**
> + **netserver** - When nut clients/slaves need to connect to the ups**
UPS Shutdown Mode:
: <select name="SHUTDOWN" size="1">
<?=mk_option($cfg['SHUTDOWN'], "batt_level", "Battery Level");?>
<?=mk_option($cfg['SHUTDOWN'], "batt_timer", "Runtime Left");?>
<?=mk_option($cfg['SHUTDOWN'], "sec_timer", "Time on Battery");?>
</select>
> Select the *Shutdown mode* for NUT, this mode determines which "timer" to use for when the UPS will shutdown the system.
>
> + **Battery Level** - Shuts down the system when there is X percentage left on the battery **
> + **Runtime Left** - Shuts down the system when there is X runtime left on the battery (in seconds)**
> + **Time on Battery** - Shuts down the system when the user defined timer reaches zero (in seconds)**
Battery level to initiate shutdown (%):
: <input type="text" name="BATTERYLEVEL" class="narrow" maxlength="2" value="<?=$cfg['BATTERYLEVEL'];?>">
> If during a power failure, the remaining battery percentage (as reported by the UPS) is below or equal to *Battery level*, NUT will initiate a system shutdown.
Runtime left to initiate shutdown (seconds):
: <input type="text" name="SECONDS" class="narrow" maxlength="4" value="<?=$cfg['SECONDS'];?>">
> If during a power failure, the remaining runtime seconds (as calculated internally by the UPS) is below or equal to *seconds*, NUT will initiate a system shutdown.
> **Note** depeding on your ups this value can "fluctuate" so be aware. if yot ups have an old battery dont use this
Time on battery before shutdown (seconds):
: <input type="text" name="TIMEOUT" class="narrow" maxlength="4" value="<?=$cfg['TIMEOUT'];?>">
> The time in seconds before the system will power down if a power failure accours.
Turn off UPS after shutdown:
: <select name="UPSKILL" size="1">
<?=mk_option($cfg['UPSKILL'], "disable", "No");?>
<?=mk_option($cfg['UPSKILL'], "enable", "Yes");?>
</select>
> Set to *Yes* to turn off the power to the UPS after a shutdown.
>
> Check your bios and enable, "Automatically power on after power loss" so that the server starts again when powers is restored.
<br><br><br>
> **Additional Notes**
>
> The usernames and passwords for *admin* and *slave* accounts in *upsd.users* file **
>
> + **Admin Account**: "admin / adminpass" - **Slave Account**: "slaveuser / slavepass"
>
> NUT is set to listen on all interface in upsd.conf "LISTEN 0.0.0.0"
>
> macester (macecapri@gmail.com)
<input type="submit" name="#default" value="Default">
: <input type="submit" name="#apply" value="Apply"><input type="button" value="Done" onclick="done()">
</form>
<div id="title"><span class="left"><img src="/plugins/nut/icons/nutsettings.png" class="icon">NUT Status</span></div>
<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
getStatus();
});
function getStatus() {
$('div#nut_status').load('/plugins/nut/include/nut_status.php');
setTimeout("getStatus()",10000);
}
</script>
<table class='share_status dash m0'>
<thead>
<tr><td colspan='3'>UPS Statistics</td></tr>
</thead>
<tr><td colspan='3'><div id='nut_status'></div></td></tr>
</table>

View File

@ -0,0 +1,3 @@
####Network UPS Tools (NUT)####
A Plugin that supports a wide variety of UPS brands and models.

View File

@ -0,0 +1,10 @@
SERVICE="disable"
DRIVER="custom"
SERIAL="none"
PORT="auto"
MODE="standalone"
SHUTDOWN="sec_timer"
BATTERYLEVEL="20"
SECONDS="240"
TIMEOUT="240"
UPSKILL="disable"

View File

@ -0,0 +1,11 @@
#!/bin/bash
cfg=/boot/config/plugins/nut/nut.cfg
# Daemon already running or no custom file?
[[ -f /var/run/upsmon.pid || ! -f $cfg ]] && exit
# Read settings
source $cfg
# Start daemon
[[ $SERVICE == enable ]] && /usr/local/emhttp/plugins/nut/scripts/rc.nut start

Binary file not shown.

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,6 @@
<?PHP
?>
<?
$sStatus = "<pre>".shell_exec("/usr/bin/upsc ups")."</pre>";
echo $sStatus;
?>

View File

@ -0,0 +1,32 @@
<?PHP
/* Copyright 2015, Dan Landon.
* Copyright 2015, Bergware International.
* Copyright 2015, Lime Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Edited by macester for NUT Plugin.
*/
?>
<?
$cfg = "/boot/config/plugins/nut/nut.cfg";
$connection = $_POST['DRIVER']=='custom' ? $_POST['SERIAL'] : $_POST['DRIVER'];
exec("/etc/rc.d/rc.nut stop");
exec("sed -i -e '/^SERVICE/c\\SERVICE=\"'{$_POST['SERVICE']}'\"' $cfg");
exec("sed -i -e '/^PORT/c\\PORT=\"'{$_POST['PORT']}'\"' $cfg");
exec("sed -i -e '/^MODE/c\\MODE=\"'{$_POST['MODE']}'\"' $cfg");
exec("sed -i -e '/^SHUTDOWN/c\\SHUTDOWN=\"'{$_POST['SHUTDOWN']}'\"' $cfg");
exec("sed -i -e '/^BATTERYLEVEL/c\\BATTERYLEVEL=\"'{$_POST['BATTERYLEVEL']}'\"' $cfg");
exec("sed -i -e '/^SECONDS/c\\SECONDS=\"'{$_POST['SECONDS']}'\"' $cfg");
exec("sed -i -e '/^TIMEOUT/c\\TIMEOUT=\"'{$_POST['TIMEOUT']}'\"' $cfg");
exec("sed -i -e '/^UPSKILL/c\\UPSKILL=\"'{$_POST['UPSKILL']}'\"' $cfg");
exec("sed -i -e '/^DRIVER/c\\DRIVER=\"'{$connection}'\"' $cfg");
if ($_POST['SERVICE']=='enable') exec("/usr/local/emhttp/plugins/nut/scripts/rc.nut start");
?>

View File

@ -0,0 +1,30 @@
#!/bin/bash
#
# NUT NOTIFYCMD script macester macecapri@gmail.com
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
BATTERYLEVEL=50
trap "exit 0" SIGTERM
if [ "$NOTIFYTYPE" = "ONLINE" ]
then
echo $0: power restored | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is no longer on battery" -i "normal"
# Cause all instances of this script to exit.
killall -s SIGTERM `basename $0`
fi
if [ "$NOTIFYTYPE" = "ONBATT" ]
then
echo $0: System shuts down when battery reaches $BATTERYLEVEL % | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is on battery" -i "alert"
# Loop with one second interval to allow SIGTERM reception.
timer=$( /usr/bin/upsc ups|grep battery.charge:|awk '{print $2}' )
while [ $timer -gt $BATTERYLEVEL ]
do
sleep 1
timer=$( /usr/bin/upsc ups|grep battery.charge:|awk '{print $2}' )
done
echo $0: commencing shutdown | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is shutting down unRAID" -i "alert"
upsmon -c fsd
fi

View File

@ -0,0 +1,30 @@
#!/bin/bash
#
# NUT NOTIFYCMD script macester macecapri@gmail.com
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
SECONDS=200
trap "exit 0" SIGTERM
if [ "$NOTIFYTYPE" = "ONLINE" ]
then
echo $0: power restored | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is no longer on battery" -i "normal"
# Cause all instances of this script to exit.
killall -s SIGTERM `basename $0`
fi
if [ "$NOTIFYTYPE" = "ONBATT" ]
then
echo $0: System shuts down when there is $SECONDS seconds left on the battery... | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is on battery" -i "alert"
# Loop with one second interval to allow SIGTERM reception.
timer=$( /usr/bin/upsc ups|grep battery.runtime:|awk '{print $2}' )
while [ $timer -gt $SECONDS ]
do
sleep 1
timer=$( /usr/bin/upsc ups|grep battery.runtime:|awk '{print $2}' )
done
echo $0: commencing shutdown | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is shutting down unRAID" -i "alert"
upsmon -c fsd
fi

View File

@ -0,0 +1,30 @@
#!/bin/bash
#
# NUT NOTIFYCMD script macester macecapri@gmail.com
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
TIMEOUT=200
trap "exit 0" SIGTERM
if [ "$NOTIFYTYPE" = "ONLINE" ]
then
echo $0: power restored | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is no longer on battery" -i "normal"
# Cause all instances of this script to exit.
killall -s SIGTERM `basename $0`
fi
if [ "$NOTIFYTYPE" = "ONBATT" ]
then
echo $0: $TIMEOUT seconds till system powers down... | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is on battery" -i "alert"
# Loop with one second interval to allow SIGTERM reception.
let "n = $TIMEOUT"
while [ $n -ne 0 ]
do
sleep 1
let "n--"
done
echo $0: commencing shutdown | wall
/usr/local/emhttp/plugins/dynamix/scripts/notify -e "UPS Notification" -s "UPS is shutting down unRAID" -i "alert"
upsmon -c fsd
fi

View File

@ -0,0 +1,14 @@
#!/bin/sh
# This file is part of Network UPS Tools build for Slackware Linux.
# It should be sourced in /etc/rc.d/rc.0 as part of the poweroff sequence.
# Here, we signal the UPS to shut off the power.
# Reference: http://www.mail-archive.com/nut-upsdev@lists.alioth.debian.org/msg01099.html
# To be sourced after the genpowerd block and before the actual halt.
if [ -f /etc/ups/flag/killpower ]; then
echo "----------------------------------------Shutting down UPS power!"
/usr/sbin/upsdrvctl shutdown
sleep 40
echo "The UPS was not shut off properly, or the power came back in the"
echo "middle of the shutdown process, or USB communication failed."
sleep 10
fi

View File

@ -0,0 +1,11 @@
#!/bin/sh
# This file is part of Network UPS Tools build for Slackware Linux.
# It should be sourced in /etc/rc.d/rc.0 as part of the poweroff sequence.
# Here, we restart udev so that the system is able to kill off the UPS inverter.
# Reference: http://www.mail-archive.com/nut-upsdev@lists.alioth.debian.org/msg01099.html
# To be sourced after the rootfs has been remounted read-only.
if [ -f /etc/ups/flag/killpower ]; then
echo "Restarting udev to be able to shut the UPS inverter off..."
/etc/rc.d/rc.udev start
sleep 10
fi

View File

@ -0,0 +1,69 @@
#!/bin/sh
# Slackware startup script for Network UPS Tools
# Copyright 2010 V'yacheslav Stetskevych
# Edited for unRAID by macester macecapri@gmail.com
DPATH=/usr/bin
FILE=/boot/config/plugins/nut/nut.cfg
export PATH=$DPATH:$PATH
start_driver() {
/usr/sbin/upsdrvctl -u root start || exit 1
}
start_upsd() {
/usr/sbin/upsd -u root || exit 1
}
start_upsmon() {
/usr/sbin/upsmon -u root || exit 1
}
stop() {
echo "Stopping the UPS services... "
if pgrep upsd 2>&1 >/dev/null; then
/usr/sbin/upsd -c stop; fi
if pgrep upsmon 2>&1 >/dev/null; then
/usr/sbin/upsmon -c stop; fi
/usr/sbin/upsdrvctl stop
sleep 2
if [ -f /var/run/upsmon.pid ]; then
rm /var/run/upsmon.pid; fi
}
write_config() {
/usr/local/emhttp/plugins/nut/scripts/write_config.sh
}
case "$1" in
start) # starts everything (for a ups server box)
sleep 1
write_config
sleep 3
start_driver
start_upsd
start_upsmon
;;
start_upsmon) # starts upsmon only (for a ups client box)
start_upsmon
;;
stop) # stops all UPS-related daemons
stop
;;
shutdown) # shuts down the UPS
echo "Killing inverter..."
/usr/sbin/upsdrvctl shutdown
;;
reload)
write_config
/usr/sbin/upsd -c reload
/usr/sbin/upsmon -c reload
;;
write_config)
write_config
;;
*)
echo "Usage: $0 {start|start_upsmon|stop|shutdown|reload|restart|write_config}"
esac

View File

@ -0,0 +1,2 @@
#!/bin/sh
/etc/rc.d/rc.nut start

View File

@ -0,0 +1,2 @@
#!/bin/sh
/etc/rc.d/rc.nut stop

View File

@ -0,0 +1,4 @@
if [ -f /usr/local/emhttp/plugins/nut/scripts/nut_kill_inverter ]; then
. /usr/local/emhttp/plugins/nut/scripts/nut_kill_inverter
fi

View File

@ -0,0 +1,4 @@
if [ -f /usr/local/emhttp/plugins/nut/scripts/nut_restart_udev ]; then
. /usr/local/emhttp/plugins/nut/scripts/nut_restart_udev
fi

View File

@ -0,0 +1,99 @@
#!/bin/bash
#
# NUT plugin configuration script for unRAID
# By macester macecapri@gmail.com
#
NUTCFG=/boot/config/plugins/nut/nut.cfg
# Killpower flag permissions
chmod 777 /etc/ups/flag
# Add nut user and group for udev at shutdown
GROUP=$( grep -ic "218" /etc/group )
USER=$( grep -ic "218" /etc/passwd )
if [ $GROUP -ge 1 ]; then
echo "NUT Group already configured"
else
groupadd -g 218 nut
fi
if [ $USER -ge 1 ]; then
echo "NUT User already configured"
else
useradd -u 218 -g nut -s /bin/false nut
fi
# Nut config files
# Add the driver config
driver_custom=$( grep -ic 'DRIVER="custom"' $NUTCFG )
if [ $driver_custom -eq 1 ]; then
var1=$( grep -i "SERIAL=" $NUTCFG|cut -d \" -f2|sed 's/^/driver = /' )
sed -i "2 s/.*/$var1/" /etc/ups/ups.conf
else
var2=$( grep -i "DRIVER=" $NUTCFG|cut -d \" -f2|sed 's/^/driver = /' )
sed -i "2 s/.*/$var2/" /etc/ups/ups.conf
fi
# add the port
var3=$( grep -i "PORT=" $NUTCFG|cut -d \" -f2|sed 's/^/port = /' )
sed -i "3 s~.*~$var3~" /etc/ups/ups.conf
# add mode standalone/netserver
var4=$( grep -i "MODE=" $NUTCFG|cut -d \" -f2|sed 's/^/MODE=/' )
sed -i "1 s/.*/$var4/" /etc/ups/nut.conf
# Set which shutdown script NUT should use
mode_bat_level=$( grep -ic 'SHUTDOWN="batt_level"' $NUTCFG )
mode_bat_timer=$( grep -ic 'SHUTDOWN="batt_timer"' $NUTCFG )
if [ $mode_bat_level -eq 1 ]; then
sed -i "6 s,.*,NOTIFYCMD \"/usr/local/emhttp/plugins/nut/scripts/notifycmd_batterylevel\"," /etc/ups/upsmon.conf
else
if [ $mode_bat_timer -eq 1 ]; then
sed -i "6 s,.*,NOTIFYCMD \"/usr/local/emhttp/plugins/nut/scripts/notifycmd_seconds\"," /etc/ups/upsmon.conf
else
sed -i "6 s,.*,NOTIFYCMD \"/usr/local/emhttp/plugins/nut/scripts/notifycmd_timeout\"," /etc/ups/upsmon.conf
fi
fi
# Edit timers fo shutdown scripts
# shutdown when battery gets to level
var5=$( grep -i "BATTERYLEVEL=" $NUTCFG|cut -d \" -f2|sed 's/^/BATTERYLEVEL=/' )
sed -i "6 s/.*/$var5/" /usr/local/emhttp/plugins/nut/scripts/notifycmd_batterylevel
# shutdown when battery time runs out
var6=$( grep -i "SECONDS=" $NUTCFG|cut -d \" -f2|sed 's/^/SECONDS=/' )
sed -i "6 s/.*/$var6/" /usr/local/emhttp/plugins/nut/scripts/notifycmd_seconds
# shutdown on user timer
var7=$( grep -i "TIMEOUT=" $NUTCFG|cut -d \" -f2|sed 's/^/TIMEOUT=/' )
sed -i "6 s/.*/$var7/" /usr/local/emhttp/plugins/nut/scripts/notifycmd_timeout
# Set if the ups should be turned off
ups_kill=$( grep -ic 'UPSKILL="enable"' $NUTCFG )
if [ $ups_kill -eq 1 ]; then
var8='POWERDOWNFLAG /etc/ups/flag/killpower'
sed -i "3 s,.*,$var8," /etc/ups/upsmon.conf
else
var9='POWERDOWNFLAG /etc/ups/flag/no_killpower'
sed -i "3 s,.*,$var9," /etc/ups/upsmon.conf
fi
# Link shutdown scripts for poweroff in rc.0 and rc.6
UDEV=$( grep -ic "/usr/local/emhttp/plugins/nut/scripts/nut_restart_udev" /etc/rc.d/rc.6 )
if [ $UDEV -ge 1 ]; then
echo "UDEV lines already exist in rc.0,6"
else
sed -i '/\/bin\/mount -v -n -o remount,ro \//r /usr/local/emhttp/plugins/nut/scripts/txt/udev.txt' /etc/rc.d/rc.6
fi
KILL=$( grep -ic "/usr/local/emhttp/plugins/nut/scripts/nut_kill_inverter" /etc/rc.d/rc.6 )
if [ $KILL -ge 1 ]; then
echo "KILL_INVERTER lines already exist in rc.0,6"
else
sed -i -e '/# Now halt (poweroff with APM or ACPI enabled kernels) or reboot./r /usr/local/emhttp/plugins/nut/scripts/txt/kill.txt' -e //N /etc/rc.d/rc.6
fi