webif/webif/lib/bin/reboot

147 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
#exec >>/tmp/reboot.log 2>&1
if [ "$1" = "-f" -a "$0" != "/tmp/fastreboot" ]; then
cp "$0" /tmp/fastreboot
chmod 755 /tmp/fastreboot
exec /tmp/fastreboot -f
exit 0
fi
model=$(cat /etc/model)
feedback()
{
[ -x /mod/bin/hwctl ] && /mod/bin/hwctl 13 0 >> /dev/null 2>&1
if [ "$model" = HDR ]; then display "$1"; else display "\$$2"; fi
}
readwakeup()
{
# Read the wakeup timer from the front panel
tries=10
while [ $tries -gt 0 ]; do
wakeup=$(/mod/bin/hwctl d)
[ -n "$wakeup" ] && break
tries=$((tries - 1))
sleep 1
done
echo "Wakeup: $wakeup"
}
setwakeup()
{
tries=10
while [ $tries -gt 0 ]; do
echo "Setting wakeup timer..."
/mod/bin/hwctl 5 1 "^$(date +%s)" >/dev/null
tries=$((tries - 1))
if readwakeup | grep "00 00 00 00"; then
sleep 1
continue
fi
echo "Success"
break
done
}
lbr=0
if [ -f /tmp/.lbr ]; then
lbr=$(cat /tmp/.lbr)
#echo "LBR: $lbr"
else
# No last-boot-reason file, fall-back to reading timer directly.
echo "No .lbr, falling back to timer..."
if readwakeup | grep "00 00 00 00"; then
echo "Setting LBR=3"
lbr=3
fi
fi
if [ $lbr -eq 3 ]; then
# Last boot was for scheduled recording. Need to set a wakeup
# flag in the Micom or the reboot will result in the Humax
# software just powering down (it presumably think that there has
# been a power failure).
readwakeup # For interest
setwakeup
readwakeup
fi
# Normal reboot.
if [ "$1" != "-f" ]; then
feedback "Reboot..." "REBT"
/etc/init.d/S90settop shut
/bin/sync
/sbin/reboot
exit 0
fi
######################################################################
# Fast reboot, thanks to work by prpr
feedback "Fast Reboot" "FRBT"
# Stop mod services
ls -1r /mod/etc/init.d/S??* |
while read -r f; do
[ -f "$f" ] || continue
case $f in
*.sh)
# actually no such scripts
continue
(
trap - INT QUIT TSTP
set -- stop
# might not use $1 ?
. "$f"
)
;;
*)
# Don't stop the SSH server
echo "$f" | grep -q dropbear && continue
[ -x "$f" ] && "$f" stop
;;
esac
done
# Stop Humax App
/etc/init.d/S90settop shut
# Kill DHCP daemon
killall udhcpc
# Stop any processes still using the disk
#sleep 1
#[ "$model" = "HDR" ] && part=/mnt/hd2 || part=/media/drive1
#lsof -t $part | xargs kill -9
# Unmount disks
/bin/sync
mount | grep '^/dev/sd' |
{ lastdev=
while read -r dev _; do
[ "${lastdev:-}" = "$dev" ] && continue
umount -l "$dev"; lastdev=$dev
done; }
# Stop device
for f in /sys/block/sd?; do
echo 1 >> "$f/device/delete"
done
feedback "START SYSTEM" "boot"
# Restart xinit modules
/etc/init.d/S80xinit start
# Restart Humax app
/etc/init.d/S90settop resume
exit 0