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