| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# edit these to match your system |
| 4 |
USERNAME=alex |
| 5 |
LOGFILE=/var/log/avicap-boot.log |
| 6 |
AVICAP_DIR=/etc/avicap |
| 7 |
|
| 8 |
# runlevel startup routine taken from Suse's startup scripts |
| 9 |
. /etc/rc.status |
| 10 |
rc_reset |
| 11 |
|
| 12 |
|
| 13 |
echo "avicap-boot: started in runlevel : " ${RUNLEVEL} |
| 14 |
|
| 15 |
check_avicap() |
| 16 |
{ |
| 17 |
if [ "$RUNLEVEL" == "" ] ; then |
| 18 |
RUNLEVEL=3 |
| 19 |
fi |
| 20 |
|
| 21 |
echo "avicap-boot: checking for start or power-off" |
| 22 |
|
| 23 |
mkdir -p $AVICAP_DIR |
| 24 |
|
| 25 |
if test ${RUNLEVEL} == S ; then |
| 26 |
# shutdown again in runlevel S/boot time - no need to boot further |
| 27 |
|
| 28 |
if test -e $AVICAP_DIR/first_shutdown ; then |
| 29 |
echo "avicp-boot: this system was booted to halt" |
| 30 |
echo "avicap-boot: shutdown system" |
| 31 |
echo "avicap-boot: mounting / rw, removing $AVICAP_DIR/first_shutdown" |
| 32 |
mount -o remount,rw / |
| 33 |
sleep 2s |
| 34 |
rm -f $AVICAP_DIR/first_shutdown |
| 35 |
sync |
| 36 |
sleep 2s |
| 37 |
mount -o remount,ro / |
| 38 |
echo "avicap-boot: shutdown to soft-off" |
| 39 |
for i in 10 9 8 7 6 5 4 3 2 1 0 ; do |
| 40 |
echo "countdown $i for avicap-boot to power-off system" |
| 41 |
sleep 1s |
| 42 |
done |
| 43 |
|
| 44 |
sync |
| 45 |
echo "avicap-boot: umounting filesystems" |
| 46 |
sleep 1s |
| 47 |
umount /proc |
| 48 |
sleep 1s |
| 49 |
umount / |
| 50 |
echo "avicap-boot: now doing actual poweroff.." |
| 51 |
sleep 1s |
| 52 |
halt -p -f |
| 53 |
echo "avicap-boot: you should never see me, power-off failed" |
| 54 |
fi |
| 55 |
elif test ${RUNLEVEL} -eq 3 ; then |
| 56 |
# || test ${RUNLEVEL} == "" ; then |
| 57 |
# check if we've to start avicap |
| 58 |
if test -e $AVICAP_DIR/next_recording ; then |
| 59 |
echo "avicap-boot will startup X and avicap -timer" |
| 60 |
echo "==============================" >>$LOGFILE |
| 61 |
( date ; 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 |
echo "avicap-boot: countdown $i for Avicap start" |
| 65 |
sleep 1s |
| 66 |
done |
| 67 |
|
| 68 |
( date ; echo "avicap-boot: startx" ) >>$LOGFILE |
| 69 |
( su -l $USERNAME -c "startx" ) 2>&1 >>$LOGFILE & |
| 70 |
|
| 71 |
sleep 1m |
| 72 |
|
| 73 |
( date ; echo "avicap-boot: kv4lsetup" ) >>$LOGFILE |
| 74 |
export DISPLAY=:0.0 |
| 75 |
chmod u+s /usr/local/bin/kv4lsetup |
| 76 |
/usr/local/bin/kv4lsetup -t=2 2>>$LOGFILE 3>>$LOGFILE 4>>$LOGFILE >>$LOGFILE |
| 77 |
sync |
| 78 |
|
| 79 |
sleep 10s |
| 80 |
|
| 81 |
( date ; echo "avicap-boot: avicap -timer" ) >>$LOGFILE |
| 82 |
( su -l $USERNAME -c "DISPLAY=:0.0 avicap -timer 2>&1 >>$LOGFILE" ) 2>&1 >>$LOGFILE & |
| 83 |
|
| 84 |
sleep 5s |
| 85 |
|
| 86 |
rm -f $AVICAP_DIR/next_recording |
| 87 |
|
| 88 |
sleep 20s |
| 89 |
|
| 90 |
( date ; echo "avicap-boot: avicap-renicer" ) >>$LOGFILE |
| 91 |
/home/alex/sbin/avicap-renicer 2>&1 >>$LOGFILE |
| 92 |
|
| 93 |
unset DISPLAY |
| 94 |
|
| 95 |
( date ; echo "avicap-boot: done" ) >>$LOGFILE |
| 96 |
echo "---------------------------" >>$LOGFILE |
| 97 |
) & |
| 98 |
else |
| 99 |
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 |
echo "avicap-boot: starting..." |
| 112 |
|
| 113 |
check_avicap |
| 114 |
|
| 115 |
rc_status -v |
| 116 |
;; |
| 117 |
stop) |
| 118 |
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 |
echo -n "No status for Avicap" |
| 133 |
rc_status -v |
| 134 |
;; |
| 135 |
*) |
| 136 |
echo "Usage: $0 {start|stop|status|restart|reload|force-reload}" |
| 137 |
exit 1 |
| 138 |
;; |
| 139 |
esac |
| 140 |
rc_exit |