slitaz-tools view tinyutils/tazctrlbox @ rev 361

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