Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Modified 2022-06-15
- readonly KERN=$(uname -r)
- readonly LOGFILE="/opt/var/log/ups-notifications.txt"
- readonly UPSCONF="/opt/etc/nut/ups.conf"
- readonly UPSUSERS="/opt/etc/nut/upsd.users"
- readonly UPSMONCONF="/opt/etc/nut/upsmon.conf"
- UPS=""
- USER=""
- PASS=""
- PDFLAG=""
- SYSUSER=""
- UPS=$(grep "\[" $UPSCONF | sed 's/\[//g' | sed 's/\]//g')
- USER=$(grep "\[" $UPSUSERS | sed 's/\[//g' | sed 's/\]//g')
- PASS=$(grep "password" $UPSUSERS | cut -f2 -d"=")
- PDFLAG=$(grep "POWERDOWNFLAG" $UPSMONCONF | cut -f2 -d" ")
- SYSUSER=$(nvram get http_username)
- {
- echo "----------------------------------------------------------------------------"
- echo "$(date): Starting NUT Services (system startup Script)"
- if [ -f "$PDFLAG" ]; then
- echo " - Power down flag file detected, deleting"
- rm "$PDFLAG"
- fi
- lsmod | grep '^input_core' > /dev/null 2>&1
- if [ "$?" = "1" ]; then
- echo "Loading kernel module INPUT_CORE"
- insmod /lib/modules/${KERN}/kernel/drivers/input/input-core.ko
- else
- echo "Kernel module INPUT_CORE is already loaded"
- fi
- lsmod | grep '^hid' > /dev/null 2>&1
- if [ "$?" = "1" ]; then
- echo "Loading kernel module HID"
- insmod /lib/modules/${KERN}/kernel/drivers/hid/hid.ko
- else
- echo "Kernel module HID is already loaded"
- fi
- lsmod | grep '^usbhid' > /dev/null 2>&1
- if [ "$?" = "1" ]; then
- echo "Loading kernel module USBHID"
- insmod /lib/modules/${KERN}/kernel/drivers/hid/usbhid/usbhid.ko
- else
- echo "Kernel module USBHID is already loaded"
- fi
- sleep 2
- echo
- echo "Executing upsdrvctl command with SYSUSER as ${SYSUSER}"
- upsdrvctl -u ${SYSUSER} start
- sleep 10
- echo
- echo "Executing upsd command with SYSUSER as ${SYSUSER}"
- upsd -u ${SYSUSER}
- sleep 2
- echo
- echo "Executing upsmon command"
- upsmon -p
- sleep 5
- echo
- BATTLOW=$(upsc ${UPS}@localhost battery.charge.low)
- if ! [ "$BATTLOW" = "25" ]; then
- echo " - Setting UPS Battery Low level to 25%"
- upsrw -s battery.charge.low=25 -u ${USER} -p ${PASS} ${UPS}@localhost
- fi
- RUNTIMELOW=$(upsc ${UPS}@localhost battery.runtime.low)
- if ! [ "$RUNTIMELOW" = "600" ]; then
- echo " - Setting UPS Low Batt Run Time to 600 seconds"
- upsrw -s battery.runtime.low=600 -u ${USER} -p ${PASS} ${UPS}@localhost
- fi
- echo "$(date): End of NUT Startup Script"
- echo "-------------------------------------------"
- } >> $LOGFILE 2>&1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement