slitaz-tools view tinyutils/tazx @ rev 929

tazx:tiny edit
author Paul Issott <paul@slitaz.org>
date Fri Nov 21 17:34:52 2014 +0000 (2014-11-21)
parents eb791cfb71c0
children 53389b39eefd
line source
1 #!/bin/sh
2 #
3 # Tazx - Ncurses X configuration for SliTaz GNU/Linux using Dialog boxes.
4 # This tinyutil is part of slitaz-tools. Tazx can configure Xorg with
5 # several Window Managers. The GTK interface to configure X is in tazbox.
6 #
7 # (c) 2011-2014 SliTaz GNU/Linux - GNU GPL v3.
8 # Authors: Christophe Lincoln <pankso@slitaz.org>
9 # Pascal Bellard <pascal.bellard@slitaz.org>
10 #
12 # 20140317: most xsession, xinitrc are obsolete, provided system files
13 # are in /etc/skel and WM config files should no longer be copied by
14 # tazx to user home. If some configs are needed by WMs they should
15 # be set by a /usr/bin/wmname-session script I guess. - Pankso
17 . /lib/libtaz.sh
18 . /etc/slitaz/slitaz.conf
19 . /etc/slitaz/applications.conf
21 export TEXTDOMAIN='slitaz-tools' #i18n
22 : ${DIALOG=dialog --timeout 60}
24 # Default user for config files in Live mode, id is 1000 since it is
25 # created by /etc/init.d/bootopts.sh.
27 USER=$(awk -F: '/1000/{print $1}' /etc/passwd)
30 #
31 # Functions
32 #
35 # Save chunk of xorg.conf into specified file
37 save_chunk() {
38 sed -e '/Section "'${1#*-}'"/,/EndSection/!d' \
39 -e "s/EndSection/&\n/" $xorg_template > \
40 $xorg_config/$1.conf
41 }
44 # Create a xorg.conf if needed
46 gen_xorg_conf_file() {
47 if [ ! -f /etc/X11/xorg.conf ]; then
48 cat > /etc/X11/xorg.conf << EOT
49 # You can put here your own Xorg configurations. This config file is read
50 # before all files in /etc/X11/xorg.conf.d and will NOT be erased by any
51 # updates.
52 EOT
53 fi
54 }
57 # Add or remove xkb applet from lxpanel
59 xkb() {
60 case $(id -u) in
61 0)
62 # Empty if lxpanel not running, else something like:
63 # tux lxpanel -p slitaz
64 LXPS=$(ps -ouser,args | sed -n '/[l]xpanel/ s| *| |p' | \
65 fgrep -v '[' | fgrep -v 'xkb' | fgrep -v 'sh')
67 # Stop lxpanel
68 if [ -n "$LXPS" ]; then
69 lxpanelctl exit
70 killall lxpanel
71 fi
73 # For all human users
74 for USER in $(awk -F: '/\/home\//{print $1}' /etc/passwd); do
75 su $USER -c '. ~/.profile; tazx xkb'
76 done
78 # Re-run lxpanel
79 [ -n "$LXPS" ] && su ${LXPS%% *} -c "exec ${LXPS#* }" &
80 ;;
82 *)
83 DOTCONFIG=${XDG_CONFIG_HOME:-$HOME/.config}
84 CFG_LXPANEL=$DOTCONFIG/lxpanel
86 if [ ! -d $CFG_LXPANEL ]; then
87 mkdir -p $DOTCONFIG
88 cp -r /etc/lxpanel $DOTCONFIG
89 fi
91 case $(fgrep 'XkbLayout' /etc/X11/xorg.conf.d/40-Keyboard.conf | \
92 fgrep -o ',') in
93 '')
94 for CFG in $(find $CFG_LXPANEL -type f -name panel); do
95 if [ -n "$(grep 'type = xkb' $CFG)" ]; then
96 echo "Remove xkb applet from $CFG"
97 sed -i "$(grep -n -e "^Plugin {" -e "^}" -e "xkb" \
98 $CFG | grep -C 1 xkb | grep -v xkb | cut -d: \
99 -f1 | tr '\n' ' ' | sed 's| |,|')d" $CFG
100 fi
101 done ;;
102 ',')
103 for CFG in $(find $CFG_LXPANEL -type f -name panel); do
104 if [ -z "$(grep 'type = xkb' $CFG)" ]; then
105 echo "Add xkb applet to $CFG"
106 XKB='Plugin {\
107 type = xkb\
108 Config {\
109 DisplayType=0\
110 PerWinLayout=0\
111 NoResetOpt=0\
112 KeepSysLayouts=1\
113 Model=pc105\
114 LayoutsList=us\
115 VariantsList=,\
116 ToggleOpt=shift_caps_toggle\
117 FlagSize=4\
118 }\
119 }\
120 '
121 sed -i "$(grep -n -e "^Plugin {" -e "tray" $CFG | \
122 grep -B1 tray | head -n1 | cut -d: -f1) i\\
123 $XKB" $CFG
124 fi
125 done ;;
126 esac ;;
127 esac
128 }
131 # Generate or regenerate 40-Keyboard.conf
133 keyboard_conf() {
134 # Configure the keyboard with the right keymap
135 keymap=$(cat /etc/keymap.conf)
136 keyboard_config="/etc/X11/xorg.conf.d/40-Keyboard.conf"
137 variant=""
139 # this XkbOption moved from 40-evdev.conf (xorg-xf86-input-evdev)
140 options="terminate:ctrl_alt_bksp"
141 _n 'Creating:'; echo -n " $keyboard_config"
142 mkdir -p $(dirname $keyboard_config)
144 case "$keymap" in
145 fr_CH-latin1)
146 # Swiss FrenCH
147 layout="ch"; variant="fr" ;;
148 uk)
149 # English UK
150 layout="gb" ;;
151 ru)
152 # Russian
153 layout="us,ru"
154 options="grp:ctrl_shift_toggle, grp_led:scroll, compose:ralt, $options" ;;
155 ua)
156 # Ukrainian
157 layout="us,ua,ru"
158 options="grp:ctrl_shift_toggle, compose:ralt, $options" ;;
159 slovene)
160 # Slovenian
161 layout="si"; options="grp:alt_shift_toggle, $options" ;;
162 us-acentos)
163 layout="us"; variant="intl" ;;
164 *)
165 # Use clean /etc/keymap.conf value.
166 keymap=${keymap%-latin1}
167 keymap=${keymap%-lat2}
168 keymap=${keymap%-lat6}
169 layout=${keymap%-abnt2}
170 esac
172 cat > $keyboard_config << EOC
173 Section "InputClass"
174 Identifier "Keyboard Defaults"
175 MatchIsKeyboard "yes"
176 Option "XkbLayout" "$layout"
177 Option "XkbVariant" "$variant"
178 Option "XkbOptions" "$options"
179 EndSection
180 EOC
182 status
183 [ -z "$variant" ] && sed -i '/XkbVariant/d' $keyboard_config
184 xkb
185 }
188 # Populate xorg.conf.d
190 xorg_conf_d() {
191 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
192 xorg_config=/etc/X11/xorg.conf.d
194 # Define the xorg.conf.new place.
195 xorg_template=/root/xorg.conf.new
197 # Obtain a default configuration file from Xorg.
198 Xorg -configure :2
200 # Backup existing config.
201 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
203 # Put the different sections in separate files in the config directory.
204 save_chunk 10-ServerLayout
205 sed -i '/Core/d' $xorg_config/10-ServerLayout.conf
206 save_chunk 20-Files
207 save_chunk 30-Module
208 save_chunk 50-Monitor
209 save_chunk 60-Device
210 save_chunk 70-Screen
212 # Remove the template.
213 rm $xorg_template
215 # Keyboard & xorg.conf
216 keyboard_conf
217 gen_xorg_conf_file
218 }
221 # Process dialog's return code.
223 dialog_end() {
224 retval=$?
225 exec 3>&-
226 # Continue or exit.
227 case $retval in
228 0|3) continue ;;
229 1|255) exit 0 ;;
230 esac
231 }
234 # Install xorg server.
236 install_xorg() {
237 [ -f "$PKGS_DB/packages.list" ] || tazpkg recharge
239 exec 3>&1
241 driver=$($DIALOG \
242 --clear --colors --scrollbar --title " $(_ 'Install Xorg') " \
243 --menu "$(_ 'Tazx helps you to select your X driver.')" 16 70 9 \
244 'auto' "$(_ 'Auto configuring')" \
245 $(fgrep xorg-xf86-video- $PKGS_DB/packages.list | cut -d- -f4 | \
246 sed "s|.*|& $(_ 'driver')|") \
247 'quit' "$(_ 'Quit')" \
248 2>&1 1>&3)
250 dialog_end
252 case $driver in
253 quit) exit 0 ;;
254 auto) autoselect_driver ;;
255 *)
256 inst_pkg xorg-server
257 inst_pkg xorg-xf86-video-$driver
258 xorg_conf_d ;;
259 esac
260 }
263 # Auto-select and install Xorg driver.
265 autoselect_driver() {
266 inst_pkg xorg-server
268 for VID in $(busybox lspci | grep 'Class 03' | cut -c21-24 | sort -u); do
269 case $VID in
270 1022|1002) d=ati ;;
271 8086) d=intel ;;
272 10de) d=nouveau ;;
273 1039) d=sis ;;
274 15ad) d=vmware ;;
275 *) d=''; $DIALOG --colors --msgbox \
276 "\n\Z1$(_n 'Failed to setup driver')\Zn $(_ '(unknown hardware)')" 7 68 ;;
277 esac
278 [ -n "$d" ] && inst_pkg xorg-xf86-video-$d
279 done
281 xorg_conf_d
282 }
285 # Install specified package.
287 inst_pkg() {
288 pkg="$@"
289 colorize 3 $(_ 'Installing pkg: $pkg')
291 case $(id -u) in
292 0) CMD="tazpkg -gi $@" ;;
293 *) CMD="sudo tazpkg -gi $@" ;;
294 esac
295 [ -d "$INSTALLED/$@" ] || $CMD
296 }
299 # Select/install Window Manager and favorite applications.
301 apps_dialog() {
302 . $user_conf
304 exec 3>&1
306 app=$($DIALOG --clear --colors --backtitle "$msg" \
307 --title "{\Z3 $(_n 'Install Window Manager and applications') \Zn}" \
308 --inputmenu "" 21 52 18 \
309 $(for a in WINDOW_MANAGER EDITOR BROWSER TERMINAL FILE_MANAGER; do
310 eval n='$'$a; echo $a $n;
311 done) 2>&1 1>&3)
312 dialog_end
314 case $app in
315 RENAMED) # like: RENAMED EDITOR myeditor
316 appname=$(echo $app | cut -d" " -f3)
317 app=$(echo $app | cut -d" " -f2) ;;
318 *)
319 app_name_dialog only-installed ;;
320 esac
322 if [ $appname != " " ]; then
323 if [ $appname = show_ALL ]; then
324 app_name_dialog full-list
325 fi
326 if [ -z $(busybox which $appname) ]; then
327 inst_pkg $(lzcat $PKGS_DB/files.list.lzma | fgrep /bin/$appname | head -n1 | cut -d: -f1)
328 fi
329 sed -i "/$app/ s|=.*$|=$appname|" $user_conf
330 fi
332 msg=''; apps_dialog # loop
333 }
336 # Show list of applications to choose.
338 app_name_dialog() {
339 case $1 in
340 full-list) height=24 ;;
341 *) height=18 ;;
342 esac
344 exec 3>&1
346 appname=$($DIALOG --clear --colors --title "$app" \
347 --menu '' $height 50 24 $(gen_applist $app $@) 2>&1 1>&3)
348 dialog_end
349 }
352 # Generate application list for Dialog or Yad.
354 gen_applist() {
355 # $1 = [ FILE_MANAGER | BROWSER | EDITOR | TERMINAL | WINDOW_MANAGER ]
356 # $2 = [ only-installed | full-list ]
357 # $3 = [ yad | * ]
359 . $user_conf
361 FILE_MANAGERS="clex caja emelfm2 mc pathfinder pcmanfm pcmanfm-qt ranger \
362 spacefm thunar xfe ytree"
364 BROWSERS="arora chrome cream dillo elinks firefox firefox-official iron \
365 links lynx midori netsurf opera QtWeb qupzilla retawq seamonkey surf tazweb"
367 EDITORS="adie beaver emacs geany jed joe juffed ht le leafpad mcedit \
368 mousepad mp-5 nano qedit SciTE vi vim xedit xfw zile"
370 TERMINALS="aterm evilvte lxterminal mrxvt qterminal sakura stjerm tilda \
371 urxvt vte xterm yeahconsole"
373 WINDOW_MANAGERS="awesome blackbox compiz dwm echinus enlightenment fluxbox \
374 icewm jwm lxde-session lxqt karmen matchbox openbox-session pekwm ratpoison \
375 xfwm4"
377 eval list='$'"$1"S
378 eval current='$'"$1"
380 for i in $current $(echo " $list " | sed "s| $current | |g"); do
382 case $(busybox which $i) in
383 '') # not installed
384 t='---' ;;
385 *) # installed
386 t='<--' ;;
387 esac
389 if [ "$2" == 'full-list' ] || [ "$t" == '<--' ]; then
390 echo "$i"
392 if [ "$3" != 'yad' ]; then
393 echo "$(echo $t | sed "s|---|$(_n 'Install')|g")"
394 fi
395 fi
396 done
398 if [ "$2" == 'only-installed' ] && [ "$3" != 'yad' ]; then
399 echo 'show_ALL' "+$(_n 'Install')"
400 fi
401 }
404 # Screen configuration dialog.
406 config_dialog() {
407 . /etc/rcS.conf
408 case $LOGIN_MANAGER in
409 slim) LM="$(_ 'ON')" ;;
410 *) LM="$(_ 'OFF')" ;;
411 esac
413 exec 3>&1
415 value=$($DIALOG \
416 --clear --colors \
417 --title "{ $(_n 'SliTaz Xorg config') }" \
418 --menu "" 16 72 10 \
419 "xorg" "$(_n 'Install or reconfigure Xorg')" \
420 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
421 "onboot" "$(_n 'AutoStart Xorg by SLiM on boot'): \Z5$LM\Zn" \
422 "slim" "$(_n '(Re)Start Simple Login Manager now')" \
423 "wm_apps" "$(_n 'Install Window Manager and applications')" \
424 "quit" "$(_n 'Quit Tazx utility')" \
425 2>&1 1>&3)
426 dialog_end
428 case "$value" in
429 xorg)
430 install_xorg ;;
432 xorg-light)
433 inst_pkg xorg-server-light
434 inst_pkg xorg-xf86-video-fbdev
435 xorg_conf_d ;;
437 onboot)
438 inst_pkg slim
439 inst_pkg dbus
441 if [ $LM == "$(_ 'OFF')" ]; then
442 LM='slim'
443 else
444 LM=''
445 fi
446 sed -i "/LOGIN_MANAGER/ s|=.*$|=$LM|" /etc/rcS.conf
448 [ -z "$LM" ] && LM='disabled'
449 _n "Start X on boot:"; boldify " $LM" ;;
451 slim)
452 inst_pkg slim
453 inst_pkg dbus
454 if [ -z $XAUTHORITY ]; then
455 stopd slim; sleep 2; startd slim
456 fi ;;
458 wm_apps)
459 slitaz_apps_conf
460 apps_dialog ;;
462 *)
463 exit 0 ;;
464 esac
465 }
468 # ~/.config/slitaz/applications.conf: Missing = failed to login
469 # Make users applications.conf in /etc/skel so new added user will get
470 # a working X session. Note --> flavors can have a custom config in
471 # /etc/slitaz/applications that we must use.
473 slitaz_apps_conf() {
474 apps_conf=/etc/slitaz/applications.conf
476 if [ "$(id -u)" = 0 ]; then
477 user_conf=$apps_conf
478 new_user_conf="/etc/skel/.config/slitaz/applications.conf"
479 mkdir -p $(dirname $new_user_conf)
480 cp -f $apps_conf $new_user_conf
481 else
482 # If started by: startx and with boot opts screen=text
483 user_conf="${XDG_CONFIG_HOME:-$HOME/.config}/slitaz/applications.conf"
484 if [ ! -f "$user_conf" ]; then
485 mkdir -p $(dirname $user_conf)
486 cp $apps_conf $user_conf
487 fi
488 fi
490 [ -f "$HOME/.xinitrc" ] || inst_pkg slitaz-configs-base --forced
491 }
494 # Commands
496 case "$1" in
497 install-xorg)
498 check_root
499 install_xorg
500 slitaz_apps_conf ;;
502 config-xorg)
503 check_root
504 slitaz_apps_conf
505 xorg_conf_d
506 # Handle live option: screen=
507 if grep -qs 'screen=' /proc/cmdline ; then
508 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
509 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
510 /etc/X11/xorg.conf.d/70-Screen.conf
511 fi ;;
513 init)
514 # We don't need much config files with last Xorg version, So just
515 # get files for starting an X session and config the keyboard.
516 check_root
517 slitaz_apps_conf
518 keyboard_conf
519 gen_xorg_conf_file ;;
521 keyboard)
522 keyboard_conf ;;
524 get-applist)
525 slitaz_apps_conf
526 gen_applist $2 $3 $4 ;;
528 auto)
529 autoselect_driver ;;
531 bpp)
532 check_root
533 xorg_conf_d
534 case "$2" in
535 8|15|16|24)
536 colors=$2 ;;
537 *)
538 exec 3>&1
539 colors=$($DIALOG --menu " " 12 12 12 \
540 24 truecolor 16 hicolor 15 hicolor 8 256colors 2>&1 1>&3)
541 dialog_end ;;
542 esac
543 sed 's|Monitor.*"$|&\n\tDefaultDepth '$colors'|' \
544 -i ${xorg_config}/70-Screen.conf ;;
546 xkb)
547 xkb ;;
549 *help)
550 emsg "
551 <b>tazx</b> - $(_ 'Configuration tool for SliTaz GNU/Linux')
553 <c 33>$(_ 'Usage:')</c> <b>tazx</b> <c 34>$(_ 'command')</c> $(_ 'parameter')
555 <c 34>$(_ 'Commands:')</c>
556 install-xorg $(_ 'Install Xorg and selected Xorg driver')
557 config-xorg $(_ 'Configure Xorg, generate configuration files')
558 bpp $(_ 'Set monitor default depth (valid parameters: 8, 15, 16 or 24)')
559 auto $(_ 'Auto-select and install Xorg driver')
560 init $(_ 'Get files for starting an X session and config the keyboard')
561 keyboard $(_ 'Generate or regenerate Xorg keyboard config')
562 "
563 ;;
565 *)
566 # User can get a new .xinitrc with tazx from cmdline.
567 case $(id -u) in
568 0)
569 slitaz_apps_conf
570 config_dialog ;;
571 *)
572 msg="\Z1 $(_n 'Run tazx as root if you need to configure xorg') \Zn"
573 slitaz_apps_conf
574 apps_dialog ;;
575 esac
576 # gen_xsession
577 ;;
578 esac
580 exit 0