Advertisement
bandsaw12

ASUS AC86U NUT Startup Script

Jul 28th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.37 KB | None | 0 0
  1. #!/bin/sh
  2. # Modified 2022-06-15
  3.  
  4. readonly KERN=$(uname -r)
  5. readonly LOGFILE="/opt/var/log/ups-notifications.txt"
  6. readonly UPSCONF="/opt/etc/nut/ups.conf"
  7. readonly UPSUSERS="/opt/etc/nut/upsd.users"
  8. readonly UPSMONCONF="/opt/etc/nut/upsmon.conf"
  9. UPS=""
  10. USER=""
  11. PASS=""
  12. PDFLAG=""
  13. SYSUSER=""
  14.  
  15. UPS=$(grep "\[" $UPSCONF | sed 's/\[//g' | sed 's/\]//g')
  16. USER=$(grep "\[" $UPSUSERS | sed 's/\[//g' | sed 's/\]//g')
  17. PASS=$(grep "password" $UPSUSERS | cut -f2 -d"=")
  18. PDFLAG=$(grep "POWERDOWNFLAG" $UPSMONCONF | cut -f2 -d" ")
  19. SYSUSER=$(nvram get http_username)
  20.  
  21. {
  22.     echo "----------------------------------------------------------------------------"
  23.     echo "$(date):  Starting NUT Services (system startup Script)"
  24.  
  25.     if [ -f "$PDFLAG" ]; then
  26.         echo "     - Power down flag file detected, deleting"
  27.         rm "$PDFLAG"
  28.     fi
  29.  
  30.     lsmod | grep '^input_core' > /dev/null 2>&1
  31.     if [ "$?" = "1" ]; then
  32.         echo "Loading kernel module INPUT_CORE"
  33.         insmod /lib/modules/${KERN}/kernel/drivers/input/input-core.ko
  34.     else
  35.         echo "Kernel module INPUT_CORE is already loaded"
  36.     fi
  37.    
  38.     lsmod | grep '^hid' > /dev/null 2>&1
  39.     if [ "$?" = "1" ]; then
  40.         echo "Loading kernel module HID"
  41.         insmod /lib/modules/${KERN}/kernel/drivers/hid/hid.ko
  42.     else
  43.         echo "Kernel module HID is already loaded"
  44.     fi
  45.    
  46.     lsmod | grep '^usbhid' > /dev/null 2>&1
  47.     if [ "$?" = "1" ]; then
  48.         echo "Loading kernel module USBHID"
  49.         insmod /lib/modules/${KERN}/kernel/drivers/hid/usbhid/usbhid.ko
  50.     else
  51.         echo "Kernel module USBHID is already loaded"
  52.     fi
  53.    
  54.     sleep 2
  55.     echo
  56.     echo "Executing upsdrvctl command with SYSUSER as ${SYSUSER}"
  57.     upsdrvctl -u ${SYSUSER} start
  58.     sleep 10
  59.  
  60.     echo
  61.     echo "Executing upsd command with SYSUSER as ${SYSUSER}"
  62.     upsd -u ${SYSUSER}
  63.     sleep 2
  64.     echo
  65.     echo "Executing upsmon command"
  66.     upsmon -p
  67.     sleep 5
  68.    
  69.     echo
  70.     BATTLOW=$(upsc ${UPS}@localhost battery.charge.low)
  71.     if ! [ "$BATTLOW" = "25" ]; then
  72.         echo "     - Setting UPS Battery Low level to 25%"
  73.         upsrw -s battery.charge.low=25 -u ${USER} -p ${PASS} ${UPS}@localhost
  74.     fi
  75.    
  76.     RUNTIMELOW=$(upsc ${UPS}@localhost battery.runtime.low)
  77.     if ! [ "$RUNTIMELOW" = "600" ]; then
  78.         echo "     - Setting UPS Low Batt Run Time to 600 seconds"
  79.         upsrw -s battery.runtime.low=600 -u ${USER} -p ${PASS} ${UPS}@localhost
  80.     fi
  81.    
  82.     echo "$(date):  End of NUT Startup Script"
  83.     echo "-------------------------------------------"
  84. } >> $LOGFILE 2>&1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement