11.1Sjmcneill#!/bin/sh -
21.1Sjmcneill#
31.4Sjruoho#	$NetBSD: acadapter,v 1.4 2010/12/31 09:29:43 jruoho 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.4Sjruoho
151.4Sjruoho	# Disable power saving mode on all network interfaces.
161.4Sjruoho	#
171.3Spgoyette	for intf in $(/sbin/ifconfig -l); do
181.1Sjmcneill		/sbin/ifconfig $intf -powersave >/dev/null 2>&1
191.1Sjmcneill	done
201.1Sjmcneill
211.4Sjruoho	# If you want to keep your hard disk idle while running
221.4Sjruoho	# on battery, the following commands will help.
231.1Sjmcneill	#
241.4Sjruoho	# /sbin/atactl wd0 setidle 300
251.4Sjruoho	# /sbin/atactl wd0 setstandby 600
261.4Sjruoho
271.4Sjruoho	# Make sure syslogd is running.
281.1Sjmcneill	#
291.4Sjruoho	# pkill syslogd
301.4Sjruoho	# /etc/rc.d/syslogd start
311.1Sjmcneill
321.4Sjruoho	# Start cron daemon when running on power.
331.4Sjruoho	#
341.4Sjruoho	# /etc/rc.d/cron start
351.1Sjmcneill
361.1Sjmcneill	exit 0
371.1Sjmcneill	;;
381.1Sjmcneill
391.1Sjmcneillreleased)
401.1Sjmcneill	logger -p info "${0}: Power saving mode" >&1
411.1Sjmcneill
421.4Sjruoho	# Enable power saving mode on all network interfaces.
431.4Sjruoho	#
441.3Spgoyette	for intf in $(/sbin/ifconfig -l); do
451.1Sjmcneill		/sbin/ifconfig $intf powersave >/dev/null 2>&1
461.1Sjmcneill	done
471.1Sjmcneill
481.1Sjmcneill	# When running on battery, we want to keep the disk idle for as long
491.1Sjmcneill	# as possible. Unfortunately, things like cron and syslog make this
501.1Sjmcneill	# very difficult. If you can live without cron or persistent logging,
511.1Sjmcneill	# you can use the commands below to disable cron and syslogd.
521.1Sjmcneill	#
531.1Sjmcneill	# If you still want to see syslog messages, you can create a custom
541.1Sjmcneill	# /etc/syslog.conf.battery that writes messages to /dev/console or
551.4Sjruoho	# possibly a free wsdisplay screen. Alternatively, /var/log could
561.4Sjruoho	# be mounted as tmpfs.
571.4Sjruoho
581.4Sjruoho	# Disk idle timeouts.
591.1Sjmcneill	#
601.4Sjruoho	# /sbin/atactl wd0 setidle 30
611.4Sjruoho	# /sbin/atactl wd0 setstandby 120
621.1Sjmcneill
631.4Sjruoho	# Stop the cron daemon.
641.4Sjruoho	#
651.4Sjruoho	# /etc/rc.d/cron stop
661.1Sjmcneill
671.4Sjruoho	# Restart syslogd using a diskless configuration.
681.4Sjruoho	#
691.4Sjruoho	# pkill syslogd
701.4Sjruoho	# /usr/sbin/syslogd -s -f /etc/syslog.conf.battery
711.1Sjmcneill
721.1Sjmcneill	exit 0
731.1Sjmcneill	;;
741.1Sjmcneill
751.1Sjmcneill*)
761.1Sjmcneill	logger -p warning "${0}: unsupported event ${2} on device ${1}" >&1
771.1Sjmcneill	exit 1
781.1Sjmcneill	;;
791.1Sjmcneillesac
80