#!/bin/sh
# run hooks for pm-utils
# TODO hybrid-sleep is not handled specially by pm-utils,
# should it be treated like hibernation or suspending?
# TODO user hooks should take precedence over default hooks
# as described in pm-action(8)

case "$1" in
    pre)
	case "$2" in
	    suspend)
		action="suspend"
		;;
	    hibernate)
		action="hibernate"
		;;
	    hybrid-sleep)
		action="suspend"
		;;
	esac
	;;
    post)
	case "$2" in
	    suspend)
		action="resume"
		;;
	    hibernate)
		action="thaw"
		;;
	    hybrid-sleep)
		action="resume"
		;;
	esac
	;;
    *)
	exit 1
esac

hook_dirs="/etc/pm/sleep.d /usr/lib/pm-utils/sleep.d"

for hook_dir in $hook_dirs ; do
    if [ -d "$hook_dir" ] ; then
	/bin/run-parts --arg "$action" "$hook_dir"
    fi
done

exit 0
