xref: /freebsd/usr.sbin/zzz/zzz.sh (revision 6841c2677c5b5e85fd727bfb934efdafd4ccc2bc)
1035e325cSNate Lawson#!/bin/sh
2035e325cSNate Lawson#
3035e325cSNate Lawson# Suspend the system using either ACPI or APM.
4035e325cSNate Lawson# For APM, "apm -z" will be issued.
5035e325cSNate Lawson# For ACPI, the configured suspend state will be looked up, checked to see
6035e325cSNate Lawson# if it is supported, and "acpiconf -s <state>" will be issued.
7035e325cSNate Lawson#
8035e325cSNate Lawson# Mark Santcroos <marks@ripe.net>
9035e325cSNate Lawson#
10035e325cSNate Lawson
11035e325cSNate LawsonPATH=/sbin:/usr/sbin:/usr/bin:/bin
12035e325cSNate Lawson
13035e325cSNate LawsonACPI_SUSPEND_STATE=hw.acpi.suspend_state
14035e325cSNate LawsonACPI_SUPPORTED_STATES=hw.acpi.supported_sleep_state
15035e325cSNate LawsonAPM_SUSPEND_DELAY=machdep.apm_suspend_delay
16035e325cSNate Lawson
17035e325cSNate Lawson# Check for ACPI support
18035e325cSNate Lawsonif sysctl $ACPI_SUSPEND_STATE >/dev/null 2>&1; then
19035e325cSNate Lawson	# Get configured suspend state
207776cec9SBenedict Reuschling	SUSPEND_STATE=$(sysctl -n $ACPI_SUSPEND_STATE)
21035e325cSNate Lawson
22035e325cSNate Lawson	# Get list of supported suspend states
237776cec9SBenedict Reuschling	SUPPORTED_STATES=$(sysctl -n $ACPI_SUPPORTED_STATES)
24035e325cSNate Lawson
25035e325cSNate Lawson	# Check if the configured suspend state is supported by the system
267776cec9SBenedict Reuschling	if echo "$SUPPORTED_STATES" | grep "$SUSPEND_STATE" >/dev/null; then
27035e325cSNate Lawson		# execute ACPI style suspend command
287776cec9SBenedict Reuschling		exec acpiconf -s "$SUSPEND_STATE"
29035e325cSNate Lawson	else
30*6841c267SOleksandr Kryvulia		echo "Requested suspend state $SUSPEND_STATE is not supported."
31c6c051e5SNate Lawson		echo "Supported states: $SUPPORTED_STATES"
32035e325cSNate Lawson	fi
33035e325cSNate Lawson# Check for APM support
34035e325cSNate Lawsonelif sysctl $APM_SUSPEND_DELAY >/dev/null 2>&1; then
35035e325cSNate Lawson	# Execute APM style suspend command
36035e325cSNate Lawson	exec apm -z
37035e325cSNate Lawsonelse
38035e325cSNate Lawson	echo "Error: no ACPI or APM suspend support found."
39035e325cSNate Lawsonfi
40035e325cSNate Lawson
41035e325cSNate Lawsonexit 1
42