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@44
|
27 oclock $(gettext 'Display overclocking information')
|
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@44
|
77 #
|
pankso@44
|
78 # GUI Functions
|
pankso@44
|
79 #
|
pankso@44
|
80
|
pankso@44
|
81 # Usage: msg_box "title" "message"
|
pankso@44
|
82 msg_box() {
|
pankso@44
|
83 dialog --title "{ $1 }" --cr-wrap \
|
pankso@44
|
84 --ok-label "TazBerry" --msgbox "\n$2" ${height} ${width}
|
pankso@44
|
85 }
|
pankso@44
|
86
|
pankso@44
|
87 # Usage: text_box "file"
|
pankso@44
|
88 text_box() {
|
pankso@44
|
89 local file="$1"
|
pankso@44
|
90 if [ -f "$file" ]; then
|
pankso@44
|
91 dialog --cr-wrap \
|
pankso@115
|
92 --title "{ $(gettext 'Viewing file:') $file }" \
|
pankso@44
|
93 --extra-button \
|
pankso@44
|
94 --extra-label "Edit file" \
|
pankso@44
|
95 --ok-label "TazBerry" \
|
pankso@44
|
96 --textbox ${file} ${height} ${width}
|
pankso@44
|
97 else
|
pankso@44
|
98 dialog --title "$title" \
|
pankso@44
|
99 --msgbox "\nERROR: $file does not exist" 10 ${width}
|
pankso@44
|
100 fi
|
pankso@44
|
101 # Handle options
|
pankso@44
|
102 case "$?" in
|
pankso@73
|
103 3) editor ${file} ;;
|
pankso@44
|
104 esac
|
pankso@44
|
105 }
|
pankso@44
|
106
|
pankso@44
|
107 # Usage: tail_box "file"
|
pankso@44
|
108 tail_box() {
|
pankso@115
|
109 dialog --title "{ $(gettext 'Watching file:') $2 }" \
|
pankso@44
|
110 --tailbox "$1" ${height} ${width}
|
pankso@44
|
111 }
|
pankso@44
|
112
|
pankso@44
|
113 # Packages info and spk-up button
|
pankso@44
|
114 pkgs_box() {
|
pankso@44
|
115 out="$tmpdir/spk-info.txt"
|
pankso@44
|
116 spk info --output=raw > ${out}
|
pankso@44
|
117 dialog --cr-wrap \
|
pankso@44
|
118 --title "{ $(gettext 'Packages') }" \
|
pankso@44
|
119 --extra-button \
|
pankso@44
|
120 --extra-label "$(gettext 'Upgrade')" \
|
pankso@44
|
121 --ok-label "TazBerry" \
|
pankso@44
|
122 --textbox "$out" ${height} ${width}
|
pankso@44
|
123 # Handle options
|
pankso@44
|
124 case "$?" in
|
pankso@44
|
125 3) spk-up && gettext "Press ENTER to go back to TazBerry"; read ;;
|
pankso@44
|
126 esac
|
pankso@44
|
127 }
|
pankso@44
|
128
|
pankso@44
|
129 oclock_box() {
|
pankso@44
|
130 out="$tmpdir/overclocking.txt"
|
pankso@44
|
131 cat > ${out} << EOT
|
pankso@44
|
132
|
pankso@44
|
133 Overclocking modes:
|
pankso@44
|
134 -------------------
|
pankso@44
|
135 $(rpi_oclock)
|
pankso@44
|
136
|
pankso@44
|
137 Current /boot/config.txt
|
pankso@44
|
138 ------------------------
|
pankso@100
|
139 $(fgrep _freq /boot/config.txt)
|
pankso@100
|
140 $(fgrep over_voltage /boot/config.txt)
|
pankso@44
|
141
|
pankso@44
|
142 EOT
|
pankso@44
|
143 dialog --cr-wrap \
|
pankso@44
|
144 --title "$title" \
|
pankso@44
|
145 --ok-label "TazBerry" \
|
pankso@44
|
146 --textbox "$out" ${height} ${width}
|
pankso@44
|
147 }
|
pankso@44
|
148
|
pankso@105
|
149 gpu_mem_box() {
|
pankso@105
|
150 dialog \
|
pankso@105
|
151 --clear \
|
pankso@105
|
152 --title "$title" \
|
pankso@105
|
153 --ok-label "Set mem" \
|
pankso@105
|
154 --cancel-label "TazBerry" \
|
paul@108
|
155 --menu "\nSet the memory allocated to the GPU (in MB)" \
|
pankso@105
|
156 ${height} ${width} 14 \
|
pankso@105
|
157 "16" "For server, NAS, base system without X" \
|
pankso@105
|
158 "32" "For very small TFT and TV display" \
|
pankso@105
|
159 "64" "Default value, fine for low latency desktop" \
|
pankso@105
|
160 "128" "For a faster desktop, using a video player" \
|
pankso@105
|
161 "256" "For media center, GL/3D applications" 2>${tmp}
|
pankso@105
|
162 mem=$(cat $tmp)
|
pankso@105
|
163 sed -i \
|
pankso@105
|
164 -e s"/#gpu_mem=.*/gpu_mem=$mem/" \
|
pankso@105
|
165 -e s"/gpu_mem=.*/gpu_mem=$mem/" /boot/config.txt
|
pankso@105
|
166 }
|
pankso@105
|
167
|
pankso@44
|
168 # Main Dialog menu
|
pankso@44
|
169 main_box() {
|
pankso@44
|
170 dialog \
|
pankso@44
|
171 --clear \
|
pankso@44
|
172 --title "$title" \
|
pankso@44
|
173 --ok-label "Exec" \
|
pankso@44
|
174 --cancel-label "Quit" \
|
pankso@44
|
175 --menu "" ${height} ${width} 14 \
|
pankso@44
|
176 "rpi-stats" "$(gettext 'Show some RPi system stats')" \
|
pankso@105
|
177 "gpu-mem" "$(gettext 'Set memory split between ARM and GPU')" \
|
pankso@105
|
178 "act-led" "$(gettext 'Test the RPi onboard ACT green led')" \
|
pankso@105
|
179 "oclock" "$(gettext 'Overclocking information and config')" \
|
pankso@105
|
180 "rpi-turbo" "$(gettext 'Enable or disable RPi turbo on next boot')" \
|
pankso@88
|
181 "boot-cmdline" "$(gettext 'View boot args /boot/cmdline.txt')" \
|
pankso@88
|
182 "boot-config" "$(gettext 'View config file /boot/config.txt')" \
|
pankso@115
|
183 "packages" "$(gettext 'SliTaz packages manager') (spk)" \
|
pankso@115
|
184 "config" "$(gettext 'System config (lang, keyboard, wifi)')" \
|
pankso@44
|
185 "reboot" "$(gettext 'Reboot SliTaz')" \
|
pankso@44
|
186 "halt" "$(gettext 'Halt the Raspberry Pi')" \
|
pankso@88
|
187 "quit" "$(gettext 'Exit TazBerry tool')" 2>${tmp}
|
pankso@44
|
188
|
pankso@44
|
189 # Handle options
|
pankso@105
|
190 case "$?" in
|
pankso@46
|
191 1|255) rm -rf ${tmpdir} && exit 0 ;;
|
pankso@44
|
192 esac
|
pankso@44
|
193
|
pankso@44
|
194 # Handle actions
|
pankso@44
|
195 action=$(cat $tmp)
|
pankso@44
|
196 case "$action" in
|
pankso@44
|
197 rpi-stats)
|
pankso@44
|
198 msg_box "RPi Stats" "$(rpi_stats)" ;;
|
pankso@105
|
199 gpu-mem)
|
pankso@105
|
200 gpu_mem_box ;;
|
pankso@105
|
201 act-led)
|
pankso@105
|
202 brightness="/sys/class/leds/led0/brightness"
|
pankso@105
|
203 (echo "1" > ${brightness}
|
pankso@105
|
204 sleep 3; echo "0" > ${brightness}) & ;;
|
pankso@100
|
205 oclock)
|
pankso@100
|
206 oclock_box ;;
|
pankso@44
|
207 rpi-turbo)
|
pankso@44
|
208 rpi_turbo && newline
|
pankso@44
|
209 gettext "Press ENTER to go back to TazBerry"; read ;;
|
pankso@105
|
210 boot-cmdline)
|
pankso@105
|
211 text_box /boot/cmdline.txt ;;
|
pankso@105
|
212 boot-config)
|
pankso@105
|
213 text_box ${config} ;;
|
pankso@44
|
214 packages)
|
pankso@88
|
215 spk-dialog ;;
|
pankso@88
|
216 config)
|
pankso@88
|
217 slitaz-config ;;
|
pankso@44
|
218 reboot)
|
pankso@44
|
219 reboot ;;
|
pankso@44
|
220 halt)
|
pankso@115
|
221 poweroff ;;
|
pankso@44
|
222 quit)
|
pankso@44
|
223 rm -rf ${tmpdir} && exit 0 ;;
|
pankso@44
|
224 esac
|
pankso@44
|
225 }
|
pankso@44
|
226
|
pankso@44
|
227 # Progress bar testsuite
|
pankso@44
|
228 gauge_box() {
|
pankso@44
|
229 { for i in $(seq 1 100); do
|
pankso@44
|
230 echo $i
|
pankso@44
|
231 sleep 0.01
|
pankso@44
|
232 done
|
pankso@44
|
233 echo 100; } | dialog --title "{ TazBerry }" \
|
pankso@44
|
234 --gauge "Work in progress..." 6 ${width} 0
|
pankso@44
|
235 }
|
pankso@44
|
236
|
pankso@44
|
237 #
|
pankso@44
|
238 # Handle commands
|
pankso@44
|
239 #
|
pankso@44
|
240
|
pankso@44
|
241 case "$1" in
|
pankso@44
|
242 oclock)
|
pankso@44
|
243 newline
|
pankso@44
|
244 boldify "Overclocking modes:"
|
pankso@44
|
245 rpi_oclock
|
pankso@44
|
246 boldify "Current config.txt:"
|
pankso@44
|
247 cat ${config}
|
pankso@44
|
248 newline ;;
|
pankso@44
|
249
|
pankso@44
|
250 ls-functions)
|
pankso@44
|
251 newline
|
pankso@44
|
252 boldify "$(gettext 'TazBerry functions list')"
|
pankso@44
|
253 separator
|
pankso@44
|
254 grep "^rpi_*" $0 | awk '{print " ", $1}'
|
pankso@44
|
255 newline ;;
|
pankso@44
|
256
|
pankso@44
|
257 testsuite)
|
pankso@44
|
258 gauge_box
|
pankso@44
|
259 msg_box "Testsuite" "Test message"
|
pankso@44
|
260 rpi_stats
|
pankso@44
|
261 newline ;;
|
pankso@44
|
262
|
pankso@44
|
263 rpi_*)
|
pankso@44
|
264 # Execute functions
|
pankso@44
|
265 $@ ;;
|
pankso@44
|
266
|
pankso@44
|
267 "")
|
pankso@44
|
268 # No args: display Ncurses dialog
|
pankso@44
|
269 while true; do
|
pankso@44
|
270 main_box
|
pankso@44
|
271 done ;;
|
pankso@44
|
272
|
pankso@44
|
273 *|*help|-h)
|
pankso@44
|
274 # Display help
|
pankso@44
|
275 help ;;
|
pankso@44
|
276 esac
|
pankso@44
|
277
|
pankso@44
|
278 # Clean exit
|
pankso@44
|
279 rm -rf ${tmpdir}
|
pankso@44
|
280 exit 0
|