updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / eee-fan / eee-fan-config.sh
blob94d7a4b1c6367729b805966d9d36b66d1ce639a2
1 #!/bin/sh
2 # A simple configuration gui for eee-fan-control.sh
3 ## yet another dubious Dougal script for Puppy Linux, Oct. 22nd 2008
4 ## Licenced under GPL v2 or later
5 ## No BASHisms I'm aware of...
6 # Update Nov. 2nd: add VERBOSE_LOGGING and mention MAX_ and MIN_ temps
8 SCRIPT_NAME="eee-fan-ctrl.sh"
9 CONFIG_FILE="/etc/eee-fan.conf"
10 LOG_FILE="/var/log/eee-fan.log"
11 # a list of the variables in the config file (so we can set the defaults in the gui)
12 VARIABLES="CONTROL_FAN SLEEP_TIME HIGH_TEMP LOW_TEMP FAN_SPEED ENABLE_LOGGING VERBOSE_LOGGING"
13 # a list of the variables that get shaded if control is set to "false"...
14 SHADEABLES="SLEEP_TIME HIGH_TEMP LOW_TEMP FAN_SPEED ENABLE_LOGGING VERBOSE_LOGGING"
16 ## A function to kill stray processes (sometimes remain if dialog closed by WM)
17 ## dialog variable passed as param
18 clean_up_gtkdialog(){
19 [ "$1" ] || return
20 for I in $( ps -eo pid,command | grep "$1" | grep -v grep | grep -F 'gtkdialog3' | cut -d' ' -f1 )
21 do kill $I
22 done
25 # Source config file
26 . $CONFIG_FILE
28 # set defaults for gtkdialog (and so we know if the value was changed...)
29 for ONE in $VARIABLES
30 do eval DEFAULT_$ONE=\$$ONE
31 done
33 # set the default visibility
34 if [ "$CONTROL_FAN" = "true" ] ; then
35 for ONE in $SHADEABLES
36 do eval VISIBLE_$ONE=\"\<visible\>enabled\<\/visible\>\"
37 done
38 else
39 for ONE in $SHADEABLES
40 do eval VISIBLE_$ONE=\"\<visible\>disabled\<\/visible\>\"
41 done
44 # create the block of if commands for (un)shading fields
45 CONTROL_FAN_CODE=""
46 for ONE in $SHADEABLES
48 CONTROL_FAN_CODE="$CONTROL_FAN_CODE
49 <action>if false disable:$ONE</action>
50 <action>if true enable:$ONE</action>"
51 done
53 export EEE_FAN_CONFIG_GUI="<window title=\"Eee Fan Control Configuration\" icon-name=\"gtk-preferences\" window-position=\"1\">
54 <vbox>
55 <checkbox>
56 <label>\"Control the fan manually?\"</label>
57 <variable>CONTROL_FAN</variable>
58 <default>$DEFAULT_CONTROL_FAN</default>
59 $CONTROL_FAN_CODE
60 </checkbox>
62 <hbox>
63 <text>
64 <label>How frequently we should check the temperature (in seconds)?</label>
65 </text>
66 <entry>
67 <variable>SLEEP_TIME</variable>
68 <default>$DEFAULT_SLEEP_TIME</default>
69 $VISIBLE_SLEEP_TIME
70 </entry>
71 </hbox>
73 <frame Operating Temperature Range >
74 <text use-markup=\"true\">
75 <label>\"The temperature range in which the fan should be active:
76 When the temperature reaches the 'High temp', the fan will be activated and remain active until the temperature gets down to the 'Low temp'. (Temperatures are in centigrade/Celsius.)
77 <i>Note: The daemon only accepts values in the range $MIN_TEMP-$MAX_TEMP.</i>\"</label>
78 </text>
79 <hbox>
80 <text>
81 <label>High temp:</label>
82 </text>
83 <entry>
84 <variable>HIGH_TEMP</variable>
85 <default>$DEFAULT_HIGH_TEMP</default>
86 $VISIBLE_HIGH_TEMP
87 </entry>
89 <text>
90 <label>Low temp:</label>
91 </text>
92 <entry>
93 <variable>LOW_TEMP</variable>
94 <default>$DEFAULT_LOW_TEMP</default>
95 $VISIBLE_LOW_TEMP
96 </entry>
97 </hbox>
98 </frame>
99 <hbox>
100 <text>
101 <label>The speed to run the fan at (0-100):</label>
102 </text>
103 <entry>
104 <variable>FAN_SPEED</variable>
105 <default>$DEFAULT_FAN_SPEED</default>
106 $VISIBLE_FAN_SPEED
107 </entry>
108 </hbox>
109 <frame Logging support (log file $LOG_FILE) >
110 <checkbox>
111 <label>Enable logging? (log any status changes)</label>
112 <variable>ENABLE_LOGGING</variable>
113 <default>$DEFAULT_ENABLE_LOGGING</default>
114 $VISIBLE_ENABLE_LOGGING
115 </checkbox>
116 <checkbox>
117 <label>Verbose logging? (log the temperature every time we check it)</label>
118 <variable>VERBOSE_LOGGING</variable>
119 <default>$DEFAULT_VERBOSE_LOGGING</default>
120 $VISIBLE_VERBOSE_LOGGING
121 </checkbox>
122 </frame>
123 <checkbox>
124 <label>Apply now (rather tnat next time script is started)?</label>
125 <variable>APPLY_NOW</variable>
126 <default>true</default>
127 </checkbox>
128 <hbox>
129 <button ok></button>
130 <button cancel></button>
131 </hbox>
132 </vbox>
133 </window>"
135 I=$IFS; IFS=""
136 for STATEMENT in $(gtkdialog --program EEE_FAN_CONFIG_GUI); do
137 eval $STATEMENT 2>/dev/null
138 done
139 IFS=$I
140 clean_up_gtkdialog EEE_FAN_CONFIG_GUI
141 unset EEE_FAN_CONFIG_GUI
143 case $EXIT in OK) ;; *) exit ;; esac
145 # see if anything has changed
146 for ONE in $VARIABLES
148 eval OLD=\$DEFAULT_$ONE
149 eval NEW=\$$ONE
150 if [ "$NEW" != "$OLD" ] ; then
151 # make sure the new value is not blank!
152 [ "$NEW" ] || continue
153 sed -i "s/^$ONE=.*/$ONE=$NEW/" "$CONFIG_FILE"
155 done
157 # see if we want to apply immediately
158 $APPLY_NOW && killall -q -HUP $SCRIPT_NAME