diff --git a/source/nut/etc/rc.d/rc.nut b/source/nut/etc/rc.d/rc.nut
new file mode 100755
index 00000000..92323dc5
--- /dev/null
+++ b/source/nut/etc/rc.d/rc.nut
@@ -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
diff --git a/source/nut/etc/ups/nut.conf b/source/nut/etc/ups/nut.conf
new file mode 100755
index 00000000..6529f5ed
--- /dev/null
+++ b/source/nut/etc/ups/nut.conf
@@ -0,0 +1 @@
+MODE=standalone
diff --git a/source/nut/etc/ups/ups.conf b/source/nut/etc/ups/ups.conf
new file mode 100755
index 00000000..c2d29b0e
--- /dev/null
+++ b/source/nut/etc/ups/ups.conf
@@ -0,0 +1,3 @@
+[ups]
+driver=none
+port=auto
diff --git a/source/nut/etc/ups/upsd.conf b/source/nut/etc/ups/upsd.conf
new file mode 100755
index 00000000..a32659e5
--- /dev/null
+++ b/source/nut/etc/ups/upsd.conf
@@ -0,0 +1 @@
+LISTEN 0.0.0.0
diff --git a/source/nut/etc/ups/upsd.users b/source/nut/etc/ups/upsd.users
new file mode 100755
index 00000000..80c04e82
--- /dev/null
+++ b/source/nut/etc/ups/upsd.users
@@ -0,0 +1,11 @@
+[admin]
+password=adminpass
+actions=set
+actions=fsd
+instcmds=all
+[monuser]
+password=monpass
+upsmon master
+[slaveuser]
+password=slavepass
+upsmon slave
diff --git a/source/nut/etc/ups/upsmon.conf b/source/nut/etc/ups/upsmon.conf
new file mode 100755
index 00000000..8991b938
--- /dev/null
+++ b/source/nut/etc/ups/upsmon.conf
@@ -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"
diff --git a/source/nut/etc/ups/upssched.conf b/source/nut/etc/ups/upssched.conf
new file mode 100755
index 00000000..8b137891
--- /dev/null
+++ b/source/nut/etc/ups/upssched.conf
@@ -0,0 +1 @@
+
diff --git a/source/nut/usr/local/emhttp/plugins/nut/NUTdetails.page b/source/nut/usr/local/emhttp/plugins/nut/NUTdetails.page
new file mode 100644
index 00000000..2867e4f3
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/NUTdetails.page
@@ -0,0 +1,36 @@
+Menu="NUTsettings"
+Title="NUT Details"
+---
+
+
+
+
+Key | Value | Key | Value |
+Please wait, retrieving UPS information... |
+
diff --git a/source/nut/usr/local/emhttp/plugins/nut/NUTsettings.page b/source/nut/usr/local/emhttp/plugins/nut/NUTsettings.page
new file mode 100755
index 00000000..198b2a6f
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/NUTsettings.page
@@ -0,0 +1,185 @@
+Menu="OtherSettings"
+Type="xmenu"
+Title="NUT Settings"
+Icon="nut.png"
+---
+
+
+
+$sName = "nut";
+$cfg = parse_plugin_cfg($sName);
+?>
+
+
+
+
+NUT Status
+
+
+
+
+
+
diff --git a/source/nut/usr/local/emhttp/plugins/nut/README.md b/source/nut/usr/local/emhttp/plugins/nut/README.md
new file mode 100755
index 00000000..9e82ca6f
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/README.md
@@ -0,0 +1,3 @@
+####Network UPS Tools (NUT)####
+
+A Plugin that supports a wide variety of UPS brands and models.
diff --git a/source/nut/usr/local/emhttp/plugins/nut/default.cfg b/source/nut/usr/local/emhttp/plugins/nut/default.cfg
new file mode 100755
index 00000000..ca4afa9b
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/default.cfg
@@ -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"
diff --git a/source/nut/usr/local/emhttp/plugins/nut/event/disks_mounted b/source/nut/usr/local/emhttp/plugins/nut/event/disks_mounted
new file mode 100755
index 00000000..78e573e0
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/event/disks_mounted
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/icons/nutdetails.png b/source/nut/usr/local/emhttp/plugins/nut/icons/nutdetails.png
new file mode 100644
index 00000000..55b2a599
Binary files /dev/null and b/source/nut/usr/local/emhttp/plugins/nut/icons/nutdetails.png differ
diff --git a/source/nut/usr/local/emhttp/plugins/nut/icons/nutsettings.png b/source/nut/usr/local/emhttp/plugins/nut/icons/nutsettings.png
new file mode 100755
index 00000000..27913857
Binary files /dev/null and b/source/nut/usr/local/emhttp/plugins/nut/icons/nutsettings.png differ
diff --git a/source/nut/usr/local/emhttp/plugins/nut/images/nut.png b/source/nut/usr/local/emhttp/plugins/nut/images/nut.png
new file mode 100755
index 00000000..d048eba3
Binary files /dev/null and b/source/nut/usr/local/emhttp/plugins/nut/images/nut.png differ
diff --git a/source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php b/source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php
new file mode 100755
index 00000000..c18eb7c1
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php
@@ -0,0 +1,6 @@
+
+
+ $sStatus = "".shell_exec("/usr/bin/upsc ups")."
";
+ echo $sStatus;
+?>
diff --git a/source/nut/usr/local/emhttp/plugins/nut/include/update.nut.php b/source/nut/usr/local/emhttp/plugins/nut/include/update.nut.php
new file mode 100755
index 00000000..ffac280f
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/include/update.nut.php
@@ -0,0 +1,32 @@
+
+
+$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");
+?>
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_batterylevel b/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_batterylevel
new file mode 100755
index 00000000..ed9db48c
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_batterylevel
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_seconds b/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_seconds
new file mode 100755
index 00000000..0df4e4d8
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_seconds
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_timeout b/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_timeout
new file mode 100755
index 00000000..da3dc093
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/notifycmd_timeout
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/nut_kill_inverter b/source/nut/usr/local/emhttp/plugins/nut/scripts/nut_kill_inverter
new file mode 100755
index 00000000..405acccd
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/nut_kill_inverter
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/nut_restart_udev b/source/nut/usr/local/emhttp/plugins/nut/scripts/nut_restart_udev
new file mode 100755
index 00000000..36c9bffa
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/nut_restart_udev
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/rc.nut b/source/nut/usr/local/emhttp/plugins/nut/scripts/rc.nut
new file mode 100755
index 00000000..92323dc5
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/rc.nut
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/start b/source/nut/usr/local/emhttp/plugins/nut/scripts/start
new file mode 100755
index 00000000..668b866c
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/start
@@ -0,0 +1,2 @@
+#!/bin/sh
+/etc/rc.d/rc.nut start
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/stop b/source/nut/usr/local/emhttp/plugins/nut/scripts/stop
new file mode 100755
index 00000000..9d14b27d
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/stop
@@ -0,0 +1,2 @@
+#!/bin/sh
+/etc/rc.d/rc.nut stop
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/txt/kill.txt b/source/nut/usr/local/emhttp/plugins/nut/scripts/txt/kill.txt
new file mode 100755
index 00000000..0ecf3025
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/txt/kill.txt
@@ -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
+
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/txt/udev.txt b/source/nut/usr/local/emhttp/plugins/nut/scripts/txt/udev.txt
new file mode 100755
index 00000000..6251dc19
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/txt/udev.txt
@@ -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
diff --git a/source/nut/usr/local/emhttp/plugins/nut/scripts/write_config.sh b/source/nut/usr/local/emhttp/plugins/nut/scripts/write_config.sh
new file mode 100755
index 00000000..791c658d
--- /dev/null
+++ b/source/nut/usr/local/emhttp/plugins/nut/scripts/write_config.sh
@@ -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