slitaz-tools view tinyutils/tazx @ rev 933

tazx:Undo previous, already checked in rcS. (except check for lxpanel & app*.conf not required). Read video= from /proc/cmdline("tazx config-xorg" only)
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Fri Dec 19 14:11:25 2014 +0000 (2014-12-19)
parents dcdd11dd6fe9
children 5db3093cbcfa
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
20 export TEXTDOMAIN='slitaz-tools' #i18n
21 : ${DIALOG=dialog --timeout 60}
23 # Default user for config files in Live mode, id is 1000 since it is
24 # created by /etc/init.d/bootopts.sh.
26 USER=$(awk -F: '/1000/{print $1}' /etc/passwd)
29 #
30 # Functions
31 #
34 # Save chunk of xorg.conf into specified file
36 save_chunk() {
37 sed -e '/Section "'${1#*-}'"/,/EndSection/!d' \
38 -e "s/EndSection/&\n/" $xorg_template > \
39 $xorg_config/$1.conf
40 }
43 # Create a xorg.conf if needed
45 gen_xorg_conf_file() {
46 if [ ! -f /etc/X11/xorg.conf ]; then
47 cat > /etc/X11/xorg.conf << EOT
48 # You can put here your own Xorg configurations. This config file is read
49 # before all files in /etc/X11/xorg.conf.d and will NOT be erased by any
50 # updates.
51 EOT
52 fi
53 }
56 # Add or remove xkb applet from lxpanel
58 xkb() {
59 case $(id -u) in
60 0)
61 # Empty if lxpanel not running, else something like:
62 # tux lxpanel -p slitaz
63 LXPS=$(ps -ouser,args | sed -n '/[l]xpanel/ s| *| |p' | \
64 fgrep -v '[' | fgrep -v 'xkb' | fgrep -v 'sh')
66 # Stop lxpanel
67 if [ -n "$LXPS" ]; then
68 lxpanelctl exit
69 killall lxpanel
70 fi
72 # For all human users
73 for USER in $(awk -F: '/\/home\//{print $1}' /etc/passwd); do
74 su $USER -c '. ~/.profile; tazx xkb'
75 done
77 # Re-run lxpanel
78 [ -n "$LXPS" ] && su ${LXPS%% *} -c "exec ${LXPS#* }" &
79 ;;
81 *)
82 DOTCONFIG=${XDG_CONFIG_HOME:-$HOME/.config}
83 CFG_LXPANEL=$DOTCONFIG/lxpanel
85 if [ ! -d $CFG_LXPANEL ]; then
86 mkdir -p $DOTCONFIG
87 cp -r /etc/lxpanel $DOTCONFIG
88 fi
90 case $(fgrep 'XkbLayout' /etc/X11/xorg.conf.d/40-Keyboard.conf | \
91 fgrep -o ',') in
92 '')
93 for CFG in $(find $CFG_LXPANEL -type f -name panel); do
94 if [ -n "$(grep 'type = xkb' $CFG)" ]; then
95 echo "Remove xkb applet from $CFG"
96 sed -i "$(grep -n -e "^Plugin {" -e "^}" -e "xkb" \
97 $CFG | grep -C 1 xkb | grep -v xkb | cut -d: \
98 -f1 | tr '\n' ' ' | sed 's| |,|')d" $CFG
99 fi
100 done ;;
101 ',')
102 for CFG in $(find $CFG_LXPANEL -type f -name panel); do
103 if [ -z "$(grep 'type = xkb' $CFG)" ]; then
104 echo "Add xkb applet to $CFG"
105 XKB='Plugin {\
106 type = xkb\
107 Config {\
108 DisplayType=0\
109 PerWinLayout=0\
110 NoResetOpt=0\
111 KeepSysLayouts=1\
112 Model=pc105\
113 LayoutsList=us\
114 VariantsList=,\
115 ToggleOpt=shift_caps_toggle\
116 FlagSize=4\
117 }\
118 }\
119 '
120 sed -i "$(grep -n -e "^Plugin {" -e "tray" $CFG | \
121 grep -B1 tray | head -n1 | cut -d: -f1) i\\
122 $XKB" $CFG
123 fi
124 done ;;
125 esac ;;
126 esac
127 }
130 # Generate or regenerate 40-Keyboard.conf
132 keyboard_conf() {
133 # Configure the keyboard with the right keymap
134 keymap=$(cat /etc/keymap.conf)
135 keyboard_config="/etc/X11/xorg.conf.d/40-Keyboard.conf"
136 variant=""
138 # this XkbOption moved from 40-evdev.conf (xorg-xf86-input-evdev)
139 options="terminate:ctrl_alt_bksp"
140 _n 'Creating:'; echo -n " $keyboard_config"
141 mkdir -p $(dirname $keyboard_config)
143 case "$keymap" in
144 fr_CH-latin1)
145 # Swiss FrenCH
146 layout="ch"; variant="fr" ;;
147 uk)
148 # English UK
149 layout="gb" ;;
150 ru)
151 # Russian
152 layout="us,ru"
153 options="grp:ctrl_shift_toggle, grp_led:scroll, compose:ralt, $options" ;;
154 ua)
155 # Ukrainian
156 layout="us,ua,ru"
157 options="grp:ctrl_shift_toggle, compose:ralt, $options" ;;
158 slovene)
159 # Slovenian
160 layout="si"; options="grp:alt_shift_toggle, $options" ;;
161 us-acentos)
162 layout="us"; variant="intl" ;;
163 *)
164 # Use clean /etc/keymap.conf value.
165 keymap=${keymap%-latin1}
166 keymap=${keymap%-lat2}
167 keymap=${keymap%-lat6}
168 layout=${keymap%-abnt2}
169 esac
171 cat > $keyboard_config << EOC
172 Section "InputClass"
173 Identifier "Keyboard Defaults"
174 MatchIsKeyboard "yes"
175 Option "XkbLayout" "$layout"
176 Option "XkbVariant" "$variant"
177 Option "XkbOptions" "$options"
178 EndSection
179 EOC
181 status
182 [ -z "$variant" ] && sed -i '/XkbVariant/d' $keyboard_config
183 [ -z $(busybox which lxpanel) ] || xkb
184 }
187 # Populate xorg.conf.d
189 xorg_conf_d() {
190 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
191 xorg_config=/etc/X11/xorg.conf.d
193 # Define the xorg.conf.new place.
194 xorg_template=/root/xorg.conf.new
196 # Obtain a default configuration file from Xorg.
197 Xorg -configure :2
199 # Backup existing config.
200 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
202 # Put the different sections in separate files in the config directory.
203 save_chunk 10-ServerLayout
204 sed -i '/Core/d' $xorg_config/10-ServerLayout.conf
205 save_chunk 20-Files
206 save_chunk 30-Module
207 save_chunk 50-Monitor
208 save_chunk 60-Device
209 save_chunk 70-Screen
211 # Remove the template.
212 rm $xorg_template
214 # Keyboard & xorg.conf
215 keyboard_conf
216 gen_xorg_conf_file
217 }
220 # Process dialog's return code.
222 dialog_end() {
223 retval=$?
224 exec 3>&-
225 # Continue or exit.
226 case $retval in
227 0|3) continue ;;
228 1|255) exit 0 ;;
229 esac
230 }
233 # Install xorg server.
235 install_xorg() {
236 [ -f "$PKGS_DB/packages.list" ] || tazpkg recharge
238 exec 3>&1
240 driver=$($DIALOG \
241 --clear --colors --scrollbar --title " $(_ 'Install Xorg') " \
242 --menu "$(_ 'Tazx helps you to select your X driver.')" 16 70 9 \
243 'auto' "$(_ 'Auto configuring')" \
244 $(fgrep xorg-xf86-video- $PKGS_DB/packages.list | cut -d- -f4 | \
245 sed "s|.*|& $(_ 'driver')|") \
246 'quit' "$(_ 'Quit')" \
247 2>&1 1>&3)
249 dialog_end
251 case $driver in
252 quit) exit 0 ;;
253 auto) autoselect_driver ;;
254 *)
255 inst_pkg xorg-server
256 inst_pkg xorg-xf86-video-$driver
257 xorg_conf_d ;;
258 esac
259 }
262 # Auto-select and install Xorg driver.
264 autoselect_driver() {
265 inst_pkg xorg-server
267 for VID in $(busybox lspci | grep 'Class 03' | cut -c21-24 | sort -u); do
268 case $VID in
269 1022|1002) d=ati ;;
270 8086) d=intel ;;
271 10de) d=nouveau ;;
272 1039) d=sis ;;
273 15ad) d=vmware ;;
274 *) d=''; $DIALOG --colors --msgbox \
275 "\n\Z1$(_n 'Failed to setup driver')\Zn $(_ '(unknown hardware)')" 7 68 ;;
276 esac
277 [ -n "$d" ] && inst_pkg xorg-xf86-video-$d
278 done
280 xorg_conf_d
281 }
284 # Install specified package.
286 inst_pkg() {
287 pkg="$@"
288 colorize 3 $(_ 'Installing pkg: $pkg')
290 case $(id -u) in
291 0) CMD="tazpkg -gi $@" ;;
292 *) CMD="sudo tazpkg -gi $@" ;;
293 esac
294 [ -d "$INSTALLED/$@" ] || $CMD
295 }
298 # Select/install Window Manager and favorite applications.
300 apps_dialog() {
301 slitaz_apps_conf
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 inst_pkg $appname
326 fi
327 if [ -z $(busybox which $appname) ]; then
328 inst_pkg $(lzcat $PKGS_DB/files.list.lzma | fgrep /bin/$appname | head -n1 | cut -d: -f1)
329 fi
330 sed -i "/$app/ s|=.*$|=\"$appname\"|" $user_conf
331 fi
333 msg=''; apps_dialog # loop
334 }
337 # Show list of applications to choose.
339 app_name_dialog() {
340 case $1 in
341 full-list) height=24 ;;
342 *) height=18 ;;
343 esac
345 exec 3>&1
347 appname=$($DIALOG --clear --colors --title "$app" \
348 --menu '' $height 50 24 $(gen_applist $app $@) 2>&1 1>&3)
349 dialog_end
350 }
353 # Generate application list for Dialog or Yad.
355 gen_applist() {
356 # $1 = [ FILE_MANAGER | BROWSER | EDITOR | TERMINAL | WINDOW_MANAGER ]
357 # $2 = [ only-installed | full-list ]
358 # $3 = [ yad | * ]
360 . $user_conf
362 FILE_MANAGERS="clex caja emelfm2 mc pathfinder pcmanfm pcmanfm-qt ranger \
363 spacefm thunar xfe ytree"
365 BROWSERS="arora chrome cream dillo elinks firefox firefox-official iron \
366 links lynx midori netsurf opera QtWeb qupzilla retawq seamonkey surf tazweb w3m xombrero"
368 EDITORS="adie beaver bluefish emacs geany jed joe juffed ht le leafpad \
369 mcedit mousepad mp-5 nano qedit SciTE tea vi vim xedit xfw zile"
371 TERMINALS="aterm evilvte lxterminal mrxvt qterminal sakura stjerm tilda \
372 urxvt vte xfce4-terminal xterm yeahconsole"
374 WINDOW_MANAGERS="awesome blackbox compiz dwm echinus enlightenment fluxbox \
375 icewm jwm lxde-session lxqt karmen matchbox openbox-session pekwm ratpoison \
376 xfwm4"
378 eval list='$'"$1"S
379 eval current='$'"$1"
381 for i in $current $(echo " $list " | sed "s| $current | |g"); do
383 case $(busybox which $i) in
384 '') # not installed
385 t='---' ;;
386 *) # installed
387 t='<--' ;;
388 esac
390 if [ "$2" == 'full-list' ] || [ "$t" == '<--' ]; then
391 echo "$i"
393 if [ "$3" != 'yad' ]; then
394 echo "$(echo $t | sed "s|---|$(_n 'Install')|g")"
395 fi
396 fi
397 done
399 if [ "$2" == 'only-installed' ] && [ "$3" != 'yad' ]; then
400 echo 'show_ALL' "+$(_n 'Install')"
401 fi
402 }
405 # Screen configuration dialog.
407 config_dialog() {
408 . /etc/rcS.conf
409 case $LOGIN_MANAGER in
410 slim) LM="$(_ 'ON')" ;;
411 *) LM="$(_ 'OFF')" ;;
412 esac
414 exec 3>&1
416 value=$($DIALOG \
417 --clear --colors \
418 --title "{ $(_n 'SliTaz Xorg config') }" \
419 --menu "" 16 72 10 \
420 "xorg" "$(_n 'Install or reconfigure Xorg')" \
421 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
422 "onboot" "$(_n 'AutoStart Xorg by SLiM on boot'): \Z5$LM\Zn" \
423 "slim" "$(_n '(Re)Start Simple Login Manager now')" \
424 "wm_apps" "$(_n 'Install Window Manager and applications')" \
425 "quit" "$(_n 'Quit Tazx utility')" \
426 2>&1 1>&3)
427 dialog_end
429 case "$value" in
430 xorg)
431 install_xorg ;;
433 xorg-light)
434 inst_pkg xorg-server-light
435 inst_pkg xorg-xf86-video-fbdev
436 xorg_conf_d ;;
438 onboot)
439 inst_pkg slim
440 inst_pkg dbus
442 if [ $LM == "$(_ 'OFF')" ]; then
443 LM='slim'
444 else
445 LM=''
446 fi
447 sed -i "/LOGIN_MANAGER/ s|=.*$|=$LM|" /etc/rcS.conf
449 [ -z "$LM" ] && LM='disabled'
450 _n "Start X on boot:"; boldify " $LM" ;;
452 slim)
453 inst_pkg slim
454 inst_pkg dbus
455 if [ -z $XAUTHORITY ]; then
456 stopd slim; sleep 2; startd slim
457 fi ;;
459 wm_apps)
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 [ -f $apps_conf ] || inst_pkg slitaz-configs --forced
478 if [ "$(id -u)" = 0 ]; then
479 user_conf=$apps_conf
480 new_user_conf="/etc/skel/.config/slitaz/applications.conf"
481 mkdir -p $(dirname $new_user_conf)
482 cp -f $apps_conf $new_user_conf
483 else
484 # If started by: startx and with boot opts screen=text
485 user_conf="${XDG_CONFIG_HOME:-$HOME/.config}/slitaz/applications.conf"
486 if [ ! -f "$user_conf" ]; then
487 mkdir -p $(dirname $user_conf)
488 cp $apps_conf $user_conf
489 fi
490 fi
491 [ -f "$HOME/.xinitrc" ] || inst_pkg slitaz-configs-base --forced
492 }
495 # Handle live options: screen= video=
496 proc_cmdline()
497 {
498 if grep -qs 'screen=' /proc/cmdline ; then
499 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
500 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
501 -i ${xorg_config}/70-Screen.conf
502 elif grep -qs 'video=' /proc/cmdline ; then
503 MODE="$(sed 's/.*video=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
504 DEPTH=$(sed 's/.*video=.*-\([0-9]*\).*/\1/' < /proc/cmdline)
505 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
506 -i ${xorg_config}/70-Screen.conf
507 set_depth $DEPTH
508 fi
509 }
511 set_depth()
512 {
513 case "$1" in
514 8|15|16|24) colors=$1 ;;
515 *)
516 exec 3>&1
517 colors=$($DIALOG --menu " " 12 12 12 \
518 24 truecolor 16 hicolor 15 hicolor 8 256colors 2>&1 1>&3)
519 dialog_end ;;
520 esac
521 sed 's|Monitor.*"$|&\n\tDefaultDepth '$colors'|' -i ${xorg_config}/70-Screen.conf
522 }
526 # Commands
528 case "$1" in
529 install-xorg)
530 check_root
531 install_xorg
532 slitaz_apps_conf ;;
534 config-xorg)
535 check_root
536 slitaz_apps_conf
537 xorg_conf_d
538 proc_cmdline ;;
540 init)
541 # We don't need much config files with last Xorg version, So just
542 # get files for starting an X session and config the keyboard.
543 check_root
544 slitaz_apps_conf
545 keyboard_conf
546 gen_xorg_conf_file ;;
548 keyboard)
549 keyboard_conf ;;
551 get-applist)
552 slitaz_apps_conf
553 gen_applist $2 $3 $4 ;;
555 auto)
556 autoselect_driver ;;
558 bpp)
559 check_root
560 xorg_conf_d
561 set_depth $2 ;;
563 xkb)
564 xkb ;;
566 *help|-h|-?)
567 emsg "
568 <b>tazx</b> - $(_ 'Configuration tool for SliTaz GNU/Linux')
570 <c 33>$(_ 'Usage:')</c> <b>tazx</b> <c 34>$(_ 'command')</c> $(_ 'parameter')
572 <c 34>$(_ 'Commands:')</c>
573 install-xorg $(_ 'Install Xorg and selected Xorg driver')
574 config-xorg $(_ 'Configure Xorg, generate configuration files')
575 bpp $(_ 'Set monitor default depth (valid parameters: 8, 15, 16 or 24)')
576 auto $(_ 'Auto-select and install Xorg driver')
577 init $(_ 'Get files for starting an X session and config the keyboard')
578 keyboard $(_ 'Generate or regenerate Xorg keyboard config')
579 "
580 ;;
582 *)
583 # User can get a new .xinitrc with tazx from cmdline.
584 case $(id -u) in
585 0)
586 config_dialog ;;
587 *)
588 msg="\Z1 $(_n 'Run tazx as root if you need to configure xorg') \Zn"
589 apps_dialog ;;
590 esac
591 # gen_xsession
592 ;;
593 esac
595 exit 0