slitaz-tools view tinyutils/tazctrlbox @ rev 296

desktopbox: Add autostart (GUI to enable/disable apps started with Openbox)
author Christophe Lincoln <pankso@slitaz.org>
date Sat Feb 21 22:33:58 2009 +0100 (2009-02-21)
parents e1be96425578
children e53d5618c5da
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 "$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>"Date: "</label>
209 </text>
210 <entry editable="false" has_frame="false">
211 <input>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="true">
223 <label>"Timezone:"</label>
224 </text>
225 <entry>
226 <input>cat /etc/TZ</input>
227 <variable>NEW_TZ</variable>
228 </entry>
229 <button>
230 <label>Change</label>
231 <input file icon="forward"></input>
232 <action>echo "$NEW_TZ" > /etc/TZ</action>
233 </button>
234 </hbox>
235 </frame>
236 </vbox>'
237 # Boot
238 MAIN_DIALOG=${MAIN_DIALOG}"
239 <vbox>
240 <frame Grub boot loader>
241 <hbox>
242 <text wrap=\"false\">
243 <label>\"Timeout:\"</label>
244 </text>
245 <entry>
246 <input>cat /boot/grub/menu.lst | grep ^timeout | cut -d \" \" -f2</input>
247 <variable>GRUB_TIMEOUT</variable>
248 </entry>
249 <button>
250 <label>Change</label>
251 <input file icon=\"forward\"></input>
252 <action>$0 sed_grub_timeout</action>
253 </button>
254 </hbox>
255 <hbox>
256 <text wrap=\"false\">
257 <label>\"Color: \"</label>
258 </text>
259 <entry>
260 <input>cat /boot/grub/menu.lst | grep ^color | cut -d \" \" -f2-3</input>
261 <variable>GRUB_COLOR</variable>
262 </entry>
263 <button>
264 <label>Change</label>
265 <input file icon=\"forward\"></input>
266 <action>$0 sed_grub_color</action>
267 </button>
268 </hbox>
269 <hbox>
270 <text wrap=\"false\">
271 <label>\"Configuration file:\"</label>
272 </text>
273 <button>
274 <label>/boot/grub/menu.lst</label>
275 <input file icon=\"accessories-text-editor\"></input>
276 <action>leafpad /boot/grub/menu.lst</action>
277 <action>refresh:GRUB_COLOR</action>
278 <action>refresh:GRUB_TIMEOUT</action>
279 </button>
280 </hbox>
281 </frame>
282 <frame rcS init scripts>
283 <hbox>
284 <text wrap=\"false\">
285 <label>\"Check filesystems:\"</label>
286 </text>
287 <entry>
288 <input>echo $CHECK_FS</input>
289 <variable>NEW_CHECK_FS</variable>
290 </entry>
291 <button>
292 <label>Change</label>
293 <input file icon=\"forward\"></input>
294 <action>$0 sed_check_fs</action>
295 </button>
296 </hbox>
297 <hbox>
298 <text wrap=\"false\">
299 <label>\"Load modules: \"</label>
300 </text>
301 <entry>
302 <input>echo $LOAD_MODULES</input>
303 <variable>NEW_MODULES</variable>
304 </entry>
305 <button>
306 <label>Change</label>
307 <input file icon=\"forward\"></input>
308 <action>$0 sed_load_modules</action>
309 </button>
310 </hbox>
311 <hbox>
312 <text wrap=\"false\">
313 <label>\"Run daemons: \"</label>
314 </text>
315 <entry>
316 <input>echo $RUN_DAEMONS</input>
317 <variable>NEW_DAEMONS</variable>
318 </entry>
319 <button>
320 <label>Change</label>
321 <input file icon=\"forward\"></input>
322 <action>$0 sed_run_daemons</action>
323 </button>
324 </hbox>
325 <hbox>
326 <text wrap=\"false\">
327 <label>\"Add local comands:\"</label>
328 </text>
329 <button>
330 <label>/etc/init.d/local.sh</label>
331 <input file icon=\"accessories-text-editor\"></input>
332 <action>leafpad /etc/init.d/local.sh</action>
333 </button>
334 </hbox>
335 </frame>
336 </vbox>"
337 # Login
338 MAIN_DIALOG=${MAIN_DIALOG}'
339 <vbox>
340 <frame Slim settings>
341 <hbox>
342 <text wrap="false">
343 <label>"Sessions: "</label>
344 </text>
345 <entry>
346 <input>cat /etc/slim.conf | grep ^session | sed s/"sessions "//</input>
347 <variable>SLIM_SESSIONS</variable>
348 </entry>
349 <button>
350 <label>Change</label>
351 <input file icon="forward"></input>
352 <action>sed -i "s/^sessions.*/sessions $SLIM_SESSIONS/" /etc/slim.conf</action>
353 </button>
354 </hbox>
355 <hbox>
356 <text wrap="false">
357 <label>"Default user: "</label>
358 </text>
359 <entry>
360 <input>cat /etc/slim.conf | grep ^default_user | sed s/"default_user "//</input>
361 <variable>SLIM_DEF_USER</variable>
362 </entry>
363 <button>
364 <label>Change</label>
365 <input file icon="forward"></input>
366 <action>sed -i "s/^default_user.*/default_user $SLIM_DEF_USER/" /etc/slim.conf</action>
367 </button>
368 </hbox>
369 <hbox>
370 <text wrap="false">
371 <label>"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>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>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>"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 # Display users list throught get_users.
410 MAIN_DIALOG=${MAIN_DIALOG}"
411 <vbox>
412 <tree>
413 <width>650</width><height>300</height>
414 <variable>USER</variable>
415 <label>Login|uid:gid|Name|Home|SHell</label>
416 <input>$0 get_users</input>
417 <action>$0 manage_user</action>
418 <action>refresh:USER</action>
419 </tree>
420 <hbox>
421 <text width-chars=\"60\">
422 <label>
423 \"Note: To change passwords and delete users you can double-click on the user name.\"
424 </label>
425 </text>
426 <button>
427 <label>Add newuser</label>
428 <input file icon=\"gtk-add\"></input>
429 <action>$0 add_user</action>
430 <action>refresh:USER</action>
431 </button>
432 </hbox>
433 </vbox>"
434 export MAIN_DIALOG=${MAIN_DIALOG}'
435 </notebook>
437 <hbox>
438 <button>
439 <label>Exit</label>
440 <input file icon="exit"></input>
441 <action type="exit">Exit</action>
442 </button>
443 </hbox>
445 </vbox>
447 </window>
448 '
450 # Script can be called with an arg to exec a function.
451 if [ -n "$1" ]; then
452 $1
453 else
454 gtkdialog --center --program=MAIN_DIALOG >/dev/null
455 fi
457 exit 0