#!/bin/sh
#===============================================================================
#
#  suspend
#
#  Copyright (C) 2009-2014 by Digi International Inc.
#  All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License version 2 as published by
#  the Free Software Foundation.
#
#
#  !Description: suspend system to RAM
#
#===============================================================================

scriptname="$(basename ${0})"
syspower="/sys/power/state"

usage() {
	printf "\nSuspend system to RAM memory\n"
	printf "\nUsage: ${scriptname} [OPTIONS]\n
	-h      Show this help
	\n"
}

while getopts "h" c; do
	case "${c}" in
		h) usage; exit;;
	esac
done

if [ -f "${syspower}" ]; then
	# Pre-suspend actions

	# Suspend the device
	printf "mem" > ${syspower}
	sleep .5

	# Post-resume actions
else
	printf "\n[ERROR] File ${syspower} not found\n\n"
fi
