summaryrefslogtreecommitdiff
blob: 0ca95dc24bac3773f5b9af35df4d6aebedab7cd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/sys-apps/speedfreq/files/speedfreq.rc,v 1.4 2004/02/25 13:46:58 tantive Exp $

depend() {
	need modules logger
	use acpid
}

check_battery() {
	[ "${SPEEDFREQ_SPEED}" == "auto" ] || return 0

	local status=""
	if [ -e /proc/acpi/battery/BAT1/state ] ; then
		status="$(awk '/^charging/ {print $NF}' /proc/acpi/battery/BAT1/state)"
	elif [ -e /proc/pmu/info ] ; then
		status="$(awk '/^AC Power/ {print $NF}' /proc/pmu/info)"
		[ ${status} -eq 1 ] \
			&& status="charging" \
			|| status="discharging"
	fi

	case ${status} in
		charging)		SPEEDFREQ_SPEED=performance;;
		discharging)	SPEEDFREQ_SPEED=powersave;;
		*)				SPEEDFREQ_SPEED=performance;;
	esac
	return 0
}

start() {
	check_battery

	ebegin "Starting speedfreq"
	/usr/sbin/speedfreqd -P /var/run/speedfreq.pid -p ${SPEEDFREQ_SPEED} ${SPEEDFREQ_OPTS}
	eend $?
}

stop() {
	ebegin "Stopping speedfreq"
	if [ -e /var/run/speedfreq.pid ] ; then
		local pid="$(</var/run/speedfreq.pid)"
		kill ${pid} >& /dev/null
		eend $? "Could not kill pid '${pid}'"
	else
		eend 1 "Lost pid file :("
	fi
}