rev |
line source |
pankso@44
|
1 #!/bin/sh
|
pankso@44
|
2 #
|
pankso@44
|
3 # TazBerry - SliTaz Raspberry Pi Config Tool
|
pankso@44
|
4 #
|
pankso@44
|
5 # Copyright (C) 2014 SliTaz ARM - BSD License
|
pankso@44
|
6 # Author: Christophe Lincoln <pankso@slitaz.org>
|
pankso@44
|
7 #
|
pankso@44
|
8 . /lib/libtaz.sh
|
pankso@44
|
9
|
pankso@44
|
10 title="{ TazBerry }"
|
pankso@44
|
11 config="/boot/config.txt"
|
pankso@44
|
12 tmpdir="/tmp/tazberry"
|
pankso@44
|
13 tmp="$tmpdir/$$"
|
pankso@44
|
14 height="20"
|
pankso@44
|
15 width="72"
|
pankso@44
|
16
|
pankso@44
|
17 # Use a tmp directory
|
pankso@44
|
18 mkdir -p ${tmpdir}
|
pankso@44
|
19
|
pankso@44
|
20 # Small built-in help
|
pankso@44
|
21 help() {
|
pankso@44
|
22 cat << EOT
|
pankso@44
|
23
|
pankso@44
|
24 $(boldify "$(gettext 'Usage:')") $(basename $0) [command|rpi_function]
|
pankso@44
|
25
|
pankso@44
|
26 $(boldify "$(gettext 'Commands:')")
|
pankso@122
|
27 oclock $(gettext 'Configure overclocking')
|
pankso@44
|
28 ls-functions $(gettext 'List TazBerry functions')
|
pankso@105
|
29 rpi_ $(gettext 'Execute any tazberry_function')
|
pankso@44
|
30 testsuite $(gettext 'Run TazBerry testsuite')
|
pankso@44
|
31
|
pankso@44
|
32 EOT
|
pankso@44
|
33 }
|
pankso@44
|
34
|
pankso@44
|
35 #
|
pankso@44
|
36 # RPi functions
|
pankso@44
|
37 #
|
pankso@44
|
38
|
paul@65
|
39 # This could move to /usr/bin/slitaz-??? or something since it's not
|
pankso@58
|
40 # ARM specific
|
pankso@44
|
41 rpi_stats() {
|
pankso@58
|
42 ip=$(ifconfig | fgrep -A 1 "encap:Ethernet" | fgrep "inet" | cut -d ":" -f 2)
|
pankso@58
|
43 mem_total=$(free -m | fgrep "Mem:" | awk '{print $2}')
|
pankso@58
|
44 mem_used=$(free -m | fgrep "Mem:" | awk '{print $3}')
|
pankso@58
|
45 mem_used_pct=$(( ( ${mem_used} * 100) / ${mem_total} ))
|
pankso@44
|
46 cat << EOT
|
pankso@67
|
47 $(gettext 'Kernel') : $(uname -snrm)
|
pankso@67
|
48 $(gettext 'Uptime') : $(uptime | awk '{print $3}' | sed s"/:/h /" | sed s"/,/min/")
|
pankso@67
|
49 $(gettext 'Network IP') : $(echo $ip | awk '{print $1}')
|
pankso@67
|
50 $(gettext 'CPU heat') : $(awk '{printf "%3.1f C\n", $1/1000}' /sys/class/thermal/thermal_zone0/temp)
|
pankso@67
|
51 $(gettext 'Processes') : $(ps | wc -l)
|
pankso@67
|
52 $(gettext 'Memory usage') : ${mem_used_pct}%
|
pankso@44
|
53 EOT
|
pankso@44
|
54 }
|
pankso@44
|
55
|
pankso@44
|
56 rpi_turbo() {
|
pankso@44
|
57 if ! fgrep -q 'force_turbo=1' ${config}; then
|
pankso@44
|
58 gettext "Enabling Raspberry Pi force turbo..."
|
pankso@44
|
59 echo "force_turbo=1" >> ${config}; status
|
pankso@44
|
60 else
|
pankso@44
|
61 gettext "Disabling Raspberry Pi force turbo..."
|
pankso@44
|
62 sed -i '/force_turbo=1/'d ${config}; status
|
pankso@44
|
63 fi
|
pankso@44
|
64 }
|
pankso@44
|
65
|
pankso@44
|
66 # RPi Overclocking
|
pankso@44
|
67 rpi_oclock() {
|
pankso@44
|
68 cat << EOT
|
pankso@44
|
69 none 700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt
|
pankso@44
|
70 modest 800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt
|
pankso@44
|
71 medium 900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt
|
pankso@44
|
72 high 950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt
|
pankso@44
|
73 turbo 1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt
|
pankso@44
|
74 EOT
|
pankso@44
|
75 }
|
pankso@44
|
76
|
pankso@122
|
77 # Unset overclocking
|
pankso@122
|
78 unset_oclock() {
|
pankso@122
|
79 debug "unset_oclock"
|
pankso@122
|
80 sed -i \
|
pankso@122
|
81 -e '/# Overclocking.*/'d \
|
pankso@122
|
82 -e '/arm_freq=/'d \
|
pankso@122
|
83 -e '/core_freq=/'d \
|
pankso@122
|
84 -e '/sdram_freq=/'d \
|
pankso@122
|
85 -e '/over_voltage=/'d ${config}
|
pankso@122
|
86 # Remove if 3 empty lines follows
|
pankso@122
|
87 sed -i '1N;N;/^\n\n$/d;P;D' ${config}
|
pankso@122
|
88 }
|
pankso@122
|
89
|
pankso@122
|
90 # Set overclocking: set_oclock [mode]
|
pankso@122
|
91 set_oclock() {
|
pankso@122
|
92 debug "set_oclock $1"
|
pankso@122
|
93 case "$1" in
|
pankso@122
|
94 none)
|
pankso@122
|
95 arm_freq=700
|
pankso@122
|
96 core_freq=250
|
pankso@122
|
97 sdram_freq=400
|
pankso@122
|
98 over_voltage=0 ;;
|
pankso@122
|
99 modest)
|
pankso@122
|
100 arm_freq=800
|
pankso@122
|
101 core_freq=300
|
pankso@122
|
102 sdram_freq=400
|
pankso@122
|
103 over_voltage=0 ;;
|
pankso@122
|
104 medium)
|
pankso@122
|
105 arm_freq=900
|
pankso@122
|
106 core_freq=333
|
pankso@122
|
107 sdram_freq=450
|
pankso@122
|
108 over_voltage=2 ;;
|
paul@127
|
109 high)
|
pankso@122
|
110 arm_freq=950
|
pankso@122
|
111 core_freq=450
|
pankso@122
|
112 sdram_freq=450
|
pankso@122
|
113 over_voltage=6 ;;
|
pankso@122
|
114 turbo)
|
pankso@122
|
115 arm_freq=1000
|
pankso@122
|
116 core_freq=500
|
pankso@122
|
117 sdram_freq=500
|
pankso@122
|
118 over_voltage=6 ;;
|
pankso@122
|
119 esac
|
pankso@122
|
120 unset_oclock
|
pankso@122
|
121 cat >> ${config} << EOT
|
pankso@122
|
122 # Overclocking Settings
|
pankso@122
|
123 arm_freq=$arm_freq
|
pankso@122
|
124 core_freq=$core_freq
|
pankso@122
|
125 sdram_freq=$sdram_freq
|
pankso@122
|
126 over_voltage=$over_voltage
|
pankso@122
|
127
|
pankso@122
|
128 EOT
|
pankso@122
|
129 }
|
pankso@122
|
130
|
pankso@44
|
131 #
|
pankso@44
|
132 # GUI Functions
|
pankso@44
|
133 #
|
pankso@44
|
134
|
pankso@44
|
135 # Usage: msg_box "title" "message"
|
pankso@44
|
136 msg_box() {
|
pankso@44
|
137 dialog --title "{ $1 }" --cr-wrap \
|
pankso@44
|
138 --ok-label "TazBerry" --msgbox "\n$2" ${height} ${width}
|
pankso@44
|
139 }
|
pankso@44
|
140
|
pankso@44
|
141 # Usage: text_box "file"
|
pankso@44
|
142 text_box() {
|
pankso@44
|
143 local file="$1"
|
pankso@44
|
144 if [ -f "$file" ]; then
|
pankso@44
|
145 dialog --cr-wrap \
|
pankso@115
|
146 --title "{ $(gettext 'Viewing file:') $file }" \
|
pankso@44
|
147 --extra-button \
|
pankso@44
|
148 --extra-label "Edit file" \
|
pankso@44
|
149 --ok-label "TazBerry" \
|
pankso@44
|
150 --textbox ${file} ${height} ${width}
|
pankso@44
|
151 else
|
pankso@44
|
152 dialog --title "$title" \
|
pankso@44
|
153 --msgbox "\nERROR: $file does not exist" 10 ${width}
|
pankso@44
|
154 fi
|
pankso@44
|
155 # Handle options
|
pankso@44
|
156 case "$?" in
|
pankso@73
|
157 3) editor ${file} ;;
|
pankso@44
|
158 esac
|
pankso@44
|
159 }
|
pankso@44
|
160
|
pankso@44
|
161 # Usage: tail_box "file"
|
pankso@44
|
162 tail_box() {
|
pankso@115
|
163 dialog --title "{ $(gettext 'Watching file:') $2 }" \
|
pankso@44
|
164 --tailbox "$1" ${height} ${width}
|
pankso@44
|
165 }
|
pankso@44
|
166
|
pankso@44
|
167 # Packages info and spk-up button
|
pankso@44
|
168 pkgs_box() {
|
pankso@44
|
169 out="$tmpdir/spk-info.txt"
|
pankso@44
|
170 spk info --output=raw > ${out}
|
pankso@44
|
171 dialog --cr-wrap \
|
pankso@44
|
172 --title "{ $(gettext 'Packages') }" \
|
pankso@44
|
173 --extra-button \
|
pankso@44
|
174 --extra-label "$(gettext 'Upgrade')" \
|
pankso@44
|
175 --ok-label "TazBerry" \
|
pankso@44
|
176 --textbox "$out" ${height} ${width}
|
pankso@44
|
177 # Handle options
|
pankso@44
|
178 case "$?" in
|
pankso@44
|
179 3) spk-up && gettext "Press ENTER to go back to TazBerry"; read ;;
|
pankso@44
|
180 esac
|
pankso@44
|
181 }
|
pankso@44
|
182
|
pankso@122
|
183 # Overclocking info TODO: button to setup
|
pankso@44
|
184 oclock_box() {
|
pankso@122
|
185 mode=$(fgrep arm_freq ${config} | cut -d '=' -f 2)
|
pankso@122
|
186 case "$mode" in
|
pankso@122
|
187 700) mode="none" ;;
|
pankso@122
|
188 800) mode="modest" ;;
|
pankso@122
|
189 900) mode="medium" ;;
|
pankso@122
|
190 950) mode="high" ;;
|
pankso@122
|
191 1000) mode="turbo" ;;
|
pankso@122
|
192 esac
|
pankso@122
|
193 dialog \
|
pankso@122
|
194 --clear --colors \
|
pankso@122
|
195 --extra-button \
|
pankso@122
|
196 --title "{ Overclocking }" \
|
pankso@44
|
197 --ok-label "TazBerry" \
|
pankso@122
|
198 --extra-label "Set Overclock" \
|
pankso@122
|
199 --cancel-label "Unset Oclock" \
|
paul@127
|
200 --menu "\nSet Raspberry Pi overclocking, current setting: \Zb\Z2$mode" \
|
pankso@122
|
201 ${height} ${width} 14 \
|
pankso@122
|
202 "none" "700MHz ARM 250MHz core 400MHz SDRAM 0 overvolt" \
|
pankso@122
|
203 "modest" "800MHz ARM 300MHz core 400MHz SDRAM 0 overvolt" \
|
pankso@122
|
204 "medium" "900MHz ARM 333MHz core 450MHz SDRAM 2 overvolt" \
|
pankso@122
|
205 "high" "950MHz ARM 450MHz core 450MHz SDRAM 6 overvolt" \
|
pankso@122
|
206 "turbo" "1000MHz ARM 500MHz core 500MHz SDRAM 6 overvolt" 2>${tmp}
|
pankso@122
|
207 retval="$?"
|
pankso@122
|
208 mode=$(cat $tmp)
|
pankso@122
|
209 case "$retval" in
|
pankso@122
|
210 0) continue ;;
|
pankso@122
|
211 1) unset_oclock ;;
|
pankso@122
|
212 3) set_oclock "$mode" ;;
|
pankso@122
|
213 255) rm -rf ${tmpdir} && exit 0 ;;
|
pankso@122
|
214 esac
|
pankso@44
|
215 }
|
pankso@44
|
216
|
pankso@105
|
217 gpu_mem_box() {
|
pankso@105
|
218 dialog \
|
pankso@105
|
219 --clear \
|
pankso@105
|
220 --title "$title" \
|
pankso@105
|
221 --ok-label "Set mem" \
|
pankso@105
|
222 --cancel-label "TazBerry" \
|
paul@108
|
223 --menu "\nSet the memory allocated to the GPU (in MB)" \
|
pankso@105
|
224 ${height} ${width} 14 \
|
pankso@105
|
225 "16" "For server, NAS, base system without X" \
|
pankso@105
|
226 "32" "For very small TFT and TV display" \
|
pankso@105
|
227 "64" "Default value, fine for low latency desktop" \
|
pankso@105
|
228 "128" "For a faster desktop, using a video player" \
|
pankso@105
|
229 "256" "For media center, GL/3D applications" 2>${tmp}
|
pankso@105
|
230 mem=$(cat $tmp)
|
pankso@105
|
231 sed -i \
|
pankso@105
|
232 -e s"/#gpu_mem=.*/gpu_mem=$mem/" \
|
pankso@105
|
233 -e s"/gpu_mem=.*/gpu_mem=$mem/" /boot/config.txt
|
pankso@105
|
234 }
|
pankso@105
|
235
|
pankso@44
|
236 # Main Dialog menu
|
pankso@44
|
237 main_box() {
|
pankso@44
|
238 dialog \
|
pankso@44
|
239 --clear \
|
pankso@44
|
240 --title "$title" \
|
pankso@44
|
241 --ok-label "Exec" \
|
pankso@44
|
242 --cancel-label "Quit" \
|
pankso@44
|
243 --menu "" ${height} ${width} 14 \
|
pankso@44
|
244 "rpi-stats" "$(gettext 'Show some RPi system stats')" \
|
pankso@105
|
245 "gpu-mem" "$(gettext 'Set memory split between ARM and GPU')" \
|
pankso@105
|
246 "act-led" "$(gettext 'Test the RPi onboard ACT green led')" \
|
pankso@122
|
247 "oclock" "$(gettext 'Overclocking configuration')" \
|
pankso@105
|
248 "rpi-turbo" "$(gettext 'Enable or disable RPi turbo on next boot')" \
|
pankso@88
|
249 "boot-cmdline" "$(gettext 'View boot args /boot/cmdline.txt')" \
|
pankso@88
|
250 "boot-config" "$(gettext 'View config file /boot/config.txt')" \
|
pankso@115
|
251 "packages" "$(gettext 'SliTaz packages manager') (spk)" \
|
pankso@115
|
252 "config" "$(gettext 'System config (lang, keyboard, wifi)')" \
|
pankso@122
|
253 "reboot" "$(gettext 'Reboot SliTaz system')" \
|
pankso@44
|
254 "halt" "$(gettext 'Halt the Raspberry Pi')" \
|
pankso@88
|
255 "quit" "$(gettext 'Exit TazBerry tool')" 2>${tmp}
|
pankso@44
|
256
|
pankso@44
|
257 # Handle options
|
pankso@105
|
258 case "$?" in
|
pankso@46
|
259 1|255) rm -rf ${tmpdir} && exit 0 ;;
|
pankso@44
|
260 esac
|
pankso@44
|
261
|
pankso@44
|
262 # Handle actions
|
pankso@44
|
263 action=$(cat $tmp)
|
pankso@44
|
264 case "$action" in
|
pankso@44
|
265 rpi-stats)
|
pankso@44
|
266 msg_box "RPi Stats" "$(rpi_stats)" ;;
|
pankso@105
|
267 gpu-mem)
|
pankso@105
|
268 gpu_mem_box ;;
|
pankso@105
|
269 act-led)
|
pankso@105
|
270 brightness="/sys/class/leds/led0/brightness"
|
pankso@105
|
271 (echo "1" > ${brightness}
|
pankso@105
|
272 sleep 3; echo "0" > ${brightness}) & ;;
|
pankso@100
|
273 oclock)
|
pankso@100
|
274 oclock_box ;;
|
pankso@44
|
275 rpi-turbo)
|
pankso@44
|
276 rpi_turbo && newline
|
pankso@44
|
277 gettext "Press ENTER to go back to TazBerry"; read ;;
|
pankso@105
|
278 boot-cmdline)
|
pankso@105
|
279 text_box /boot/cmdline.txt ;;
|
pankso@105
|
280 boot-config)
|
pankso@105
|
281 text_box ${config} ;;
|
pankso@44
|
282 packages)
|
pankso@88
|
283 spk-dialog ;;
|
pankso@88
|
284 config)
|
pankso@88
|
285 slitaz-config ;;
|
pankso@44
|
286 reboot)
|
pankso@44
|
287 reboot ;;
|
pankso@44
|
288 halt)
|
pankso@115
|
289 poweroff ;;
|
pankso@44
|
290 quit)
|
pankso@44
|
291 rm -rf ${tmpdir} && exit 0 ;;
|
pankso@44
|
292 esac
|
pankso@44
|
293 }
|
pankso@44
|
294
|
pankso@44
|
295 # Progress bar testsuite
|
pankso@44
|
296 gauge_box() {
|
pankso@44
|
297 { for i in $(seq 1 100); do
|
pankso@44
|
298 echo $i
|
pankso@44
|
299 sleep 0.01
|
pankso@44
|
300 done
|
pankso@44
|
301 echo 100; } | dialog --title "{ TazBerry }" \
|
pankso@44
|
302 --gauge "Work in progress..." 6 ${width} 0
|
pankso@44
|
303 }
|
pankso@44
|
304
|
pankso@44
|
305 #
|
pankso@44
|
306 # Handle commands
|
pankso@44
|
307 #
|
pankso@44
|
308
|
pankso@44
|
309 case "$1" in
|
pankso@44
|
310 oclock)
|
pankso@122
|
311 oclock_box ;;
|
pankso@44
|
312
|
pankso@44
|
313 ls-functions)
|
pankso@44
|
314 newline
|
pankso@44
|
315 boldify "$(gettext 'TazBerry functions list')"
|
pankso@44
|
316 separator
|
pankso@44
|
317 grep "^rpi_*" $0 | awk '{print " ", $1}'
|
pankso@44
|
318 newline ;;
|
pankso@44
|
319
|
pankso@44
|
320 testsuite)
|
pankso@44
|
321 gauge_box
|
pankso@44
|
322 msg_box "Testsuite" "Test message"
|
pankso@44
|
323 rpi_stats
|
pankso@44
|
324 newline ;;
|
pankso@44
|
325
|
pankso@44
|
326 rpi_*)
|
pankso@44
|
327 # Execute functions
|
pankso@44
|
328 $@ ;;
|
pankso@44
|
329
|
pankso@44
|
330 "")
|
pankso@44
|
331 # No args: display Ncurses dialog
|
pankso@44
|
332 while true; do
|
pankso@44
|
333 main_box
|
pankso@44
|
334 done ;;
|
pankso@44
|
335
|
pankso@44
|
336 *|*help|-h)
|
pankso@44
|
337 # Display help
|
pankso@44
|
338 help ;;
|
pankso@44
|
339 esac
|
pankso@44
|
340
|
pankso@44
|
341 # Clean exit
|
pankso@44
|
342 rm -rf ${tmpdir}
|
pankso@44
|
343 exit 0
|