slitaz-tools view tinyutils/tazctrlbox @ rev 516

tazx: incorrect tux; slitaz installer creates 1008 user
author Rohit Joshi <jozee@slitaz.org>
date Wed Nov 10 20:26:12 2010 -0500 (2010-11-10)
parents ab795ec4f9c1
children f55199628729
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>rmdir /home/$NEW_USER</action>
167 <action>cp -a /etc/skel /home/$NEW_USER</action>
168 <action>cp /root/.xinitrc /home/$NEW_USER</action>
169 <action>mkdir -p /home/$NEW_USER/.config/slitaz</action>
170 <action>cp -a /etc/slitaz/applications.conf /home/$NEW_USER/.config/slitaz</action>
171 <action>chown -R $NEW_USER:$NEW_USER /home/$NEW_USER</action>
172 <action type="closewindow">MANAGE_USER</action>
173 </button>
174 <button cancel>
175 <action type="closewindow">MANAGE_USER</action>
176 </button>
177 </hbox>
178 </vbox>
179 </window>
180 '
181 gtkdialog --center --program=ADD_USER_DIALOG >/dev/null
182 }
184 # i18n functions.
185 list_locales()
186 {
187 cd /usr/share/i18n/locales
188 for locale in `ls -1 [a-z][a-z]_[A-Z][A-Z]`
189 do
190 echo "preferences-desktop-locale | $locale | UTF-8"
191 done
192 }
193 gen_utf8_locale()
194 {
195 rm -rf /usr/lib/locale/$LANGUAGE
196 localedef -i $LANGUAGE -c -f UTF-8 /usr/lib/locale/$LANGUAGE
197 # System configuration
198 echo "LANG=$LANGUAGE" > /etc/locale.conf
199 echo "LC_ALL=$LANGUAGE" >> /etc/locale.conf
200 }
202 # Main dialog with notebook.
203 #
204 export MAIN_DIALOG='
205 <window title="'`gettext "SliTaz Control Box"`'" icon-name="computer">
206 <vbox>
208 <hbox>
209 <text use-markup="true">
210 <label>"'`gettext "<b>SliTaz Control Box</b>"`'"</label>
211 </text>
212 <pixmap>
213 <input file>/usr/share/pixmaps/tazctrlbox.png</input>
214 </pixmap>
215 </hbox>
217 <notebook labels="'`gettext "Boot loader|Initialization|Login manager|Time|Language|Users"`'">'
219 # GRUB.
220 MAIN_DIALOG=${MAIN_DIALOG}"
221 <vbox>
222 <frame `gettext "Grub boot loader"`>
223 <hbox>
224 <text wrap=\"false\">
225 <label>\"`gettext "Timeout:"`\"</label>
226 </text>
227 <entry>
228 <input>cat /boot/grub/menu.lst | grep ^timeout | cut -d \" \" -f2</input>
229 <variable>GRUB_TIMEOUT</variable>
230 </entry>
231 <button>
232 <label>`gettext "Change"`</label>
233 <input file icon=\"forward\"></input>
234 <action>$0 sed_grub_timeout</action>
235 </button>
236 </hbox>
237 <hbox>
238 <text wrap=\"false\">
239 <label>\"`gettext "Color:"` \"</label>
240 </text>
241 <entry>
242 <input>cat /boot/grub/menu.lst | grep ^color | cut -d \" \" -f2-3</input>
243 <variable>GRUB_COLOR</variable>
244 </entry>
245 <button>
246 <label>`gettext "Change"`</label>
247 <input file icon=\"forward\"></input>
248 <action>$0 sed_grub_color</action>
249 </button>
250 </hbox>
251 <hbox>
252 <text wrap=\"false\">
253 <label>\"`gettext "Configuration file:"`\"</label>
254 </text>
255 <button>
256 <label>/boot/grub/menu.lst</label>
257 <input file icon=\"accessories-text-editor\"></input>
258 <action>leafpad /boot/grub/menu.lst</action>
259 <action>refresh:GRUB_COLOR</action>
260 <action>refresh:GRUB_TIMEOUT</action>
261 </button>
262 </hbox>
263 </frame>
264 </vbox>"
265 # Init script.
266 MAIN_DIALOG=${MAIN_DIALOG}"
267 <vbox>
268 <frame `gettext "rcS init scripts"`>
269 <hbox>
270 <text wrap=\"false\">
271 <label>\"`gettext "Check filesystems:"`\"</label>
272 </text>
273 <entry>
274 <input>echo $CHECK_FS</input>
275 <variable>NEW_CHECK_FS</variable>
276 </entry>
277 <button>
278 <label>Change</label>
279 <input file icon=\"forward\"></input>
280 <action>$0 sed_check_fs</action>
281 </button>
282 </hbox>
283 <hbox>
284 <text wrap=\"false\">
285 <label>\"`gettext "Load modules:"` \"</label>
286 </text>
287 <entry>
288 <input>echo $LOAD_MODULES</input>
289 <variable>NEW_MODULES</variable>
290 </entry>
291 <button>
292 <label>`gettext "Change"`</label>
293 <input file icon=\"forward\"></input>
294 <action>$0 sed_load_modules</action>
295 </button>
296 </hbox>
297 <hbox>
298 <text wrap=\"false\">
299 <label>\"`gettext "Run daemons:"` \"</label>
300 </text>
301 <entry>
302 <input>echo $RUN_DAEMONS</input>
303 <variable>NEW_DAEMONS</variable>
304 </entry>
305 <button>
306 <label>`gettext "Change"`</label>
307 <input file icon=\"forward\"></input>
308 <action>$0 sed_run_daemons</action>
309 </button>
310 </hbox>
311 <hbox>
312 <text wrap=\"false\">
313 <label>\"`gettext "Add local commands:"`\"</label>
314 </text>
315 <button>
316 <label>/etc/init.d/local.sh</label>
317 <input file icon=\"accessories-text-editor\"></input>
318 <action>leafpad /etc/init.d/local.sh</action>
319 </button>
320 </hbox>
321 </frame>
322 </vbox>"
323 # Slim login.
324 MAIN_DIALOG=${MAIN_DIALOG}'
325 <vbox>
326 <frame '`gettext "Slim settings"`'>
327 <hbox>
328 <text wrap="false">
329 <label>"'`gettext "Sessions:"`' "</label>
330 </text>
331 <entry>
332 <input>cat /etc/slim.conf | grep ^session | sed s/"sessions. *"//</input>
333 <variable>SLIM_SESSIONS</variable>
334 </entry>
335 <button>
336 <label>'`gettext "Change"`'</label>
337 <input file icon="forward"></input>
338 <action>sed -i "s/^sessions.*/sessions $SLIM_SESSIONS/" /etc/slim.conf</action>
339 </button>
340 </hbox>
341 <hbox>
342 <text wrap="false">
343 <label>"'`gettext "Default user:"`' "</label>
344 </text>
345 <entry>
346 <input>cat /etc/slim.conf | grep ^default_user | sed s/"default_user. *"//</input>
347 <variable>SLIM_DEF_USER</variable>
348 </entry>
349 <button>
350 <label>'`gettext "Change"`'</label>
351 <input file icon="forward"></input>
352 <action>sed -i "s/^default_user.*/default_user $SLIM_DEF_USER/" /etc/slim.conf</action>
353 </button>
354 </hbox>
355 <hbox>
356 <text wrap="false">
357 <label>"'`gettext "Auto login (yes|no):"`' "</label>
358 </text>
359 <entry max_length="3">
360 <input>cat /etc/slim.conf | grep ^auto_login | sed s/"auto_login. *"//</input>
361 <variable>SLIM_AUTO_LOGIN</variable>
362 </entry>
363 <button>
364 <label>'`gettext "Change"`'</label>
365 <input file icon="forward"></input>
366 <action>sed -i "s/^auto_login.*/auto_login $SLIM_AUTO_LOGIN/" /etc/slim.conf</action>
367 </button>
368 </hbox>
369 <hbox>
370 <text wrap="false">
371 <label>"'`gettext "Theme:"`'"</label>
372 </text>
373 <combobox>
374 <variable>NEW_SLIM_THEME</variable>'
375 # List all installed Slim themes.
376 for dir in $(ls /usr/share/slim/themes)
377 do
378 THEME_ITEMS="<item>$dir</item>"
379 MAIN_DIALOG=${MAIN_DIALOG}${THEME_ITEMS}
380 done
381 MAIN_DIALOG=${MAIN_DIALOG}'
382 </combobox>
383 <button>
384 <label>'`gettext "Preview"`'</label>
385 <input file icon="video-display"></input>
386 <action>slim -p /usr/share/slim/themes/$NEW_SLIM_THEME &</action>
387 </button>
388 <button>
389 <label>'`gettext "Change"`'</label>
390 <input file icon="forward"></input>
391 <action>sed -i "s/^current_theme.*/current_theme $NEW_SLIM_THEME/" /etc/slim.conf</action>
392 <action>refresh:SLIM_THEME</action>
393 </button>
394 </hbox>
395 <hbox>
396 <text wrap="false">
397 <label>"'`gettext "Configuration file:"`'"</label>
398 </text>
399 <button>
400 <label>/etc/slim.conf</label>
401 <input file icon="accessories-text-editor"></input>
402 <action>leafpad /etc/slim.conf</action>
403 <action>refresh:SLIM_SESSIONS</action>
404 <action>refresh:SLIM_DEF_USER</action>
405 </button>
406 </hbox>
407 </frame>
408 </vbox>'
409 # Time settings.
410 MAIN_DIALOG=${MAIN_DIALOG}'
411 <vbox>
412 <frame '`gettext "Date and time"`'>
413 <hbox>
414 <text wrap="false">
415 <label>"'`gettext "System time:"`' "</label>
416 </text>
417 <entry editable="false">
418 <input>LC_ALL=C date</input>
419 <variable>DATE</variable>
420 </entry>
421 <button>
422 <label>'`gettext "Sync online"`'</label>
423 <input file icon="reload"></input>
424 <action>rdate -s tick.greyware.com</action>
425 <action>refresh:DATE</action>
426 <action>refresh:HWTIME</action>
427 </button>
428 </hbox>
429 <hbox>
430 <text wrap="false">
431 <label>"'`gettext "Hardware time:"`'"</label>
432 </text>
433 <entry editable="false">
434 <input>LC_ALL=C hwclock</input>
435 <variable>HWTIME</variable>
436 </entry>
437 <button>
438 <label>'`gettext "Set from system"`'</label>
439 <input file icon="reload"></input>
440 <action>hwclock -w -u</action>
441 <action>refresh:HWTIME</action>
442 <action>refresh:DATE</action>
443 </button>
444 </hbox>
445 <hbox>
446 <text wrap="true">
447 <label>"'`gettext "Timezone:"`' "</label>
448 </text>
449 <entry>
450 <input>cat /etc/TZ</input>
451 <variable>NEW_TZ</variable>
452 </entry>
453 <button>
454 <label>'`gettext "Change"`'</label>
455 <input file icon="forward"></input>
456 <action>echo "$NEW_TZ" > /etc/TZ</action>
457 </button>
458 </hbox>
459 </frame>
460 </vbox>'
461 # Language settings.
462 MAIN_DIALOG=${MAIN_DIALOG}"
463 <vbox>
464 <tree>
465 <width>600</width><height>210</height>
466 <variable>LANGUAGE</variable>
467 <label>`gettext "Language|Charmap"`</label>
468 <input icon_column=\"0\">$0 list_locales</input>
469 <action>$0 gen_utf8_locale</action>
470 </tree>
471 <hbox>
472 <text width-chars=\"60\">
473 <label>
474 \"`gettext "To change the system language you can double-click on the locale name."`\"
475 </label>
476 </text>
477 <button>
478 <label>`gettext "Keymap"`</label>
479 <input file icon=\"input-keyboard\"></input>
480 <action>tazkeymap &</action>
481 </button>
482 </hbox>
483 </vbox>"
484 # Display users list through get_users.
485 MAIN_DIALOG=${MAIN_DIALOG}"
486 <vbox>
487 <tree>
488 <width>600</width><height>210</height>
489 <variable>USER</variable>
490 <label>`gettext "Login|uid:gid|Name|Home|SHell"`</label>
491 <input icon_column=\"0\">$0 get_users</input>
492 <action>$0 manage_user</action>
493 <action>refresh:USER</action>
494 </tree>
495 <hbox>
496 <text width-chars=\"60\">
497 <label>
498 \"`gettext "To change passwords or delete users you can double-click on the user name."`\"
499 </label>
500 </text>
501 <button>
502 <label>`gettext "Add newuser"`</label>
503 <input file icon=\"gtk-add\"></input>
504 <action>$0 add_user</action>
505 <action>refresh:USER</action>
506 </button>
507 </hbox>
508 </vbox>"
509 export MAIN_DIALOG=${MAIN_DIALOG}'
510 </notebook>
512 <hbox>
513 <button>
514 <label>'`gettext "Network"`'</label>
515 <input file icon="netbox"></input>
516 <action>netbox &</action>
517 </button>
518 <button>
519 <label>'`gettext "Wireless"`'</label>
520 <input file icon="network-wireless"></input>
521 <action>wifibox &</action>
522 </button>
523 <button>
524 <label>'`gettext "Packages"`'</label>
525 <input file icon="tazpkg"></input>
526 <action>tazpkgbox &</action>
527 </button>
528 <button>
529 <label>'`gettext "Hardware"`'</label>
530 <input file icon="computer"></input>
531 <action>tazhw box &</action>
532 </button>
533 <button>
534 <label>'`gettext "Server"`'</label>
535 <input file icon="utilities-system-monitor"></input>
536 <action>serverbox &</action>
537 </button>
538 <button>
539 <label>'`gettext "Storage"`'</label>
540 <input file icon="media-flash"></input>
541 <action>mountbox &</action>
542 </button>
543 <button>
544 <label>'`gettext "Exit"`'</label>
545 <input file icon="exit"></input>
546 <action type="exit">Exit</action>
547 </button>
548 </hbox>
550 </vbox>
552 </window>'
554 # Script can be called with an arg to exec a function.
555 if [ -n "$1" ]; then
556 $1
557 else
558 gtkdialog --center --program=MAIN_DIALOG >/dev/null
559 fi
561 exit 0