UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / platforms / darwin / apccontrol.in
blob145f2df975cd2442c80bd8a9ff46aec6c00de6f7
1 #!@SCRIPTSHELL@
3 # Copyright (C) 1999-2002 Riccardo Facchetti <riccardo@master.oasi.gpa.it>
5 #  for apcupsd release @VERSION@ (@DATE@) - @DISTNAME@
7 # @configure_input@
9 #  Note, this is a generic file that can be used by most
10 #   systems. If a particular system needs to have something
11 #   special, start with this file, and put a copy in the
12 #   platform subdirectory.
16 # These variables are needed for set up the autoconf other variables.
18 prefix=@prefix@
19 exec_prefix=@exec_prefix@
21 APCPID=@PIDDIR@/apcupsd.pid
22 APCUPSD=@sbindir@/apcupsd
23 SHUTDOWN=@SHUTDOWN@
24 SCRIPTSHELL=@SCRIPTSHELL@
25 SCRIPTDIR=@sysconfdir@
26 WALL=wall
28 # Log notifications using Growl, if available
29 GROWLSEARCH="/usr/bin/growlnotify /usr/local/bin/growlnotify /opt/local/bin/growlnotify"
30 for GROWL in $GROWLSEARCH ; do
31         if [ -x $GROWL ] ; then
32                 WALL="$GROWL -t Apcupsd Notice"
33                 break
34         fi
35 done
38 # Concatenate all output from this script to the events file
39 #  Note, the following kills the script in a power fail situation
40 #   where the disks are mounted read-only.
41 # exec >>@LOGDIR@/apcupsd.events 2>&1
44 # This piece is to substitute the default behaviour with your own script,
45 # perl, or C program.
46 # You can customize every single command creating an executable file (may be a
47 # script or a compiled program) and calling it the same as the $1 parameter
48 # passed by apcupsd to this script.
50 # After executing your script, apccontrol continues with the default action.
51 # If you do not want apccontrol to continue, exit your script with exit 
52 # code 99. E.g. "exit 99".
54 # WARNING: the apccontrol file will be overwritten every time you update your
55 # apcupsd, doing `make install'. Your own customized scripts will _not_ be
56 # overwritten. If you wish to make changes to this file (discouraged), you
57 # should change apccontrol.sh.in and then rerun the configure process.
59 if [ -f ${SCRIPTDIR}/${1} -a -x ${SCRIPTDIR}/${1} ]
60 then
61     ${SCRIPTDIR}/${1} ${2} ${3} ${4}
62     # exit code 99 means he does not want us to do default action
63     if [ $? = 99 ] ; then
64         exit 0
65     fi
68 case "$1" in
69     killpower)
70         echo "Apccontrol doing: ${APCUPSD} --killpower on UPS ${2}"
71         sleep 10
72         ${APCUPSD} --killpower
73         echo "Apccontrol has done: ${APCUPSD} --killpower on UPS ${2}" | ${WALL}
74     ;;
75     commfailure)
76         echo "Communications lost with UPS ${2}" | ${WALL}
77     ;;
78     commok)
79         echo "Communications restored with UPS ${2}" | ${WALL}
80     ;;
82 # powerout, onbattery, offbattery, mainsback events occur
83 #   in that order.
85     powerout)
86     ;;
87     onbattery)
88         echo "Power failure on UPS ${2}. Running on batteries." | ${WALL}
89     ;;
90     offbattery)
91         echo "Power has returned on UPS ${2}..." | ${WALL}
92     ;;
93     mainsback)
94         if [ -f @PWRFAILDIR@/powerfail ] ; then
95            printf "Continuing with shutdown."  | ${WALL}
96         fi
97     ;;
98     failing)
99         echo "Battery power exhaused on UPS ${2}. Doing shutdown." | ${WALL}
100     ;;
101     timeout)
102         echo "Battery time limit exceeded on UPS ${2}. Doing shutdown." | ${WALL}
103     ;;
104     loadlimit)
105         echo "Remaining battery charge below limit on UPS ${2}. Doing shutdown." | ${WALL}
106     ;;
107     runlimit)
108         echo "Remaining battery runtime below limit on UPS ${2}. Doing shutdown." | ${WALL}
109     ;;
110     doreboot)
111         echo "UPS ${2} initiating Reboot Sequence" | ${WALL}
112         ${SHUTDOWN} -r now "apcupsd UPS ${2} initiated reboot"
113     ;;
114     doshutdown)
115         echo "UPS ${2} initiated Shutdown Sequence" | ${WALL}
116         ${SHUTDOWN} -h now "apcupsd UPS ${2} initiated shutdown"
117     ;;
118     annoyme)
119         echo "Power problems with UPS ${2}. Please logoff." | ${WALL}
120     ;;
121     emergency)
122         echo "Emergency Shutdown. Possible battery failure on UPS ${2}." | ${WALL}
123     ;;
124     changeme)
125         echo "Emergency! Batteries have failed on UPS ${2}. Change them NOW" | ${WALL}
126     ;;
127     remotedown)
128         echo "Remote Shutdown. Beginning Shutdown Sequence." | ${WALL}
129     ;;
130     startselftest)
131     ;;
132     endselftest)
133     ;;
134     battdetach)
135     ;;
136     battattach)
137     ;;
138     *)  echo "Usage: ${0##*/} command"
139         echo "       warning: this script is intended to be launched by"
140         echo "       apcupsd and should never be launched by users."
141         exit 1
142     ;;
143 esac