mirror of
https://github.com/archlinuxarm/PKGBUILDs.git
synced 2024-11-28 22:57:37 +00:00
68 lines
1.9 KiB
Bash
68 lines
1.9 KiB
Bash
#!/bin/sh
|
|
|
|
. /etc/rc.conf
|
|
. /etc/rc.d/functions
|
|
|
|
# This script invalidates any stale swsusp and Software Suspend 2 images. It
|
|
# searches all swap partitions on your machine, as well as Suspend2's
|
|
# filewriter files (by way of the hibernate script telling it where to find
|
|
# it).
|
|
#
|
|
# It should be called on boot, after mounting filesystems, but before enabling
|
|
# swap or clearing out /var/run. Copy this into /etc/init.d/ (or the appropriate
|
|
# place on your system), then add a symlink at the appropriate point on boot.
|
|
# On a Debian system, you would do this:
|
|
# update-rc.d hibernate-cleanup.sh start 31 S .
|
|
#
|
|
# On other SysV-based systems, you would do something like:
|
|
# ln -s ../init.d/hibernate-cleanup.sh /etc/rcS.d/S31hibernate-cleanup.sh
|
|
|
|
HIBERNATE_FILEWRITER_TRAIL="/var/run/suspend2_filewriter_image_exists"
|
|
|
|
clear_swap() {
|
|
local where wason
|
|
where=$1
|
|
wason=
|
|
swapoff $where 2>/dev/null && wason=yes
|
|
mkswap $where > /dev/null || stat_append " (failed: $?)"
|
|
[ -n "$wason" ] && swapon $where
|
|
}
|
|
|
|
check_swap_sig() {
|
|
local where what type rest p c
|
|
while read where what type rest ; do
|
|
test "$type" = "swap" || continue
|
|
case "$(dd if=$where bs=1 count=6 skip=4086 2>/dev/null)" in
|
|
S1SUSP|S2SUSP|ULSUSP|pmdisk|[zZ]*)
|
|
stat_append "$where"
|
|
clear_swap $where
|
|
stat_append ", "
|
|
esac
|
|
done < /etc/fstab
|
|
}
|
|
|
|
check_filewriter_sig() {
|
|
local target
|
|
[ -f "$HIBERNATE_FILEWRITER_TRAIL" ] || return 0
|
|
read target < $HIBERNATE_FILEWRITER_TRAIL
|
|
[ -f "$target" ] || return
|
|
case "`dd \"if=$target\" bs=8 count=1 2>/dev/null`" in
|
|
HaveImag)
|
|
/bin/echo -ne "Suspend2\n\0\0" | dd "of=$target" bs=11 count=1 conv=notrunc 2>/dev/null
|
|
stat_append -n "$target, "
|
|
rm -f $HIBERNATE_FILEWRITER_TRAIL
|
|
esac
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
stat_busy "Invalidating stale software suspend images... "
|
|
check_swap_sig
|
|
check_filewriter_sig
|
|
stat_done
|
|
;;
|
|
stop)
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop}"
|
|
esac
|