slitaz-tools view tinyutils/tazx @ rev 936

autoselect_driver(): no xorg_conf_d
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Mon Jan 12 01:19:06 2015 +0200 (2015-01-12)
parents 5db3093cbcfa
children 5d80f6fdbdb7
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
279 }
282 # Install specified package.
284 inst_pkg() {
285 pkg="$@"
286 colorize 3 $(_ 'Installing pkg: $pkg')
288 case $(id -u) in
289 0) CMD="tazpkg -gi $@" ;;
290 *) CMD="sudo tazpkg -gi $@" ;;
291 esac
292 [ -d "$INSTALLED/$@" ] || $CMD
293 }
296 # Select/install Window Manager and favorite applications.
298 apps_dialog() {
299 slitaz_apps_conf
300 . $user_conf
302 exec 3>&1
304 app=$($DIALOG --clear --colors --backtitle "$msg" \
305 --title "{\Z3 $(_n 'Install Window Manager and applications') \Zn}" \
306 --inputmenu "" 21 52 18 \
307 $(for a in WINDOW_MANAGER EDITOR BROWSER TERMINAL FILE_MANAGER; do
308 eval n='$'$a; echo $a $n;
309 done) 2>&1 1>&3)
310 dialog_end
312 case $app in
313 RENAMED*) # like: RENAMED EDITOR myeditor
314 appname=$(echo $app | cut -d" " -f3)
315 app=$(echo $app | cut -d" " -f2) ;;
316 *)
317 app_name_dialog only-installed ;;
318 esac
320 if [ $appname != " " ]; then
321 if [ $appname = show_ALL ]; then
322 app_name_dialog full-list
323 inst_pkg $appname
324 fi
325 if [ -z $(busybox which $appname) ]; then
326 inst_pkg $appname
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 w3m xombrero"
367 EDITORS="adie beaver bluefish emacs geany jed joe juffed ht le leafpad \
368 mcedit mousepad mp-5 nano qedit SciTE tea vi vim xedit xfw zile"
370 TERMINALS="aterm evilvte lxterminal mrxvt qterminal sakura stjerm tilda \
371 urxvt vte xfce4-terminal 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 apps_dialog ;;
461 *)
462 exit 0 ;;
463 esac
464 }
467 # ~/.config/slitaz/applications.conf: Missing = failed to login
468 # Make users applications.conf in /etc/skel so new added user will get
469 # a working X session. Note --> flavors can have a custom config in
470 # /etc/slitaz/applications that we must use.
472 slitaz_apps_conf() {
473 apps_conf=/etc/slitaz/applications.conf
475 [ -f $apps_conf ] || inst_pkg slitaz-configs --forced
477 if [ "$(id -u)" = 0 ]; then
478 user_conf=$apps_conf
479 new_user_conf="/etc/skel/.config/slitaz/applications.conf"
480 mkdir -p $(dirname $new_user_conf)
481 cp -f $apps_conf $new_user_conf
482 else
483 # If started by: startx and with boot opts screen=text
484 user_conf="${XDG_CONFIG_HOME:-$HOME/.config}/slitaz/applications.conf"
485 if [ ! -f "$user_conf" ]; then
486 mkdir -p $(dirname $user_conf)
487 cp $apps_conf $user_conf
488 fi
489 fi
490 [ -f "$HOME/.xinitrc" ] || inst_pkg slitaz-configs-base --forced
491 }
494 # Handle live options: screen= video=
495 proc_cmdline()
496 {
497 if grep -qs 'screen=' /proc/cmdline ; then
498 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
499 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
500 -i ${xorg_config}/70-Screen.conf
501 elif grep -qs 'video=' /proc/cmdline ; then
502 MODE="$(sed 's/.*video=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
503 DEPTH=$(sed 's/.*video=.*-\([0-9]*\).*/\1/' < /proc/cmdline)
504 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
505 -i ${xorg_config}/70-Screen.conf
506 set_depth $DEPTH
507 fi
508 }
510 set_depth()
511 {
512 case "$1" in
513 8|15|16|24|32) colors=$1 ;;
514 *)
515 exec 3>&1
516 colors=$($DIALOG --menu " " 12 12 12 \
517 32 truecolor 24 truecolor 16 hicolor 15 hicolor 8 256colors 2>&1 1>&3)
518 dialog_end ;;
519 esac
520 sed 's|Monitor.*"$|&\n\tDefaultDepth '$colors'|' -i ${xorg_config}/70-Screen.conf
521 }
525 # Commands
527 case "$1" in
528 install-xorg)
529 check_root
530 install_xorg
531 slitaz_apps_conf ;;
533 config-xorg)
534 check_root
535 slitaz_apps_conf
536 xorg_conf_d
537 proc_cmdline ;;
539 init)
540 # We don't need much config files with last Xorg version, So just
541 # get files for starting an X session and config the keyboard.
542 check_root
543 slitaz_apps_conf
544 keyboard_conf
545 gen_xorg_conf_file ;;
547 keyboard)
548 keyboard_conf ;;
550 get-applist)
551 slitaz_apps_conf
552 gen_applist $2 $3 $4 ;;
554 auto)
555 autoselect_driver ;;
557 bpp)
558 check_root
559 xorg_conf_d
560 proc_cmdline
561 set_depth $2 ;;
563 xkb)
564 xkb ;;
567 *help|-h|-?)
568 emsg "
569 <b>tazx</b> - $(_ 'Configuration tool for SliTaz GNU/Linux')
571 <c 33>$(_ 'Usage:')</c> <b>tazx</b> <c 34>$(_ 'command')</c> $(_ 'parameter')
573 <c 34>$(_ 'Commands:')</c>
574 install-xorg $(_ 'Install Xorg and selected Xorg driver')
575 config-xorg $(_ 'Configure Xorg, generate configuration files')
576 bpp $(_ 'Set monitor default depth (valid parameters: 8, 15, 16 or 24)')
577 auto $(_ 'Auto-select and install Xorg driver')
578 init $(_ 'Get files for starting an X session and config the keyboard')
579 keyboard $(_ 'Generate or regenerate Xorg keyboard config')
580 "
581 ;;
583 *)
584 # User can get a new .xinitrc with tazx from cmdline.
585 case $(id -u) in
586 0)
587 config_dialog ;;
588 *)
589 msg="\Z1 $(_n 'Run tazx as root if you need to configure xorg') \Zn"
590 apps_dialog ;;
591 esac
592 # gen_xsession
593 ;;
594 esac
596 exit 0