updated on Mon Jan 23 20:11:11 UTC 2012
[aur-mirror.git] / phc-k8 / phc-k8.rc
blob574a9da702db8cf0100f938a05f196d17fe32842
1 #!/bin/bash
2 shopt -s nullglob
4 if [ "$1" = set ]; then
5 . /etc/conf.d/phc-k8
6 [ -n "$VIDS" ] || exit
7 for i in $(< /proc/cmdline); do
8 [ $i = nophc ] && exit
9 done
10 for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids; do
11 echo $VIDS > "$i"
12 done
13 exit
16 . /etc/rc.conf
17 . /etc/rc.d/functions
19 case "$1" in
20 start)
21 . /etc/conf.d/phc-k8
22 if [ -z "$VIDS" ]; then
23 printhl 'Please edit /etc/conf.d/phc-k8'
24 exit 1
26 stat_busy 'Setting PHC VIDs'
27 for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids; do
28 echo $VIDS > "$i"
29 done && stat_done || stat_fail
31 stop)
32 stat_busy 'Resetting default PHC VIDs'
33 for i in /sys/devices/system/cpu/cpu*/cpufreq; do
34 [ -e "$i/phc_default_vids" -a -e "$i/phc_vids" ] && cat "$i/phc_default_vids" > "$i/phc_vids"
35 done && stat_done || stat_fail
37 status)
38 check_off () {
39 for i in /sys/devices/system/cpu/cpu*/cpufreq; do
40 [ "$(< $i/phc_vids)" = "$(< $i/phc_default_vids)" ] || return;
41 done
43 check_on () {
44 for i in /sys/devices/system/cpu/cpu*/cpufreq/phc_vids; do
45 [[ "$(< $i)" =~ "$VIDS" ]] || return;
46 done
48 stat_busy 'PHC status'
49 . /etc/conf.d/phc-intel
50 if check_off; then
51 status_stopped
52 elif check_on; then
53 status_started
54 else
55 stat_fail
58 setup)
59 LOG='/var/log/phc-k8.log'
60 fail () {
61 stat_fail
62 printhl "Look at $LOG to find out what went wrong"
63 exit 1
65 stat_busy 'Removing old phc-k8 modules'
66 for i in /lib/modules/*; do
67 if [ -f "$i/phc-k8.ko" -a ! -f "$i/version" ]; then
68 rm -f "$i"/{mperf,phc-k8}.ko
69 rmdir --ignore-fail-on-non-empty "$i"
70 elif [ -d "$i/updates/kernel/arch/x86/kernel/cpu/cpufreq" -a ! -d "$i/kernel" ]; then
71 rm -f "$i"/updates/kernel/arch/x86/kernel/cpu/cpufreq/{mperf,phc-k8}.ko
72 rmdir -p --ignore-fail-on-non-empty "$i/updates/kernel/arch/x86/kernel/cpu/cpufreq"
74 done
75 stat_done
76 stat_busy 'Compiling new phc-k8 module'
77 cd /usr/src/phc-k8/
78 make &>$LOG && stat_done || fail
79 stat_busy 'Installing new phc-k8 module'
80 make install &>>$LOG && stat_done || fail
81 stat_busy 'Cleaning up'
82 make clean &>>$LOG && stat_done || fail
85 echo "usage: $0 {start|stop|status|setup|set}"
86 esac