Debian Codegraph @

VDR/vdrshutdown

raw
1 #!/bin/bash
2 # $Id: vdrshutdown 773 2004-08-23 01:22:35Z bistr-o-math $
3
4 NVRAMCMD=/usr/local/bin/nvram-wakeup
5 SVDRPCMD=/usr/local/src/VDR/svdrpsend.pl
6 LOGGER=/bin/logger
7 CHECKSCRIPT=/path/to/the/script
8
9 #################
10 ## if the script $CHECKSCRIPT thinks that we should shutdown,
11 ## it must not print anything on stdout.
12 ## if it thinks that we should NOT shutdown,
13 ## it must print a one-line message on stdout describing the reason.
14 ##
15 ## note that all parameters passed to vdrshutdown will also be passed to $CHECKSCRIPT
16 ## so it might use them (e.g. $5 -eq 0 below)
17 ##
18 ## it might look like this:
19 ## --------------------------
20 ## #!/bin/bash
21 ##
22 ## pgrep 2divx >/dev/null 2>&1 && { echo Divx-Conversion is still running; exit; }
23 ##
24 ## test -a /some/file && { echo /some/file exists; exit; }
25 ##
26 ## USERCOUNT=`who | wc -l`;
27 ## test $5 -eq 0 -a $USERCOUNT -gt 0 && { echo "$USERCOUNT users are logged in."; exit; }
28 ##
29 ## --------------------------
30 ##
31 ## now if $CHECKSCRIPT exists and is executable, the message will be passed through
32 ## SVDRP to the tv screen.
33 ##
34
35 test -x $CHECKSCRIPT && {
36 msg=`$CHECKSCRIPT "$@"`
37 test "$msg" != "" && {
38 $SVDRPCMD MESG $msg &
39 $LOGGER -t `basename $0` "shutdown aborted: $msg"
40 exit 1
41 }
42 }
43
44 #################
45
46 # Add here needed options like --configfile=...
47 # (read 'man nvram-wakeup' and 'man nvram-wakeup.conf' for more details)
48 $NVRAMCMD --syslog --settime $1
49
50 # if you are going to use the set_timer script instead of nvram-wakeup,
51 # comment out the line above and uncomment the following line.
52 # (read the comments inside the script for more details)
53 # $PATH_TO_SET_TIMER/set_timer $1 $2
54
55
56 case $PIPESTATUS in
57 0) # all went ok - new date and time set
58 shutdown -h now
59 EXITSTATUS=0
60 ;;
61 1) # all went ok - new date and time set.
62 #
63 # *** but we need to reboot. ***
64 #
65 # for some boards this is needed after every change.
66 #
67 # for some other boards, we only need this after changing the
68 # status flag, i.e. from enabled to disabled or the other way.
69
70
71 # For plan A - (Plan A is not supported anymore---see README)
72 #
73 # For plan B - (don't forget to install the modified kernel image first)
74 #
75
76 lilo -R PowerOff
77
78 shutdown -r now
79 EXITSTATUS=0
80 ;;
81 2) # something went wrong
82 # don't do anything - just exit with status 1
83 EXITSTATUS=1
84 ;;
85 esac
86
87 # exit with 0 if everything went ok.
88 # exit with 1 if something went wrong.
89 exit $EXITSTATUS