updated on Tue Jan 10 00:10:07 UTC 2012
[aur-mirror.git] / hibernate-script / hibernate.rc
blob6a326a303bb8c056615f4a99f0de1a355c0e3a8c
1 #!/bin/sh
3 . /etc/rc.conf
4 . /etc/rc.d/functions
6 # This script invalidates any stale swsusp and Software Suspend 2 images. It
7 # searches all swap partitions on your machine, as well as Suspend2's
8 # filewriter files (by way of the hibernate script telling it where to find
9 # it).
11 # It should be called on boot, after mounting filesystems, but before enabling
12 # swap or clearing out /var/run. Copy this into /etc/init.d/ (or the appropriate
13 # place on your system), then add a symlink at the appropriate point on boot.
14 # On a Debian system, you would do this:
15 # update-rc.d hibernate-cleanup.sh start 31 S .
17 # On other SysV-based systems, you would do something like:
18 # ln -s ../init.d/hibernate-cleanup.sh /etc/rcS.d/S31hibernate-cleanup.sh
20 HIBERNATE_FILEWRITER_TRAIL="/var/run/suspend2_filewriter_image_exists"
22 clear_swap() {
23 local where wason
24 where=$1
25 wason=
26 swapoff $where 2>/dev/null && wason=yes
27 mkswap $where > /dev/null || stat_append " (failed: $?)"
28 [ -n "$wason" ] && swapon $where
31 check_swap_sig() {
32 local where what type rest p c
33 while read where what type rest ; do
34 test "$type" = "swap" || continue
35 case "$(dd if=$where bs=1 count=6 skip=4086 2>/dev/null)" in
36 S1SUSP|S2SUSP|ULSUSP|pmdisk|[zZ]*)
37 stat_append "$where"
38 clear_swap $where
39 stat_append ", "
40 esac
41 done < /etc/fstab
44 check_filewriter_sig() {
45 local target
46 [ -f "$HIBERNATE_FILEWRITER_TRAIL" ] || return 0
47 read target < $HIBERNATE_FILEWRITER_TRAIL
48 [ -f "$target" ] || return
49 case "`dd \"if=$target\" bs=8 count=1 2>/dev/null`" in
50 HaveImag)
51 /bin/echo -ne "Suspend2\n\0\0" | dd "of=$target" bs=11 count=1 conv=notrunc 2>/dev/null
52 stat_append -n "$target, "
53 rm -f $HIBERNATE_FILEWRITER_TRAIL
54 esac
57 case "$1" in
58 start)
59 stat_busy "Invalidating stale software suspend images... "
60 check_swap_sig
61 check_filewriter_sig
62 stat_done
64 stop)
67 echo "Usage: $0 {start|stop}"
68 esac