acadapter revision 1.1
11.1Sjmcneill#!/bin/sh -
21.1Sjmcneill#
31.1Sjmcneill#	$NetBSD: acadapter,v 1.1 2006/09/26 02:17:38 jmcneill Exp $
41.1Sjmcneill#
51.1Sjmcneill# Generic script for acadapter events.
61.1Sjmcneill#
71.1Sjmcneill# Arguments passed by powerd(8):
81.1Sjmcneill#
91.1Sjmcneill#	device event
101.1Sjmcneill
111.1Sjmcneillcase "${2}" in
121.1Sjmcneillpressed)
131.1Sjmcneill	logger -p info "${0}: Full performance mode" >&1
141.1Sjmcneill	# The following turns up brightness on a Sony Vaio laptop
151.1Sjmcneill	/sbin/sysctl -w hw.sony0.brt=8 >/dev/null 2>&1
161.1Sjmcneill	# Enable full performance mode for speedstep CPUs
171.1Sjmcneill	/sbin/sysctl -w machdep.speedstep_state=1 2>&1
181.1Sjmcneill	# Disable power saving mode on all network interfaces
191.1Sjmcneill	for intf in /sbin/ifconfig -l; do
201.1Sjmcneill		/sbin/ifconfig $intf -powersave >/dev/null 2>&1
211.1Sjmcneill	done
221.1Sjmcneill
231.1Sjmcneill	#
241.1Sjmcneill	# If you want to keep your hard disk idle while running on
251.1Sjmcneill	# battery, the following commands will help.
261.1Sjmcneill	#
271.1Sjmcneill
281.1Sjmcneill	# Disk idle timeouts
291.1Sjmcneill	#/sbin/atactl wd0 setidle 300
301.1Sjmcneill	#/sbin/atactl wd0 setstandby 600
311.1Sjmcneill	# Make sure syslogd is running
321.1Sjmcneill	#pkill syslogd
331.1Sjmcneill	#/etc/rc.d/syslogd start
341.1Sjmcneill	# Startup cron daemon when running on power
351.1Sjmcneill	#/etc/rc.d/cron start
361.1Sjmcneill
371.1Sjmcneill	# All finished
381.1Sjmcneill	exit 0
391.1Sjmcneill	;;
401.1Sjmcneill
411.1Sjmcneillreleased)
421.1Sjmcneill	logger -p info "${0}: Power saving mode" >&1
431.1Sjmcneill	# The following turns down brightness on a Sony Vaio laptop
441.1Sjmcneill	/sbin/sysctl -w hw.sony0.brt=0 >/dev/null 2>&1
451.1Sjmcneill	# Enable power saving mode for speedstep CPUs
461.1Sjmcneill	/sbin/sysctl -w machdep.speedstep_state=0 >/dev/null 2>&1
471.1Sjmcneill
481.1Sjmcneill	# Disable power saving mode on all network interfaces
491.1Sjmcneill	for intf in /sbin/ifconfig -l; do
501.1Sjmcneill		/sbin/ifconfig $intf powersave >/dev/null 2>&1
511.1Sjmcneill	done
521.1Sjmcneill
531.1Sjmcneill	#
541.1Sjmcneill	# When running on battery, we want to keep the disk idle for as long
551.1Sjmcneill	# as possible. Unfortunately, things like cron and syslog make this
561.1Sjmcneill	# very difficult. If you can live without cron or persistent logging,
571.1Sjmcneill	# you can use the commands below to disable cron and syslogd.
581.1Sjmcneill	#
591.1Sjmcneill	# If you still want to see syslog messages, you can create a custom
601.1Sjmcneill	# /etc/syslog.conf.battery that writes messages to /dev/console or
611.1Sjmcneill	# possibly a free wsdisplay screen.
621.1Sjmcneill	#
631.1Sjmcneill
641.1Sjmcneill	# Disk idle timeouts
651.1Sjmcneill	#/sbin/atactl wd0 setidle 30
661.1Sjmcneill	#/sbin/atactl wd0 setstandby 120
671.1Sjmcneill	
681.1Sjmcneill	# Stop the cron daemon
691.1Sjmcneill	#/etc/rc.d/cron stop
701.1Sjmcneill
711.1Sjmcneill	# Restart syslogd using a diskless configuration
721.1Sjmcneill	#pkill syslogd
731.1Sjmcneill	#/usr/sbin/syslogd -s -f /etc/syslog.conf.battery
741.1Sjmcneill
751.1Sjmcneill	# All finished
761.1Sjmcneill	exit 0
771.1Sjmcneill	;;
781.1Sjmcneill
791.1Sjmcneill*)
801.1Sjmcneill	logger -p warning "${0}: unsupported event ${2} on device ${1}" >&1
811.1Sjmcneill	exit 1
821.1Sjmcneill	;;
831.1Sjmcneillesac
84