| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # edit these to match your system |
| 4 | USERNAME=alex |
| 5 | LOGFILE=/var/log/avicap-boot.logscip-shell filesystem . . `/var/log/avicap-boot.log`. |
| 6 | AVICAP_DIR=/etc/avicapscip-shell filesystem . . `/etc/avicap`. |
| 7 | |
| 8 | # runlevel startup routine taken from Suse's startup scripts |
| 9 | . /etc/rc.statusscip-shell source . . `/etc/rc.status`. |
| 10 | rc_reset |
| 11 | |
| 12 | |
| 13 | echoscip-shell system . . echo. "avicap-boot: started in runlevel : " ${RUNLEVEL} |
| 14 | |
| 15 | check_avicapscip-shell shell avifile 1:0.7.48~20090503.ds-32 check_avicap().() |
| 16 | { |
| 17 | if [scip-shell system . . `[`. "$RUNLEVEL" == "" ] ; then |
| 18 | RUNLEVEL=3 |
| 19 | fi |
| 20 | |
| 21 | echoscip-shell system . . echo. "avicap-boot: checking for start or power-off" |
| 22 | |
| 23 | mkdirscip-shell system . . mkdir. -p $AVICAP_DIR |
| 24 | |
| 25 | if testscip-shell system . . test. ${RUNLEVEL} == S ; then |
| 26 | # shutdown again in runlevel S/boot time - no need to boot further |
| 27 | |
| 28 | if testscip-shell system . . test. -e $AVICAP_DIR/first_shutdown ; then |
| 29 | echoscip-shell system . . echo. "avicp-boot: this system was booted to halt" |
| 30 | echoscip-shell system . . echo. "avicap-boot: shutdown system" |
| 31 | echoscip-shell system . . echo. "avicap-boot: mounting / rw, removing $AVICAP_DIR/first_shutdown" |
| 32 | mountscip-shell system . . mount. -o remount,rw /scip-shell filesystem . . `/`. |
| 33 | sleepscip-shell system . . sleep. 2s |
| 34 | rmscip-shell system . . rm. -f $AVICAP_DIR/first_shutdown |
| 35 | syncscip-shell system . . sync. |
| 36 | sleepscip-shell system . . sleep. 2s |
| 37 | mountscip-shell system . . mount. -o remount,ro /scip-shell filesystem . . `/`. |
| 38 | echoscip-shell system . . echo. "avicap-boot: shutdown to soft-off" |
| 39 | for i in 10 9 8 7 6 5 4 3 2 1 0 ; do |
| 40 | echoscip-shell system . . echo. "countdown $i for avicap-boot to power-off system" |
| 41 | sleepscip-shell system . . sleep. 1s |
| 42 | done |
| 43 | |
| 44 | syncscip-shell system . . sync. |
| 45 | echoscip-shell system . . echo. "avicap-boot: umounting filesystems" |
| 46 | sleepscip-shell system . . sleep. 1s |
| 47 | umountscip-shell system . . umount. /procscip-shell filesystem . . `/proc`. |
| 48 | sleepscip-shell system . . sleep. 1s |
| 49 | umountscip-shell system . . umount. /scip-shell filesystem . . `/`. |
| 50 | echoscip-shell system . . echo. "avicap-boot: now doing actual poweroff.." |
| 51 | sleepscip-shell system . . sleep. 1s |
| 52 | halt -p -f |
| 53 | echoscip-shell system . . echo. "avicap-boot: you should never see me, power-off failed" |
| 54 | fi |
| 55 | elif testscip-shell system . . test. ${RUNLEVEL} -eq 3 ; then |
| 56 | # || test ${RUNLEVEL} == "" ; then |
| 57 | # check if we've to start avicap |
| 58 | if testscip-shell system . . test. -e $AVICAP_DIR/next_recording ; then |
| 59 | echoscip-shell system . . echo. "avicap-boot will startup X and avicap -timer" |
| 60 | echoscip-shell system . . echo. "==============================" >>$LOGFILE |
| 61 | ( datescip-shell system . . date. ; echoscip-shell system . . echo. "avicap-boot: starting X/avicap" ) >>$LOGFILE |
| 62 | ( |
| 63 | for i in 10 9 8 7 6 5 4 3 2 1 0 ; do |
| 64 | echoscip-shell system . . echo. "avicap-boot: countdown $i for Avicap start" |
| 65 | sleepscip-shell system . . sleep. 1s |
| 66 | done |
| 67 | |
| 68 | ( datescip-shell system . . date. ; echoscip-shell system . . echo. "avicap-boot: startx" ) >>$LOGFILE |
| 69 | ( suscip-shell system . . su. -l $USERNAME -c "startx" ) 2>&1 >>$LOGFILE & |
| 70 | |
| 71 | sleepscip-shell system . . sleep. 1m |
| 72 | |
| 73 | ( datescip-shell system . . date. ; echoscip-shell system . . echo. "avicap-boot: kv4lsetup" ) >>$LOGFILE |
| 74 | export DISPLAY=:0.0 |
| 75 | chmodscip-shell system . . chmod. u+s /usr/local/bin/kv4lsetupscip-shell filesystem . . `/usr/local/bin/kv4lsetup`. |
| 76 | /usr/local/bin/kv4lsetupscip-shell filesystem . . `/usr/local/bin/kv4lsetup`. -t=2 2>>$LOGFILE 3>>$LOGFILE 4>>$LOGFILE >>$LOGFILE |
| 77 | syncscip-shell system . . sync. |
| 78 | |
| 79 | sleepscip-shell system . . sleep. 10s |
| 80 | |
| 81 | ( datescip-shell system . . date. ; echoscip-shell system . . echo. "avicap-boot: avicap -timer" ) >>$LOGFILE |
| 82 | ( suscip-shell system . . su. -l $USERNAME -c "DISPLAY=:0.0 avicap -timer 2>&1 >>$LOGFILE" ) 2>&1 >>$LOGFILE & |
| 83 | |
| 84 | sleepscip-shell system . . sleep. 5s |
| 85 | |
| 86 | rmscip-shell system . . rm. -f $AVICAP_DIR/next_recording |
| 87 | |
| 88 | sleepscip-shell system . . sleep. 20s |
| 89 | |
| 90 | ( datescip-shell system . . date. ; echoscip-shell system . . echo. "avicap-boot: avicap-renicer" ) >>$LOGFILE |
| 91 | /home/alex/sbin/avicap-renicerscip-shell filesystem . . `/home/alex/sbin/avicap-renicer`. 2>&1 >>$LOGFILE |
| 92 | |
| 93 | unset DISPLAY |
| 94 | |
| 95 | ( datescip-shell system . . date. ; echoscip-shell system . . echo. "avicap-boot: done" ) >>$LOGFILE |
| 96 | echoscip-shell system . . echo. "---------------------------" >>$LOGFILE |
| 97 | ) & |
| 98 | else |
| 99 | echoscip-shell system . . echo. "avicap-boot: normal booting, no pending recordings" |
| 100 | fi |
| 101 | fi |
| 102 | |
| 103 | } |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | case "$1" in |
| 110 | start) |
| 111 | echoscip-shell system . . echo. "avicap-boot: starting..." |
| 112 | |
| 113 | check_avicapscip-shell shell avifile 1:0.7.48~20090503.ds-32 check_avicap(). |
| 114 | |
| 115 | rc_status -v |
| 116 | ;; |
| 117 | stop) |
| 118 | echoscip-shell system . . echo. -n "Nothing to stop for Avicap" |
| 119 | |
| 120 | rc_status -v |
| 121 | ;; |
| 122 | restart) |
| 123 | ## If first returns OK call the second, if first or |
| 124 | ## second command fails, set echo return value. |
| 125 | $0 stop |
| 126 | $0 start |
| 127 | |
| 128 | # Remember status and be quiet |
| 129 | rc_status |
| 130 | ;; |
| 131 | status) |
| 132 | echoscip-shell system . . echo. -n "No status for Avicap" |
| 133 | rc_status -v |
| 134 | ;; |
| 135 | *) |
| 136 | echoscip-shell system . . echo. "Usage: $0 {start|stop|status|restart|reload|force-reload}" |
| 137 | exit 1 |
| 138 | ;; |
| 139 | esac |
| 140 | rc_exit |