slitaz-tools view tinyutils/tazctrlbox @ rev 471

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