slitaz-tools view oldstuff/tazctrlbox @ rev 625

Gettextize setmixer and make pot
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jun 14 22:47:24 2011 +0200 (2011-06-14)
parents 0a7ab48dfe8c
children 83491d0ac7b1
line source
1 #!/bin/sh
2 #
3 # SliTaz Control Box is a tool to configure and manage a SliTaz system.
4 # The script uses GTKdialog for the UI interface. Some shell functions
5 # are called by argument. Individual window dialogs are put into
6 # functions.
7 #
8 # (C) GNU gpl v3 - SliTaz GNU/Linux 2010.
9 # Author: Christophe Lincoln <pankso@slitaz.org>
10 #
11 VERSION=1.1
13 # Include gettext helper script.
14 . /usr/bin/gettext.sh
16 # Export package name for gettext.
17 TEXTDOMAIN='tazctrlbox'
18 export TEXTDOMAIN
20 # Get init configuration.
21 . /etc/rcS.conf
23 # Tazctrlbox is only for root.
24 if test $(id -u) != 0 ; then
25 exec subox $0
26 exit 0
27 fi
29 # By default autologin is not configured on an installed system.
30 if ! grep -q 'auto_login' /etc/slim.conf; then
31 echo '# Auto login default user' >> /etc/slim.conf
32 echo 'auto_login no' >> /etc/slim.conf
33 fi
35 # Change Grub menu.lst timeout.
36 sed_grub_timeout()
37 {
38 CURRENT=`cat /boot/grub/menu.lst | grep ^timeout | cut -d " " -f2`
39 sed -i s/"timeout $CURRENT"/"timeout $GRUB_TIMEOUT"/ /boot/grub/menu.lst
40 }
42 # Change Grub menu.lst timeout.
43 sed_grub_color()
44 {
45 CURRENT=`cat /boot/grub/menu.lst | grep ^color | cut -d " " -f2-3`
46 sed -i s#"color $CURRENT"#"color $GRUB_COLOR"# /boot/grub/menu.lst
47 }
49 # Set check fs on boot.
50 sed_check_fs()
51 {
52 sed -i s#"CHECK_FS=\"$CHECK_FS\""#"CHECK_FS=\"$NEW_CHECK_FS\""# \
53 /etc/rcS.conf
54 }
56 # Set loaded modules on boot.
57 sed_load_modules()
58 {
59 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$NEW_MODULES\""/ \
60 /etc/rcS.conf
61 }
63 # Set daemons to run on boot.
64 sed_run_daemons()
65 {
66 sed -i s/"RUN_DAEMONS=\"$RUN_DAEMONS\""/"RUN_DAEMONS=\"$NEW_DAEMONS\""/ \
67 /etc/rcS.conf
68 }
70 # Get user list.
71 get_users()
72 {
73 for i in `cat /etc/passwd | cut -d ":" -f 1`
74 do
75 if [ -d /home/$i ]; then
76 login=$i
77 uid=`cat /etc/passwd | grep $i | cut -d ":" -f 3`
78 gid=`cat /etc/passwd | grep $i | cut -d ":" -f 4`
79 name=`cat /etc/passwd | grep $i | cut -d ":" -f 5 | sed s/,,,//`
80 home=`cat /etc/passwd | grep $i | cut -d ":" -f 6`
81 shell=`cat /etc/passwd | grep $i | cut -d ":" -f 7`
82 echo "system-users | $login | $uid:$gid | $name | $home | $shell"
83 fi
84 done
85 }
87 # Remove a user or change passwd.
88 manage_user()
89 {
90 export MANAGE_DIALOG="
91 <window title=\"`gettext "Manage user: "`$USER\" icon-name=\"computer\">
92 <vbox>
93 <vbox>
94 <text wrap=\"false\" width-chars=\"34\">
95 <label>\"
96 Login name: $USER
97 \"</label>
98 </text>
99 </vbox>
100 <hbox>
101 <text wrap=\"false\">
102 <label>\"`gettext "New password:"`\"</label>
103 </text>
104 <entry invisible_char=\"*\" visibility=\"false\" max_length=\"8\">
105 <variable>PASSWD</variable>
106 </entry>
107 <button>
108 <label>Change</label>
109 <input file icon=\"forward\"></input>
110 <action>echo \"$USER:$PASSWD\" | chpasswd</action>
111 <action type=\"closewindow\">MANAGE_USER</action>
112 </button>
113 </hbox>
114 <hbox>
115 <button>
116 <label>`gettext "Delete user"`</label>
117 <input file icon=\"gtk-delete\"></input>
118 <action>deluser $USER</action>
119 <action type=\"closewindow\">MANAGE_USER</action>
120 </button>
121 <button cancel>
122 <action type=\"closewindow\">MANAGE_USER</action>
123 </button>
124 </hbox>
125 </vbox>
126 </window>
127 "
128 gtkdialog --center --program=MANAGE_DIALOG >/dev/null
129 }
131 # Add a new user.
132 add_user()
133 {
134 export ADD_USER_DIALOG='
135 <window title="New user" icon-name="gtk-add">
136 <vbox>
137 <vbox>
138 <text wrap="false" width-chars="34">
139 <label>"'`gettext "
140 New account information"`'
141 "</label>
142 </text>
143 </vbox>
144 <hbox>
145 <text wrap="false">
146 <label>"'`gettext "Login:"`' "</label>
147 </text>
148 <entry>
149 <variable>NEW_USER</variable>
150 </entry>
151 </hbox>
152 <hbox>
153 <text wrap="false">
154 <label>"'`gettext "Password:"`'"</label>
155 </text>
156 <entry invisible_char="*" visibility="false" max_length="8">
157 <variable>PASSWD</variable>
158 </entry>
159 </hbox>
160 <hbox>
161 <button ok>
162 <action>adduser -D $NEW_USER</action>
163 <action>echo "$NEW_USER:$PASSWD" | chpasswd</action>
164 <action>addgroup $NEW_USER audio</action>
165 <action>addgroup $NEW_USER cdrom</action>
166 <action>addgroup $NEW_USER floppy</action>
167 <action>addgroup $NEW_USER video</action>
168 <action>rmdir /home/$NEW_USER</action>
169 <action>cp -a /etc/skel /home/$NEW_USER</action>
170 <action>cp /root/.xinitrc /home/$NEW_USER</action>
171 <action>mkdir -p /home/$NEW_USER/.config/slitaz</action>
172 <action>cp -a /etc/slitaz/applications.conf /home/$NEW_USER/.config/slitaz</action>
173 <action>chown -R $NEW_USER:$NEW_USER /home/$NEW_USER</action>
174 <action type="closewindow">MANAGE_USER</action>
175 </button>
176 <button cancel>
177 <action type="closewindow">MANAGE_USER</action>
178 </button>
179 </hbox>
180 </vbox>
181 </window>
182 '
183 gtkdialog --center --program=ADD_USER_DIALOG >/dev/null
184 }
186 # i18n functions.
187 list_locales()
188 {
189 cd /usr/share/i18n/locales
190 for locale in `ls -1 [a-z][a-z]_[A-Z][A-Z]`
191 do
192 echo "preferences-desktop-locale | $locale | UTF-8"
193 done
194 }
195 gen_utf8_locale()
196 {
197 rm -rf /usr/lib/locale/$LANGUAGE
198 localedef -i $LANGUAGE -c -f UTF-8 /usr/lib/locale/$LANGUAGE
199 # System configuration
200 echo "LANG=$LANGUAGE" > /etc/locale.conf
201 echo "LC_ALL=$LANGUAGE" >> /etc/locale.conf
202 }
204 # Main dialog with notebook.
205 #
206 export MAIN_DIALOG='
207 <window title="'`gettext "SliTaz Control Box"`'" icon-name="computer">
208 <vbox>
210 <hbox>
211 <text use-markup="true">
212 <label>"'`gettext "<b>SliTaz Control Box</b>"`'"</label>
213 </text>
214 <pixmap>
215 <input file>/usr/share/pixmaps/tazctrlbox.png</input>
216 </pixmap>
217 </hbox>
219 <notebook labels="'`gettext "Boot loader|Initialization|Login manager|Time|Language|Users"`'">'
221 # GRUB.
222 MAIN_DIALOG=${MAIN_DIALOG}"
223 <vbox>
224 <frame `gettext "Grub boot loader"`>
225 <hbox>
226 <text wrap=\"false\">
227 <label>\"`gettext "Timeout:"`\"</label>
228 </text>
229 <entry>
230 <input>cat /boot/grub/menu.lst | grep ^timeout | cut -d \" \" -f2</input>
231 <variable>GRUB_TIMEOUT</variable>
232 </entry>
233 <button>
234 <label>`gettext "Change"`</label>
235 <input file icon=\"forward\"></input>
236 <action>$0 sed_grub_timeout</action>
237 </button>
238 </hbox>
239 <hbox>
240 <text wrap=\"false\">
241 <label>\"`gettext "Color:"` \"</label>
242 </text>
243 <entry>
244 <input>cat /boot/grub/menu.lst | grep ^color | cut -d \" \" -f2-3</input>
245 <variable>GRUB_COLOR</variable>
246 </entry>
247 <button>
248 <label>`gettext "Change"`</label>
249 <input file icon=\"forward\"></input>
250 <action>$0 sed_grub_color</action>
251 </button>
252 </hbox>
253 <hbox>
254 <text wrap=\"false\">
255 <label>\"`gettext "Configuration file:"`\"</label>
256 </text>
257 <button>
258 <label>/boot/grub/menu.lst</label>
259 <input file icon=\"accessories-text-editor\"></input>
260 <action>leafpad /boot/grub/menu.lst</action>
261 <action>refresh:GRUB_COLOR</action>
262 <action>refresh:GRUB_TIMEOUT</action>
263 </button>
264 </hbox>
265 </frame>
266 </vbox>"
267 # Init script.
268 MAIN_DIALOG=${MAIN_DIALOG}"
269 <vbox>
270 <frame `gettext "rcS init scripts"`>
271 <hbox>
272 <text wrap=\"false\">
273 <label>\"`gettext "Check filesystems:"`\"</label>
274 </text>
275 <entry>
276 <input>echo $CHECK_FS</input>
277 <variable>NEW_CHECK_FS</variable>
278 </entry>
279 <button>
280 <label>Change</label>
281 <input file icon=\"forward\"></input>
282 <action>$0 sed_check_fs</action>
283 </button>
284 </hbox>
285 <hbox>
286 <text wrap=\"false\">
287 <label>\"`gettext "Load modules:"` \"</label>
288 </text>
289 <entry>
290 <input>echo $LOAD_MODULES</input>
291 <variable>NEW_MODULES</variable>
292 </entry>
293 <button>
294 <label>`gettext "Change"`</label>
295 <input file icon=\"forward\"></input>
296 <action>$0 sed_load_modules</action>
297 </button>
298 </hbox>
299 <hbox>
300 <text wrap=\"false\">
301 <label>\"`gettext "Run daemons:"` \"</label>
302 </text>
303 <entry>
304 <input>echo $RUN_DAEMONS</input>
305 <variable>NEW_DAEMONS</variable>
306 </entry>
307 <button>
308 <label>`gettext "Change"`</label>
309 <input file icon=\"forward\"></input>
310 <action>$0 sed_run_daemons</action>
311 </button>
312 </hbox>
313 <hbox>
314 <text wrap=\"false\">
315 <label>\"`gettext "Add local commands:"`\"</label>
316 </text>
317 <button>
318 <label>/etc/init.d/local.sh</label>
319 <input file icon=\"accessories-text-editor\"></input>
320 <action>leafpad /etc/init.d/local.sh</action>
321 </button>
322 </hbox>
323 </frame>
324 </vbox>"
325 # Slim login.
326 MAIN_DIALOG=${MAIN_DIALOG}'
327 <vbox>
328 <frame '`gettext "Slim settings"`'>
329 <hbox>
330 <text wrap="false">
331 <label>"'`gettext "Sessions:"`' "</label>
332 </text>
333 <entry>
334 <input>cat /etc/slim.conf | grep ^session | sed s/"sessions. *"//</input>
335 <variable>SLIM_SESSIONS</variable>
336 </entry>
337 <button>
338 <label>'`gettext "Change"`'</label>
339 <input file icon="forward"></input>
340 <action>sed -i "s/^sessions.*/sessions $SLIM_SESSIONS/" /etc/slim.conf</action>
341 </button>
342 </hbox>
343 <hbox>
344 <text wrap="false">
345 <label>"'`gettext "Default user:"`' "</label>
346 </text>
347 <entry>
348 <input>cat /etc/slim.conf | grep ^default_user | sed s/"default_user. *"//</input>
349 <variable>SLIM_DEF_USER</variable>
350 </entry>
351 <button>
352 <label>'`gettext "Change"`'</label>
353 <input file icon="forward"></input>
354 <action>sed -i "s/^default_user.*/default_user $SLIM_DEF_USER/" /etc/slim.conf</action>
355 </button>
356 </hbox>
357 <hbox>
358 <text wrap="false">
359 <label>"'`gettext "Auto login (yes|no):"`' "</label>
360 </text>
361 <entry max_length="3">
362 <input>cat /etc/slim.conf | grep ^auto_login | sed s/"auto_login. *"//</input>
363 <variable>SLIM_AUTO_LOGIN</variable>
364 </entry>
365 <button>
366 <label>'`gettext "Change"`'</label>
367 <input file icon="forward"></input>
368 <action>sed -i "s/^auto_login.*/auto_login $SLIM_AUTO_LOGIN/" /etc/slim.conf</action>
369 </button>
370 </hbox>
371 <hbox>
372 <text wrap="false">
373 <label>"'`gettext "Theme:"`'"</label>
374 </text>
375 <combobox>
376 <variable>NEW_SLIM_THEME</variable>'
377 # List all installed Slim themes.
378 for dir in $(ls /usr/share/slim/themes)
379 do
380 THEME_ITEMS="<item>$dir</item>"
381 MAIN_DIALOG=${MAIN_DIALOG}${THEME_ITEMS}
382 done
383 MAIN_DIALOG=${MAIN_DIALOG}'
384 </combobox>
385 <button>
386 <label>'`gettext "Preview"`'</label>
387 <input file icon="video-display"></input>
388 <action>slim -p /usr/share/slim/themes/$NEW_SLIM_THEME &</action>
389 </button>
390 <button>
391 <label>'`gettext "Change"`'</label>
392 <input file icon="forward"></input>
393 <action>sed -i "s/^current_theme.*/current_theme $NEW_SLIM_THEME/" /etc/slim.conf</action>
394 <action>refresh:SLIM_THEME</action>
395 </button>
396 </hbox>
397 <hbox>
398 <text wrap="false">
399 <label>"'`gettext "Configuration file:"`'"</label>
400 </text>
401 <button>
402 <label>/etc/slim.conf</label>
403 <input file icon="accessories-text-editor"></input>
404 <action>leafpad /etc/slim.conf</action>
405 <action>refresh:SLIM_SESSIONS</action>
406 <action>refresh:SLIM_DEF_USER</action>
407 </button>
408 </hbox>
409 </frame>
410 </vbox>'
411 # Time settings.
412 MAIN_DIALOG=${MAIN_DIALOG}'
413 <vbox>
414 <frame '`gettext "Date and time"`'>
415 <hbox>
416 <text wrap="false">
417 <label>"'`gettext "System time:"`' "</label>
418 </text>
419 <entry editable="false">
420 <input>LC_ALL=C date</input>
421 <variable>DATE</variable>
422 </entry>
423 <button>
424 <label>'`gettext "Sync online"`'</label>
425 <input file icon="reload"></input>
426 <action>rdate -s tick.greyware.com</action>
427 <action>refresh:DATE</action>
428 <action>refresh:HWTIME</action>
429 </button>
430 </hbox>
431 <hbox>
432 <text wrap="false">
433 <label>"'`gettext "Hardware time:"`'"</label>
434 </text>
435 <entry editable="false">
436 <input>LC_ALL=C hwclock</input>
437 <variable>HWTIME</variable>
438 </entry>
439 <button>
440 <label>'`gettext "Set from system"`'</label>
441 <input file icon="reload"></input>
442 <action>hwclock -w -u</action>
443 <action>refresh:HWTIME</action>
444 <action>refresh:DATE</action>
445 </button>
446 </hbox>
447 <hbox>
448 <text wrap="true">
449 <label>"'`gettext "Timezone:"`' "</label>
450 </text>
451 <entry>
452 <input>cat /etc/TZ</input>
453 <variable>NEW_TZ</variable>
454 </entry>
455 <button>
456 <label>'`gettext "Change"`'</label>
457 <input file icon="forward"></input>
458 <action>echo "$NEW_TZ" > /etc/TZ</action>
459 </button>
460 </hbox>
461 </frame>
462 </vbox>'
463 # Language settings.
464 MAIN_DIALOG=${MAIN_DIALOG}"
465 <vbox>
466 <tree>
467 <width>600</width><height>210</height>
468 <variable>LANGUAGE</variable>
469 <label>`gettext "Language|Charmap"`</label>
470 <input icon_column=\"0\">$0 list_locales</input>
471 <action>$0 gen_utf8_locale</action>
472 </tree>
473 <hbox>
474 <text width-chars=\"60\">
475 <label>
476 \"`gettext "To change the system language you can double-click on the locale name."`\"
477 </label>
478 </text>
479 <button>
480 <label>`gettext "Keymap"`</label>
481 <input file icon=\"input-keyboard\"></input>
482 <action>tazkeymap &</action>
483 </button>
484 </hbox>
485 </vbox>"
486 # Display users list through get_users.
487 MAIN_DIALOG=${MAIN_DIALOG}"
488 <vbox>
489 <tree>
490 <width>600</width><height>210</height>
491 <variable>USER</variable>
492 <label>`gettext "Login|uid:gid|Name|Home|SHell"`</label>
493 <input icon_column=\"0\">$0 get_users</input>
494 <action>$0 manage_user</action>
495 <action>refresh:USER</action>
496 </tree>
497 <hbox>
498 <text width-chars=\"60\">
499 <label>
500 \"`gettext "To change passwords or delete users you can double-click on the user name."`\"
501 </label>
502 </text>
503 <button>
504 <label>`gettext "Add newuser"`</label>
505 <input file icon=\"gtk-add\"></input>
506 <action>$0 add_user</action>
507 <action>refresh:USER</action>
508 </button>
509 </hbox>
510 </vbox>"
511 export MAIN_DIALOG=${MAIN_DIALOG}'
512 </notebook>
514 <hbox>
515 <button>
516 <label>'`gettext "Network"`'</label>
517 <input file icon="netbox"></input>
518 <action>netbox &</action>
519 </button>
520 <button>
521 <label>'`gettext "Wireless"`'</label>
522 <input file icon="network-wireless"></input>
523 <action>wifibox &</action>
524 </button>
525 <button>
526 <label>'`gettext "Packages"`'</label>
527 <input file icon="tazpkg"></input>
528 <action>tazpkgbox &</action>
529 </button>
530 <button>
531 <label>'`gettext "Hardware"`'</label>
532 <input file icon="computer"></input>
533 <action>tazhw box &</action>
534 </button>
535 <button>
536 <label>'`gettext "Server"`'</label>
537 <input file icon="utilities-system-monitor"></input>
538 <action>serverbox &</action>
539 </button>
540 <button>
541 <label>'`gettext "Storage"`'</label>
542 <input file icon="media-flash"></input>
543 <action>mountbox &</action>
544 </button>
545 <button>
546 <label>'`gettext "Exit"`'</label>
547 <input file icon="exit"></input>
548 <action type="exit">Exit</action>
549 </button>
550 </hbox>
552 </vbox>
554 </window>'
556 # Script can be called with an arg to exec a function.
557 if [ -n "$1" ]; then
558 $1
559 else
560 gtkdialog --center --program=MAIN_DIALOG >/dev/null
561 fi
563 exit 0