Home | History | Annotate | Line # | Download | only in scripts
      1 #!/bin/sh -
      2 #
      3 #	$NetBSD: sleep_button,v 1.9 2011/09/17 14:44:18 jym Exp $
      4 #
      5 # Generic script for sleep button events.
      6 #
      7 # Arguments passed by powerd(8):
      8 #
      9 #	device event
     10 
     11 case "${2}" in
     12 pressed)
     13 
     14 	/etc/rc.d/bluetooth stop
     15 	/etc/rc.d/ntpd stop
     16 	/etc/rc.d/dhclient stop
     17 	/etc/rc.d/network stop
     18 	/etc/rc.d/wpa_supplicant stop
     19 
     20 	if /sbin/sysctl -q hw.acpi.sleep.state; then
     21 		/sbin/sysctl -w hw.acpi.sleep.state=3
     22 	elif /sbin/sysctl -q machdep.xen.suspend; then
     23 		/sbin/sysctl -w machdep.xen.suspend=1
     24 	else
     25 		sleep 1
     26 		if /etc/rc.d/apmd onestatus >/dev/null ; then
     27 			/usr/sbin/apm -z
     28 		else
     29 			/usr/sbin/apm -d -z
     30 		fi
     31 		# ... waking up
     32 		sleep 1
     33 	fi
     34 
     35 	/etc/rc.d/wpa_supplicant start
     36 	/etc/rc.d/network start
     37 	/etc/rc.d/dhclient start
     38 	/etc/rc.d/ntpdate start
     39 	/etc/rc.d/ntpd start
     40 	/etc/rc.d/bluetooth start
     41 	;;
     42 
     43 released)
     44 	case "${1}" in
     45 	vmt0)
     46 		# Virtual machine is resuming, restart the network
     47 		/etc/rc.d/dhcpcd restart
     48 		;;
     49 	esac
     50 	;;
     51 *)
     52 	logger -p warning "${0}: unsupported event ${2} on device ${1}" >&1
     53 	exit 1
     54 	;;
     55 esac
     56