#!/bin/sh
# -*- Mode: shell-script -*-
# Copyright (C) 2003-2005 by Mandriva
# Author: Chmouel Boudjnah
# Redistribution of this file is permitted under the terms of the GNU 
# Public License (GPL)

debug=

. /etc/sysconfig/suspend

[ -n "$debug" ] && debug="-d"

while getopts d opt
  do
  case "$opt" in
      d) debug="-d";;
  esac
done
shift $((OPTIND - 1))

ACTION=$1

if [ -z "$ACTION" ]; then
    cat <<EOF
Usage: $0 ACTION

Suspend to memory: 
  $0 [memory|ram|suspend]
Suspend to disk:
  $0 [disk|hibernate]
EOF
    exit 1
fi

if [[ -e /sys/power/state || -n $SWSUSP_FORCE_SUSPEND_MODE ]];then
    . /usr/share/suspend-scripts/swsusp.functions
    case $ACTION in
	memory|ram|suspend)
	    suspend_to_ram $debug;;
	disk|hibernate)
	    suspend_to_disk $debug;;
	*)
	    echo "$ACTION is not supported in SWSUSP mode";;
    esac
elif [[ -e /proc/apm ]];then
    case $ACTION in
	memory|ram|suspend)
	    apm -s;;
	*)
	    echo "$ACTION is not supported in APM mode";;
    esac
fi
