slitaz-tools view tinyutils/tazx @ rev 1006

Update translations.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Nov 19 23:26:17 2016 +0200 (2016-11-19)
parents 53c750021d6d
children c187e3d49df6
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-2015 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
20 export TEXTDOMAIN='slitaz-tools' #i18n
21 : ${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=1\
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 # Reference: syslinux receipt; LXPanel keyboard layout switcher
145 case "$keymap" in
146 # Swiss FrenCH
147 fr_CH-latin1) layout='ch'; variant='fr' ;;
148 # English UK
149 uk) layout='gb' ;;
150 # Greek
151 gr) layout='us,gr'
152 options="grp:ctrl_shift_toggle, grp_led:scroll, compose:ralt, $options" ;;
153 # Russian
154 ru) layout='us,ru'
155 options="grp:ctrl_shift_toggle, grp_led:scroll, compose:ralt, $options" ;;
156 # Ukrainian
157 ua) layout='us,ua,ru'
158 options="grp:ctrl_shift_toggle, compose:ralt, $options" ;;
159 # Slovenian
160 slovene) layout='si' ;;
161 # Brasil (us-acentos); English US (acentos)
162 us-acentos) layout='us'; variant='intl' ;;
163 # Deutsch Schweiz
164 de_CH-latin1) layout='ch' ;;
165 # Deutsch Schweiz (sg) in syslinux menu
166 sg-latin1)
167 # I can't guess appropriate layout for this one
168 ;;
169 # Dvorak
170 dvorak) layout='us'; variant='dvorak' ;;
171 dvorak-l) layout='us'; variant='dvorak-l' ;;
172 dvorak-r) layout='us'; variant='dvorak-r' ;;
173 # French (Canada)
174 cf) layout='ca' ;;
175 # Croatian
176 hr,croat|croat) layout='hr' ;;
177 # Japanese
178 jp106) layout='jp' ;; # is ok?
179 # Dutch
180 nl2) layout='nl' ;;
181 # Polish
182 pl2) layout='pl' ;;
183 # Turkish
184 trq) layout='tr' ;;
185 tr_q-latin5) layout='tr'; variant='ku' ;; # is ok?
186 # Persian(Farsi) (Iran)
187 ir) layout='us,ir'
188 options="grp:alt_shift_toggle, grp_led:scroll, $options" ;;
189 *)
190 # Use clean /etc/keymap.conf value.
191 keymap=${keymap%-latin1}
192 keymap=${keymap%-lat2}
193 keymap=${keymap%-lat6}
194 layout=${keymap%-abnt2}
195 esac
197 update_conf=''
198 if [ -e "$keyboard_config" ]; then
199 actual_layout="$(awk 'BEGIN{FS="\""}{if($2=="XkbLayout")print $4}' $keyboard_config)"
200 # config not matched '/etc/keymap.conf', update
201 [ "$layout" != "$actual_layout" ] && update_conf='1'
202 else
203 # config absent, create
204 update_conf='1'
205 fi
207 [ -n "$update_conf" ] && cat > $keyboard_config << EOC
208 Section "InputClass"
209 Identifier "Keyboard Defaults"
210 MatchIsKeyboard "yes"
211 Option "XkbLayout" "$layout"
212 Option "XkbVariant" "$variant"
213 Option "XkbOptions" "$options"
214 EndSection
215 EOC
217 status
218 [ -z "$variant" ] && sed -i '/XkbVariant/d' $keyboard_config
219 [ -z $(busybox which lxpanel) ] || xkb
220 }
223 # Populate xorg.conf.d
225 xorg_conf_d() {
226 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
227 xorg_config=/etc/X11/xorg.conf.d
229 # Define the xorg.conf.new place.
230 xorg_template=/root/xorg.conf.new
232 # Obtain a default configuration file from Xorg.
233 Xorg -configure :2
235 # Backup existing config.
236 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
238 # Put the different sections in separate files in the config directory.
239 save_chunk 10-ServerLayout
240 sed -i '/Core/d' $xorg_config/10-ServerLayout.conf
241 save_chunk 20-Files
242 save_chunk 30-Module
243 save_chunk 50-Monitor
244 save_chunk 60-Device
245 save_chunk 70-Screen
247 # Remove the template.
248 rm $xorg_template
250 # Keyboard & xorg.conf
251 keyboard_conf
252 gen_xorg_conf_file
253 }
256 # Process dialog's return code.
258 dialog_end() {
259 retval=$?
260 exec 3>&-
261 # Continue or exit.
262 case $retval in
263 0|3) continue ;;
264 1|255) exit 0 ;;
265 esac
266 }
269 # Install xorg server.
271 install_xorg() {
272 [ -f "$PKGS_DB/packages.list" ] || tazpkg recharge
274 exec 3>&1
276 driver=$($DIALOG \
277 --clear --colors --scrollbar --title " $(_ 'Install Xorg') " \
278 --menu "$(_ 'Tazx helps you to select your X driver.')" 16 70 9 \
279 'auto' "$(_ 'Auto configuring')" \
280 $(fgrep xorg-xf86-video- $PKGS_DB/packages.list | cut -d- -f4 | \
281 sed "s|.*|& $(_ 'driver')|") \
282 'quit' "$(_ 'Quit')" \
283 2>&1 1>&3)
285 dialog_end
287 case $driver in
288 quit) exit 0 ;;
289 auto) autoselect_driver ;;
290 *)
291 inst_pkg xorg-server
292 inst_pkg xorg-xf86-video-$driver
293 xorg_conf_d ;;
294 esac
295 }
298 # Auto-select and install Xorg driver.
300 autoselect_driver() {
301 inst_pkg xorg-server
303 for VID in $(busybox lspci | grep 'Class 03' | cut -c21-24 | sort -u); do
304 case $VID in
305 1022|1002) d=ati ;;
306 8086) d=intel ;;
307 10de) d=nouveau ;;
308 1039) d=sis ;;
309 15ad) d=vmware ;;
310 *) d=''; $DIALOG --colors --msgbox \
311 "\n\Z1$(_n 'Failed to setup driver')\Zn $(_ '(unknown hardware)')" 7 68 ;;
312 esac
313 [ -n "$d" ] && inst_pkg xorg-xf86-video-$d
314 [ -n "$d" ] && inst_pkg mesa-dri-$d
315 done
316 }
319 # Install specified package.
321 inst_pkg() {
322 pkg="$@"
323 colorize 3 $(_ 'Installing pkg: %s' "$pkg")
325 case $(id -u) in
326 0) CMD="tazpkg -gi $@" ;;
327 *) CMD="sudo tazpkg -gi $@" ;;
328 esac
329 [ -d "$INSTALLED/$@" ] || $CMD
330 }
333 # Select/install Window Manager and favorite applications.
335 apps_dialog() {
336 slitaz_apps_conf
337 . $user_conf
339 exec 3>&1
341 app=$($DIALOG --clear --colors --backtitle "$msg" --ok-label " $(_n 'Install')..." \
342 --title "{\Z3 $(_n 'Install Window Manager and applications') \Zn}" \
343 --inputmenu "" 21 52 18 \
344 $(for a in WINDOW_MANAGER EDITOR BROWSER TERMINAL FILE_MANAGER; do
345 eval n='$'$a; echo $a $n;
346 done) 2>&1 1>&3)
347 dialog_end
349 case $app in
350 RENAMED*) # like: RENAMED EDITOR myeditor
351 appname=$(echo $app | cut -d" " -f3)
352 app=$(echo $app | cut -d" " -f2) ;;
353 *)
354 app_name_dialog only-installed ;;
355 esac
357 if [ "$appname" != " " ]; then
358 if [ "$appname" == 'show_ALL' ]; then
359 app_name_dialog full-list
360 inst_pkg $appname
361 fi
362 if [ -z $(busybox which $appname) ]; then
363 inst_pkg $appname
364 inst_pkg $(lzcat $PKGS_DB/files.list.lzma | fgrep /bin/$appname | head -n1 | cut -d: -f1)
365 fi
366 sed -i "/$app/ s|=.*$|=\"$appname\"|" $user_conf
367 fi
369 msg=''; apps_dialog # loop
370 }
373 # Show list of applications to choose.
375 app_name_dialog() {
376 case $1 in
377 full-list) height='24' ;;
378 *) height='18' ;;
379 esac
381 exec 3>&1
383 appname=$($DIALOG --clear --colors --title "$app" \
384 --menu '' $height 50 24 $(gen_applist $app $@) 2>&1 1>&3)
385 dialog_end
386 }
389 # Generate application list for Dialog or Yad.
391 gen_applist() {
392 # $1 = [ FILE_MANAGER | BROWSER | EDITOR | TERMINAL | WINDOW_MANAGER ]
393 # $2 = [ only-installed | full-list ]
394 # $3 = [ yad | * ]
396 . $user_conf
398 FILE_MANAGERS="clex caja emelfm2 mc pathfinder pcmanfm pcmanfm-qt ranger \
399 spacefm thunar xfe ytree"
401 BROWSERS="arora chrome cream dillo elinks firefox firefox-official iron \
402 links lynx midori netsurf opera palemoon QtWeb qupzilla retawq seamonkey surf \
403 tazweb w3m xombrero"
405 EDITORS="adie beaver bluefish emacs geany jed joe juffed ht le leafpad \
406 mcedit mousepad mp-5 nano qedit SciTE tea vi vim xedit xfw zile"
408 TERMINALS="aterm evilvte lxterminal mrxvt qterminal sakura stjerm tilda \
409 urxvt vte xfce4-terminal xterm yeahconsole"
411 WINDOW_MANAGERS="awesome blackbox compiz dwm echinus enlightenment fluxbox \
412 icewm jwm lxde-session lxqt karmen matchbox openbox-session pekwm ratpoison \
413 xfwm4"
415 eval list='$'"$1"S
416 eval current='$'"$1"
418 for i in $current $(echo " $list " | sed "s| $current | |g"); do
420 case $(busybox which $i) in
421 '') # not installed
422 t='---' ;;
423 *) # installed
424 t='<--' ;;
425 esac
427 if [ "$2" == 'full-list' ] || [ "$t" == '<--' ]; then
428 echo "$i"
430 if [ "$3" != 'yad' ]; then
431 echo "$(echo $t | sed "s|---|$(_n 'Install')|g")"
432 fi
433 fi
434 done
436 if [ "$2" == 'only-installed' ] && [ "$3" != 'yad' ]; then
437 echo 'show_ALL' "+$(_n 'Install')"
438 fi
439 }
442 # Screen configuration dialog.
444 config_dialog() {
445 . /etc/rcS.conf
446 case $LOGIN_MANAGER in
447 slim) LM="$(_ 'ON')" ;;
448 *) LM="$(_ 'OFF')" ;;
449 esac
451 exec 3>&1
453 value=$($DIALOG \
454 --clear --colors \
455 --title "{ $(_n 'SliTaz Xorg config') }" \
456 --menu "" 16 72 10 \
457 "xorg" "$(_n 'Install or reconfigure Xorg')" \
458 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
459 "onboot" "$(_n 'AutoStart Xorg by SLiM on boot'): \Z5$LM\Zn" \
460 "slim" "$(_n '(Re)Start Simple Login Manager now')" \
461 "wm_apps" "$(_n 'Install Window Manager and applications')" \
462 "quit" "$(_n 'Quit Tazx utility')" \
463 2>&1 1>&3)
464 dialog_end
466 case "$value" in
467 xorg)
468 install_xorg ;;
470 xorg-light)
471 inst_pkg xorg-server-light
472 inst_pkg xorg-xf86-video-fbdev
473 xorg_conf_d ;;
475 onboot)
476 inst_pkg slim
477 inst_pkg dbus
479 if [ $LM == "$(_ 'OFF')" ]; then
480 LM='slim'
481 else
482 LM=''
483 fi
484 sed -i "/LOGIN_MANAGER/ s|=.*$|=$LM|" /etc/rcS.conf
486 [ -z "$LM" ] && LM='disabled'
487 _n "Start X on boot:"; boldify " $LM" ;;
489 slim)
490 inst_pkg slim
491 inst_pkg dbus
492 if [ -z $XAUTHORITY ]; then
493 stopd slim; sleep 2; startd slim
494 fi ;;
496 wm_apps)
497 apps_dialog ;;
499 *)
500 exit 0 ;;
501 esac
502 }
505 # ~/.config/slitaz/applications.conf: Missing = failed to login
506 # Make users applications.conf in /etc/skel so new added user will get
507 # a working X session. Note --> flavors can have a custom config in
508 # /etc/slitaz/applications that we must use.
510 slitaz_apps_conf() {
511 apps_conf=/etc/slitaz/applications.conf
513 [ -f $apps_conf ] || inst_pkg slitaz-configs --forced
515 if [ "$(id -u)" -eq 0 ]; then
516 user_conf="$apps_conf"
517 new_user_conf='/etc/skel/.config/slitaz/applications.conf'
518 mkdir -p $(dirname $new_user_conf)
519 cp -f $apps_conf $new_user_conf
520 else
521 # If started by: startx and with boot opts screen=text
522 user_conf="${XDG_CONFIG_HOME:-$HOME/.config}/slitaz/applications.conf"
523 if [ ! -f "$user_conf" ]; then
524 mkdir -p $(dirname $user_conf)
525 cp $apps_conf $user_conf
526 fi
527 fi
528 [ -f "$HOME/.xinitrc" ] || inst_pkg slitaz-configs-base --forced
529 }
532 # Handle live options: screen= video=
534 proc_cmdline()
535 {
536 if grep -qs 'screen=' /proc/cmdline ; then
537 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
538 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
539 -i ${xorg_config}/70-Screen.conf
540 elif grep -qs 'video=' /proc/cmdline ; then
541 MODE="$(sed 's/.*video=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
542 DEPTH=$(sed 's/.*video=.*-\([0-9]*\).*/\1/' < /proc/cmdline)
543 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
544 -i ${xorg_config}/70-Screen.conf
545 set_depth $DEPTH
546 fi
547 }
550 set_depth()
551 {
552 case "$1" in
553 8|15|16|24|32) colors=$1 ;;
554 *)
555 exec 3>&1
556 colors=$($DIALOG --menu " " 12 12 12 \
557 32 truecolor 24 truecolor 16 hicolor 15 hicolor 8 256colors 2>&1 1>&3)
558 dialog_end ;;
559 esac
560 (grep -q 'DefaultDepth' ${xorg_config}/70-Screen.conf) || \
561 sed 's|Monitor.*"$|&\n\tDefaultDepth '$colors'|' -i ${xorg_config}/70-Screen.conf
562 }
566 # Commands
568 case "$1" in
569 install-xorg)
570 check_root
571 install_xorg
572 slitaz_apps_conf ;;
574 config-xorg)
575 check_root
576 slitaz_apps_conf
577 xorg_conf_d
578 proc_cmdline ;;
580 init)
581 # We don't need much config files with last Xorg version, So just
582 # get files for starting an X session and config the keyboard.
583 check_root
584 slitaz_apps_conf
585 keyboard_conf
586 gen_xorg_conf_file ;;
588 keyboard)
589 keyboard_conf ;;
591 get-applist)
592 slitaz_apps_conf
593 gen_applist $2 $3 $4 ;;
595 auto)
596 autoselect_driver ;;
598 bpp)
599 check_root
600 xorg_conf_d
601 proc_cmdline
602 set_depth $2 ;;
604 xkb)
605 xkb ;;
608 *help|-h|-?)
609 emsg "
610 <b>tazx</b> - $(_ 'Configuration tool for SliTaz GNU/Linux')
612 <c 33>$(_ 'Usage:')</c> <b>tazx</b> <c 34>$(_ 'command')</c> $(_ 'parameter')
614 <c 34>$(_ 'Commands:')</c>
615 install-xorg $(_ 'Install Xorg and selected Xorg driver')
616 config-xorg $(_ 'Configure Xorg, generate configuration files')
617 bpp $(_ 'Set monitor default depth (valid parameters: 8, 15, 16 or 24)')
618 auto $(_ 'Auto-select and install Xorg driver')
619 init $(_ 'Get files for starting an X session and config the keyboard')
620 keyboard $(_ 'Generate or regenerate Xorg keyboard config')
621 "
622 ;;
624 *)
625 # User can get a new .xinitrc with tazx from cmdline.
626 case $(id -u) in
627 0)
628 config_dialog ;;
629 *)
630 msg="\Z1 $(_n 'Run tazx as root if you need to configure xorg') \Zn"
631 apps_dialog ;;
632 esac
633 # gen_xsession
634 ;;
635 esac
637 exit 0