pandora-xfce-image.bb: Updated to Final version
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_cpuspeed.sh
1 #!/bin/bash
2 #get value range
3 minmhz="$(cat /etc/pandora/conf/cpu.conf | grep 'min:' | awk -F\: '{print $2}')"
4 safemhz="$(cat /etc/pandora/conf/cpu.conf | grep 'safe:' | awk -F\: '{print $2}')"
5 maxmhz="$(cat /etc/pandora/conf/cpu.conf | grep 'max:' | awk -F\: '{print $2}')"
6 warn="$(cat /etc/pandora/conf/cpu.conf | grep 'warn:' | awk -F\: '{print $2}')"
7 device=/proc/pandora/cpu_mhz_max
8 curmhz="$(cat $device)"
9 newmhz="$(cat $device)"
10 kernel_major=`uname -r | cut -c 1`
11
12 if [ ! -e $device ]; then
13     if [ -z "$1" -a -n "$DISPLAY" ]; then
14         zenity --info --title="CPU-Settings not supported" --text \
15             "Sorry, the experimental kernel does not support setting the clockspeed (yet)."
16     fi
17     exit 1
18 fi
19
20 if [ ! $1 ]; then
21         if [ $DISPLAY ]; then
22                 newmhz=$(zenity --scale --text "Set CPU clockspeed" --min-value=$minmhz --max-value=$maxmhz --value=$curmhz --step 1)
23         else
24                 newmhz=$(read -p "Please enter the desired clockspeed")
25         fi
26 else
27         newmhz=$1
28 fi
29
30 if [ $newmhz ]; then
31         if [ $newmhz -gt $safemhz ]; then
32                 if [ $warn != no ]; then 
33                         if [ $DISPLAY ]; then
34                                 answer=$(zenity --question --title "Alert" --text "You are trying to set the CPU clock to $newmhz which is above the warning level of $safemhz, doing so may burn down your house, sour milk, or just blow up (OK, not that likely)! Proceed?";echo $?)
35                                 echo $answer
36                                 if [ $answer = 1 ]; then exit 1; fi
37                         else
38                                 answer="n";read -p "You are trying to set the CPU clock to $newmhz which is above the warning level of $safemhz, doing so may burn down your house, sour milk, or just blow up (OK, not that likely)! Proceed? [y/n]" -t 10 answer
39                                 echo $answer
40                                 if [ $answer = n ]; then exit 1; fi
41                         fi
42                 fi
43         fi
44  
45         if [ $newmhz -le $minmhz ]; then newmhz=$minmhz; fi
46         if [ $newmhz -ge $maxmhz ]; then newmhz=$maxmhz; fi
47         echo $newmhz > $device
48         echo cpu_mhz_max set to $(cat $device)
49
50         if [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
51                 # must poke cpufreq so it does the actual clock transition
52                 # according to new limits
53                 gov=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
54                 echo $gov > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
55         fi
56 fi