#!/bin/bash
# -*- Mode: shell-script -*-
# Copyright (C) 2003 by MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com>
# Redistribution of this file is permitted under the terms of the GNU 
# Public License (GPL)
#
# suspend: 20
# resume: 10
# resume-second: 50
#

. /etc/sysconfig/suspend

ARG=$1
MOD=$2

function suspend {
    if [ "$MOD" != "s4" ]; then
	exit;
    fi
    BOOT_IMAGE=`sed -e "s/.*BOOT_IMAGE=\(\S*\).*/\1/" /proc/cmdline`
    REBOOTIN="/usr/sbin/rebootin"
    if [ -z "$BOOT_IMAGE" ];then
	 echo "Can't determine lilo boot entry";
	 exit;
    fi
    if [ ! -x $REBOOTIN ]; then
	 echo "rebootin binary not executable or not found";
	 exit;
    fi
    if ! ($REBOOTIN -n $BOOT_IMAGE 2>/dev/null ); then
	 echo "*** Unable to find lilo boot entry $BOOT_IMAGE in lilo.conf. ***"
	 echo "*** You have to resume with the kernel you're using currently ***"
	 echo "*** otherwise, you won't be able to resume this session ***"
    fi;
}

case $ARG in
    suspend)
	suspend
	;;
esac
