slitaz-tools view tinyutils/tazctrlbox @ rev 312

tazctrlbox: improved date and time setting + users management
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 03 23:17:19 2009 +0100 (2009-03-03)
parents da1310b3627c
children 3a685ebc294f
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 # Change Grub menu.lst timeout.
23 sed_grub_timeout()
24 {
25 CURRENT=`cat /boot/grub/menu.lst | grep ^timeout | cut -d " " -f2`
26 sed -i s/"timeout $CURRENT"/"timeout $GRUB_TIMEOUT"/ /boot/grub/menu.lst
27 }
29 # Change Grub menu.lst timeout.
30 sed_grub_color()
31 {
32 CURRENT=`cat /boot/grub/menu.lst | grep ^color | cut -d " " -f2-3`
33 sed -i s#"color $CURRENT"#"color $GRUB_COLOR"# /boot/grub/menu.lst
34 }
36 # Set checked fs on boot.
37 sed_check_fs()
38 {
39 sed -i s#"CHECK_FS=\"$CHECK_FS\""#"CHECK_FS=\"$NEW_CHECK_FS\""# \
40 /etc/rcS.conf
41 }
43 # Set loaded modules on boot.
44 sed_load_modules()
45 {
46 sed -i s/"LOAD_MODULES=\"$LOAD_MODULES\""/"LOAD_MODULES=\"$NEW_MODULES\""/ \
47 /etc/rcS.conf
48 }
50 # Set daemons to run on boot.
51 sed_run_daemons()
52 {
53 sed -i s/"RUN_DAEMONS=\"$RUN_DAEMONS\""/"RUN_DAEMONS=\"$NEW_DAEMONS\""/ \
54 /etc/rcS.conf
55 }
57 # Get user list
58 get_users()
59 {
60 for i in `cat /etc/passwd | cut -d ":" -f 1`
61 do
62 if [ -d /home/$i ]; then
63 login=$i
64 uid=`cat /etc/passwd | grep $i | cut -d ":" -f 3`
65 gid=`cat /etc/passwd | grep $i | cut -d ":" -f 4`
66 name=`cat /etc/passwd | grep $i | cut -d ":" -f 5 | sed s/,,,//`
67 home=`cat /etc/passwd | grep $i | cut -d ":" -f 6`
68 shell=`cat /etc/passwd | grep $i | cut -d ":" -f 7`
69 echo "system-users | $login | $uid:$gid | $name | $home | $shell"
70 fi
71 done
72 }
74 # Remove a user or change passwd.
75 manage_user()
76 {
77 export MANAGE_DIALOG="
78 <window title=\"Manage user: $USER\" icon-name=\"computer\">
79 <vbox>
80 <hbox>
81 <text wrap=\"false\" width-chars=\"34\">
82 <label>\"
83 Login name: $USER
84 \"</label>
85 </text>
86 </hbox>
87 <hbox>
88 <text wrap=\"false\">
89 <label>\"New password:\"</label>
90 </text>
91 <entry invisible_char=\"*\" visibility=\"false\">
92 <variable>PASSWD</variable>
93 </entry>
94 <button>
95 <label>Change</label>
96 <input file icon=\"forward\"></input>
97 <action>echo \"$USER:$PASSWD\" | chpasswd</action>
98 <action type=\"closewindow\">MANAGE_USER</action>
99 </button>
100 </hbox>
101 <hbox>
102 <button>
103 <label>Delete user</label>
104 <input file icon=\"gtk-delete\"></input>
105 <action>deluser $USER</action>
106 <action type=\"closewindow\">MANAGE_USER</action>
107 </button>
108 <button cancel>
109 <action type=\"closewindow\">MANAGE_USER</action>
110 </button>
111 </hbox>
112 </vbox>
113 </window>
114 "
115 gtkdialog --center --program=MANAGE_DIALOG >/dev/null
116 }
118 # Add a new user.
119 add_user()
120 {
121 export ADD_USER_DIALOG='
122 <window title="New user" icon-name="gtk-add">
123 <vbox>
124 <hbox>
125 <text wrap="false" width-chars="34">
126 <label>"
127 New account information
128 "</label>
129 </text>
130 </hbox>
131 <hbox>
132 <text wrap="false">
133 <label>"Login: "</label>
134 </text>
135 <entry>
136 <variable>NEW_USER</variable>
137 </entry>
138 </hbox>
139 <hbox>
140 <text wrap="false">
141 <label>"Password:"</label>
142 </text>
143 <entry invisible_char="*" visibility="false">
144 <variable>PASSWD</variable>
145 </entry>
146 </hbox>
147 <hbox>
148 <button ok>
149 <action>adduser -D $NEW_USER</action>
150 <action>echo "$NEW_USER:$PASSWD" | chpasswd</action>
151 <action>adduser -G audio $NEW_USER</action>
152 <action>rmdir /home/$NEW_USER</action>
153 <action>cp -a /etc/skel /home/$NEW_USER</action>
154 <action>cp /root/.xinitrc /home/$NEW_USER</action>
155 <action>chown -R $NEW_USER:$NEW_USER /home/$NEW_USER</action>
156 <action type="closewindow">MANAGE_USER</action>
157 </button>
158 <button cancel>
159 <action type="closewindow">MANAGE_USER</action>
160 </button>
161 </hbox>
162 </vbox>
163 </window>
164 '
165 gtkdialog --center --program=ADD_USER_DIALOG >/dev/null
166 }
168 # Main dialog with notebook.
169 #
170 export MAIN_DIALOG='
171 <window title="SliTaz Control Box" icon-name="computer">
172 <vbox>
174 <hbox>
175 <text use-markup="true">
176 <label>"<b>SliTaz Control Box</b>"</label>
177 </text>
178 <pixmap>
179 <input file>/usr/share/pixmaps/tazctrlbox.png</input>
180 </pixmap>
181 </hbox>
183 <notebook labels="System|Boot|Login|Users">
185 <vbox>
186 <frame Boxes panel>
187 <hbox>
188 <button>
189 <label>Devices Manager</label>
190 <input file icon="media-flash"></input>
191 <action>mountbox &</action>
192 </button>
193 <button>
194 <label>Network configuration</label>
195 <input file icon="netbox"></input>
196 <action>netbox &</action>
197 </button>
198 <button>
199 <label>Packages Manager</label>
200 <input file icon="tazpkg"></input>
201 <action>tazpkgbox &</action>
202 </button>
203 </hbox>
204 </frame>
205 <frame Date and time>
206 <hbox>
207 <text wrap="false">
208 <label>"System time: "</label>
209 </text>
210 <entry editable="false">
211 <input>LC_ALL=C date</input>
212 <variable>DATE</variable>
213 </entry>
214 <button>
215 <label>Sync online</label>
216 <input file icon="reload"></input>
217 <action>rdate -s tick.greyware.com</action>
218 <action>refresh:DATE</action>
219 </button>
220 </hbox>
221 <hbox>
222 <text wrap="false">
223 <label>"Hardware time:"</label>
224 </text>
225 <entry editable="false">
226 <input>LC_ALL=C hwclock</input>
227 <variable>HWTIME</variable>
228 </entry>
229 <button>
230 <label>System to HW</label>
231 <input file icon="reload"></input>
232 <action>hwclock -w</action>
233 <action>refresh:HWTIME</action>
234 </button>
235 </hbox>
236 <hbox>
237 <text wrap="true">
238 <label>"Timezone: "</label>
239 </text>
240 <entry>
241 <input>cat /etc/TZ</input>
242 <variable>NEW_TZ</variable>
243 </entry>
244 <button>
245 <label>Change</label>
246 <input file icon="forward"></input>
247 <action>echo "$NEW_TZ" > /etc/TZ</action>
248 </button>
249 </hbox>
250 </frame>
251 </vbox>'
252 # Boot
253 MAIN_DIALOG=${MAIN_DIALOG}"
254 <vbox>
255 <frame Grub boot loader>
256 <hbox>
257 <text wrap=\"false\">
258 <label>\"Timeout:\"</label>
259 </text>
260 <entry>
261 <input>cat /boot/grub/menu.lst | grep ^timeout | cut -d \" \" -f2</input>
262 <variable>GRUB_TIMEOUT</variable>
263 </entry>
264 <button>
265 <label>Change</label>
266 <input file icon=\"forward\"></input>
267 <action>$0 sed_grub_timeout</action>
268 </button>
269 </hbox>
270 <hbox>
271 <text wrap=\"false\">
272 <label>\"Color: \"</label>
273 </text>
274 <entry>
275 <input>cat /boot/grub/menu.lst | grep ^color | cut -d \" \" -f2-3</input>
276 <variable>GRUB_COLOR</variable>
277 </entry>
278 <button>
279 <label>Change</label>
280 <input file icon=\"forward\"></input>
281 <action>$0 sed_grub_color</action>
282 </button>
283 </hbox>
284 <hbox>
285 <text wrap=\"false\">
286 <label>\"Configuration file:\"</label>
287 </text>
288 <button>
289 <label>/boot/grub/menu.lst</label>
290 <input file icon=\"accessories-text-editor\"></input>
291 <action>leafpad /boot/grub/menu.lst</action>
292 <action>refresh:GRUB_COLOR</action>
293 <action>refresh:GRUB_TIMEOUT</action>
294 </button>
295 </hbox>
296 </frame>
297 <frame rcS init scripts>
298 <hbox>
299 <text wrap=\"false\">
300 <label>\"Check filesystems:\"</label>
301 </text>
302 <entry>
303 <input>echo $CHECK_FS</input>
304 <variable>NEW_CHECK_FS</variable>
305 </entry>
306 <button>
307 <label>Change</label>
308 <input file icon=\"forward\"></input>
309 <action>$0 sed_check_fs</action>
310 </button>
311 </hbox>
312 <hbox>
313 <text wrap=\"false\">
314 <label>\"Load modules: \"</label>
315 </text>
316 <entry>
317 <input>echo $LOAD_MODULES</input>
318 <variable>NEW_MODULES</variable>
319 </entry>
320 <button>
321 <label>Change</label>
322 <input file icon=\"forward\"></input>
323 <action>$0 sed_load_modules</action>
324 </button>
325 </hbox>
326 <hbox>
327 <text wrap=\"false\">
328 <label>\"Run daemons: \"</label>
329 </text>
330 <entry>
331 <input>echo $RUN_DAEMONS</input>
332 <variable>NEW_DAEMONS</variable>
333 </entry>
334 <button>
335 <label>Change</label>
336 <input file icon=\"forward\"></input>
337 <action>$0 sed_run_daemons</action>
338 </button>
339 </hbox>
340 <hbox>
341 <text wrap=\"false\">
342 <label>\"Add local comands:\"</label>
343 </text>
344 <button>
345 <label>/etc/init.d/local.sh</label>
346 <input file icon=\"accessories-text-editor\"></input>
347 <action>leafpad /etc/init.d/local.sh</action>
348 </button>
349 </hbox>
350 </frame>
351 </vbox>"
352 # Login
353 MAIN_DIALOG=${MAIN_DIALOG}'
354 <vbox>
355 <frame Slim settings>
356 <hbox>
357 <text wrap="false">
358 <label>"Sessions: "</label>
359 </text>
360 <entry>
361 <input>cat /etc/slim.conf | grep ^session | sed s/"sessions "//</input>
362 <variable>SLIM_SESSIONS</variable>
363 </entry>
364 <button>
365 <label>Change</label>
366 <input file icon="forward"></input>
367 <action>sed -i "s/^sessions.*/sessions $SLIM_SESSIONS/" /etc/slim.conf</action>
368 </button>
369 </hbox>
370 <hbox>
371 <text wrap="false">
372 <label>"Default user: "</label>
373 </text>
374 <entry>
375 <input>cat /etc/slim.conf | grep ^default_user | sed s/"default_user "//</input>
376 <variable>SLIM_DEF_USER</variable>
377 </entry>
378 <button>
379 <label>Change</label>
380 <input file icon="forward"></input>
381 <action>sed -i "s/^default_user.*/default_user $SLIM_DEF_USER/" /etc/slim.conf</action>
382 </button>
383 </hbox>
384 <hbox>
385 <text wrap="false">
386 <label>"Theme:"</label>
387 </text>
388 <combobox>
389 <variable>NEW_SLIM_THEME</variable>'
390 # List all installed Slim themes.
391 for dir in $(ls /usr/share/slim/themes)
392 do
393 THEME_ITEMS="<item>$dir</item>"
394 MAIN_DIALOG=${MAIN_DIALOG}${THEME_ITEMS}
395 done
396 MAIN_DIALOG=${MAIN_DIALOG}'
397 </combobox>
398 <button>
399 <label>Preview</label>
400 <input file icon="video-display"></input>
401 <action>slim -p /usr/share/slim/themes/$NEW_SLIM_THEME &</action>
402 </button>
403 <button>
404 <label>Change</label>
405 <input file icon="forward"></input>
406 <action>sed -i "s/^current_theme.*/current_theme $NEW_SLIM_THEME/" /etc/slim.conf</action>
407 <action>refresh:SLIM_THEME</action>
408 </button>
409 </hbox>
410 <hbox>
411 <text wrap="false">
412 <label>"Configuration file:"</label>
413 </text>
414 <button>
415 <label>/etc/slim.conf</label>
416 <input file icon="accessories-text-editor"></input>
417 <action>leafpad /etc/slim.conf</action>
418 <action>refresh:SLIM_SESSIONS</action>
419 <action>refresh:SLIM_DEF_USER</action>
420 </button>
421 </hbox>
422 </frame>
423 </vbox>'
424 # Display users list throught get_users.
425 MAIN_DIALOG=${MAIN_DIALOG}"
426 <vbox>
427 <tree>
428 <width>650</width><height>300</height>
429 <variable>USER</variable>
430 <label>Login|uid:gid|Name|Home|SHell</label>
431 <input icon_column=\"0\">$0 get_users</input>
432 <action>$0 manage_user</action>
433 <action>refresh:USER</action>
434 </tree>
435 <hbox>
436 <text width-chars=\"66\">
437 <label>
438 \"Note: To change passwords and delete users you can double-click on the user name.\"
439 </label>
440 </text>
441 <button>
442 <label>Add newuser</label>
443 <input file icon=\"gtk-add\"></input>
444 <action>$0 add_user</action>
445 <action>refresh:USER</action>
446 </button>
447 </hbox>
448 </vbox>"
449 export MAIN_DIALOG=${MAIN_DIALOG}'
450 </notebook>
452 <hbox>
453 <button>
454 <label>Exit</label>
455 <input file icon="exit"></input>
456 <action type="exit">Exit</action>
457 </button>
458 </hbox>
460 </vbox>
462 </window>
463 '
465 # Script can be called with an arg to exec a function.
466 if [ -n "$1" ]; then
467 $1
468 else
469 gtkdialog --center --program=MAIN_DIALOG >/dev/null
470 fi
472 exit 0