slitaz-tools view tinyutils/tazx @ rev 1037

tazbox: lxpolkit support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 23 10:41:01 2021 +0000 (2021-10-23)
parents c187e3d49df6
children
line source
1 #!/bin/sh
2 #
3 # Tazx - Ncurses X configuration for SliTaz GNU/Linux using Dialog boxes.
4 # This tiny util 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-2017 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 # Generate or regenerate 40-Keyboard.conf
59 keyboard_conf() {
60 # Configure the keyboard with the correct keymap
61 keymap=$(cat /etc/keymap.conf)
62 keyboard_config="/etc/X11/xorg.conf.d/40-Keyboard.conf"
63 variant=""
65 # this XkbOption moved from 40-evdev.conf (xorg-xf86-input-evdev)
66 options="terminate:ctrl_alt_bksp"
67 _n 'Creating:'; echo -n " $keyboard_config"
68 mkdir -p $(dirname $keyboard_config)
70 # Reference: syslinux receipt; LXPanel keyboard layout switcher
71 case "$keymap" in
72 # Swiss FrenCH
73 fr_CH-latin1) layout='ch'; variant='fr' ;;
74 # English UK
75 uk) layout='gb' ;;
76 # Greek
77 gr) layout='us,gr'
78 options="grp:ctrl_shift_toggle, grp_led:scroll, compose:ralt, $options" ;;
79 # Russian
80 ru) layout='us,ru'
81 options="grp:ctrl_shift_toggle, grp_led:scroll, compose:ralt, $options" ;;
82 # Ukrainian
83 ua) layout='us,ua,ru'
84 options="grp:ctrl_shift_toggle, compose:ralt, $options" ;;
85 # Slovenian
86 slovene) layout='si' ;;
87 # Brasil (us-acentos); English US (acentos)
88 us-acentos) layout='us'; variant='intl' ;;
89 # Deutsch Schweiz
90 de_CH-latin1) layout='ch' ;;
91 # Deutsch Schweiz (sg) in syslinux menu
92 sg-latin1)
93 # I can't guess appropriate layout for this one
94 ;;
95 # Dvorak
96 dvorak) layout='us'; variant='dvorak' ;;
97 dvorak-l) layout='us'; variant='dvorak-l' ;;
98 dvorak-r) layout='us'; variant='dvorak-r' ;;
99 # French (Canada)
100 cf) layout='ca' ;;
101 # Croatian
102 hr,croat|croat) layout='hr' ;;
103 # Japanese
104 jp106) layout='jp' ;; # is ok?
105 # Dutch
106 nl2) layout='nl' ;;
107 # Polish
108 pl2) layout='pl' ;;
109 # Turkish
110 trq) layout='tr' ;;
111 tr_q-latin5) layout='tr'; variant='ku' ;; # is ok?
112 # Persian(Farsi) (Iran)
113 ir) layout='us,ir'
114 options="grp:alt_shift_toggle, grp_led:scroll, $options" ;;
115 *)
116 # Use clean /etc/keymap.conf value.
117 keymap=${keymap%-latin1}
118 keymap=${keymap%-lat2}
119 keymap=${keymap%-lat6}
120 layout=${keymap%-abnt2}
121 esac
123 update_conf=''
124 if [ -e "$keyboard_config" ]; then
125 actual_layout="$(awk 'BEGIN{FS="\""}{if($2=="XkbLayout")print $4}' $keyboard_config)"
126 # config not matched '/etc/keymap.conf', update
127 [ "$layout" != "$actual_layout" ] && update_conf='1'
128 else
129 # config absent, create
130 update_conf='1'
131 fi
133 [ -n "$update_conf" ] && cat > $keyboard_config <<EOC
134 Section "InputClass"
135 Identifier "Keyboard Defaults"
136 MatchIsKeyboard "yes"
137 Option "XkbLayout" "$layout"
138 Option "XkbVariant" "$variant"
139 Option "XkbOptions" "$options"
140 EndSection
141 EOC
143 status
144 [ -z "$variant" ] && sed -i '/XkbVariant/d' $keyboard_config
145 }
148 # Populate xorg.conf.d
150 xorg_conf_d() {
151 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
152 xorg_config=/etc/X11/xorg.conf.d
154 # Define the xorg.conf.new place.
155 xorg_template=/root/xorg.conf.new
157 # Obtain a default configuration file from Xorg.
158 Xorg -configure :2
160 # Backup existing config.
161 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &>/dev/null
163 # Put the different sections in separate files in the config directory.
164 save_chunk 10-ServerLayout
165 sed -i '/Core/d' $xorg_config/10-ServerLayout.conf
166 save_chunk 20-Files
167 save_chunk 30-Module
168 save_chunk 50-Monitor
169 save_chunk 60-Device
170 save_chunk 70-Screen
172 # Remove the template.
173 rm $xorg_template
175 # Keyboard & xorg.conf
176 keyboard_conf
177 gen_xorg_conf_file
178 }
181 # Process dialog's return code.
183 dialog_end() {
184 retval=$?
185 exec 3>&-
186 # Continue or exit.
187 case $retval in
188 0|3) continue ;;
189 1|255) exit 0 ;;
190 esac
191 }
194 # Install xorg server.
196 install_xorg() {
197 [ -f "$PKGS_DB/packages.list" ] || tazpkg recharge
199 exec 3>&1
201 driver=$($DIALOG \
202 --clear --colors --scrollbar --title " $(_ 'Install Xorg') " \
203 --menu "$(_ 'Tazx helps you to select your X driver.')" 16 70 9 \
204 'auto' "$(_ 'Auto configuring')" \
205 $(fgrep xorg-xf86-video- $PKGS_DB/packages.list | cut -d- -f4 | \
206 sed "s|.*|& $(_ 'driver')|") \
207 'quit' "$(_ 'Quit')" \
208 2>&1 1>&3)
210 dialog_end
212 case $driver in
213 quit) exit 0 ;;
214 auto) autoselect_driver ;;
215 *)
216 inst_pkg xorg-server
217 inst_pkg xorg-xf86-video-$driver
218 xorg_conf_d ;;
219 esac
220 }
223 # Auto-select and install Xorg driver.
225 autoselect_driver() {
226 inst_pkg xorg-server
228 for VID in $(busybox lspci | grep 'Class 03' | cut -c21-24 | sort -u); do
229 case $VID in
230 1022|1002) d=ati ;;
231 8086) d=intel ;;
232 10de) d=nouveau ;;
233 1039) d=sis ;;
234 15ad) d=vmware ;;
235 *) d=''; $DIALOG --colors --msgbox \
236 "\n\Z1$(_n 'Failed to setup driver')\Zn $(_ '(unknown hardware)')" 7 68 ;;
237 esac
238 [ -n "$d" ] && inst_pkg xorg-xf86-video-$d
239 [ -n "$d" ] && inst_pkg mesa-dri-$d
240 done
241 }
244 # Install specified package.
246 inst_pkg() {
247 pkg="$@"
248 colorize 3 $(_ 'Installing pkg: %s' "$pkg")
250 case $(id -u) in
251 0) CMD="tazpkg -gi $@" ;;
252 *) CMD="sudo tazpkg -gi $@" ;;
253 esac
254 [ -d "$INSTALLED/$@" ] || $CMD
255 }
258 # Select/install Window Manager and favorite applications.
260 apps_dialog() {
261 slitaz_apps_conf
262 . $user_conf
264 exec 3>&1
266 app=$($DIALOG --clear --colors --backtitle "$msg" --ok-label " $(_n 'Install')..." \
267 --title "{\Z3 $(_n 'Install Window Manager and applications') \Zn}" \
268 --inputmenu "" 21 52 18 \
269 $(for a in WINDOW_MANAGER EDITOR BROWSER TERMINAL FILE_MANAGER; do
270 eval n='$'$a; echo $a $n;
271 done) 2>&1 1>&3)
272 dialog_end
274 case $app in
275 RENAMED*) # like: RENAMED EDITOR myeditor
276 appname=$(echo $app | cut -d" " -f3)
277 app=$(echo $app | cut -d" " -f2) ;;
278 *)
279 app_name_dialog only-installed ;;
280 esac
282 if [ "$appname" != " " ]; then
283 if [ "$appname" = 'show_ALL' ]; then
284 app_name_dialog full-list
285 inst_pkg $appname
286 fi
287 if [ -z $(busybox which $appname) ]; then
288 inst_pkg $appname
289 inst_pkg $(lzcat $PKGS_DB/files.list.lzma | fgrep /bin/$appname | head -n1 | cut -d: -f1)
290 fi
291 sed -i "/$app/ s|=.*$|=\"$appname\"|" $user_conf
292 fi
294 msg=''; apps_dialog # loop
295 }
298 # Show list of applications to choose.
300 app_name_dialog() {
301 case $1 in
302 full-list) height='24' ;;
303 *) height='18' ;;
304 esac
306 exec 3>&1
308 appname=$($DIALOG --clear --colors --title "$app" \
309 --menu '' $height 50 24 $(gen_applist $app $@) 2>&1 1>&3)
310 dialog_end
311 }
314 # Generate application list for Dialog or Yad.
316 gen_applist() {
317 # $1 = [ FILE_MANAGER | BROWSER | EDITOR | TERMINAL | WINDOW_MANAGER ]
318 # $2 = [ only-installed | full-list ]
319 # $3 = [ yad | * ]
321 . $user_conf
323 FILE_MANAGERS="clex caja emelfm2 mc pathfinder pcmanfm pcmanfm-qt ranger \
324 spacefm thunar xfe ytree"
326 BROWSERS="arora chrome cream dillo elinks firefox firefox-official iron \
327 links lynx midori netsurf opera palemoon QtWeb qupzilla retawq seamonkey surf \
328 tazweb w3m xombrero"
330 EDITORS="adie beaver bluefish emacs geany jed joe juffed ht le leafpad \
331 mcedit mousepad mp-5 nano qedit SciTE tea vi vim xedit xfw zile"
333 TERMINALS="aterm evilvte lxterminal mrxvt qterminal sakura stjerm tilda \
334 urxvt vte xfce4-terminal xterm yeahconsole"
336 WINDOW_MANAGERS="awesome blackbox compiz dwm echinus enlightenment fluxbox \
337 icewm jwm lxde-session lxqt karmen matchbox openbox-session pekwm ratpoison \
338 xfwm4"
340 eval list='$'"$1"S
341 eval current='$'"$1"
343 for i in $current $(echo " $list " | sed "s| $current | |g"); do
345 case $(busybox which $i) in
346 '') # not installed
347 t='---' ;;
348 *) # installed
349 t='<--' ;;
350 esac
352 if [ "$2" = 'full-list' ] || [ "$t" = '<--' ]; then
353 echo "$i"
355 if [ "$3" != 'yad' ]; then
356 echo "$(echo $t | sed "s|---|$(_n 'Install')|g")"
357 fi
358 fi
359 done
361 if [ "$2" = 'only-installed' ] && [ "$3" != 'yad' ]; then
362 echo 'show_ALL' "+$(_n 'Install')"
363 fi
364 }
367 # Screen configuration dialog.
369 config_dialog() {
370 . /etc/rcS.conf
371 case $LOGIN_MANAGER in
372 slim) LM="$(_ 'ON')" ;;
373 *) LM="$(_ 'OFF')" ;;
374 esac
376 exec 3>&1
378 value=$($DIALOG \
379 --clear --colors \
380 --title "{ $(_n 'SliTaz Xorg config') }" \
381 --menu "" 16 72 10 \
382 "xorg" "$(_n 'Install or reconfigure Xorg')" \
383 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
384 "onboot" "$(_n 'AutoStart Xorg by SLiM on boot'): \Z5$LM\Zn" \
385 "slim" "$(_n '(Re)Start Simple Login Manager now')" \
386 "wm_apps" "$(_n 'Install Window Manager and applications')" \
387 "quit" "$(_n 'Quit Tazx utility')" \
388 2>&1 1>&3)
389 dialog_end
391 case "$value" in
392 xorg)
393 install_xorg ;;
395 xorg-light)
396 inst_pkg xorg-server-light
397 inst_pkg xorg-xf86-video-fbdev
398 xorg_conf_d ;;
400 onboot)
401 inst_pkg slim
402 inst_pkg dbus
404 if [ $LM = "$(_ 'OFF')" ]; then
405 LM='slim'
406 else
407 LM=''
408 fi
409 sed -i "/LOGIN_MANAGER/ s|=.*$|=$LM|" /etc/rcS.conf
411 [ -z "$LM" ] && LM='disabled'
412 _n "Start X on boot:"; boldify " $LM" ;;
414 slim)
415 inst_pkg slim
416 inst_pkg dbus
417 if [ -z $XAUTHORITY ]; then
418 stopd slim; sleep 2; startd slim
419 fi ;;
421 wm_apps)
422 apps_dialog ;;
424 *)
425 exit 0 ;;
426 esac
427 }
430 # ~/.config/slitaz/applications.conf: Missing = failed to login
431 # Make users applications.conf in /etc/skel so new added user will get
432 # a working X session. Note --> flavors can have a custom config in
433 # /etc/slitaz/applications that we must use.
435 slitaz_apps_conf() {
436 apps_conf=/etc/slitaz/applications.conf
438 [ -f $apps_conf ] || inst_pkg slitaz-configs --forced
440 if [ "$(id -u)" -eq 0 ]; then
441 user_conf="$apps_conf"
442 new_user_conf='/etc/skel/.config/slitaz/applications.conf'
443 mkdir -p $(dirname $new_user_conf)
444 cp -f $apps_conf $new_user_conf
445 else
446 # If started by: startx and with boot opts screen=text
447 user_conf="${XDG_CONFIG_HOME:-$HOME/.config}/slitaz/applications.conf"
448 if [ ! -f "$user_conf" ]; then
449 mkdir -p $(dirname $user_conf)
450 cp $apps_conf $user_conf
451 fi
452 fi
453 [ -f "$HOME/.xinitrc" ] || inst_pkg slitaz-configs-base --forced
454 }
457 # Handle live options: screen= video=
459 proc_cmdline()
460 {
461 if grep -qs 'screen=' /proc/cmdline ; then
462 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
463 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
464 -i ${xorg_config}/70-Screen.conf
465 elif grep -qs 'video=' /proc/cmdline ; then
466 MODE="$(sed 's/.*video=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
467 DEPTH=$(sed 's/.*video=.*-\([0-9]*\).*/\1/' < /proc/cmdline)
468 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
469 -i ${xorg_config}/70-Screen.conf
470 set_depth $DEPTH
471 fi
472 }
475 set_depth()
476 {
477 case "$1" in
478 8|15|16|24|32) colors=$1 ;;
479 *)
480 exec 3>&1
481 colors=$($DIALOG --menu " " 12 12 12 \
482 32 truecolor 24 truecolor 16 hicolor 15 hicolor 8 256colors 2>&1 1>&3)
483 dialog_end ;;
484 esac
485 (grep -q 'DefaultDepth' ${xorg_config}/70-Screen.conf) || \
486 sed 's|Monitor.*"$|&\n\tDefaultDepth '$colors'|' -i ${xorg_config}/70-Screen.conf
487 }
491 # Commands
493 case "$1" in
494 install-xorg)
495 check_root
496 install_xorg
497 slitaz_apps_conf ;;
499 config-xorg)
500 check_root
501 slitaz_apps_conf
502 xorg_conf_d
503 proc_cmdline ;;
505 init)
506 # We don't need much config files with last Xorg version, So just
507 # get files for starting an X session and config the keyboard.
508 check_root
509 slitaz_apps_conf
510 keyboard_conf
511 gen_xorg_conf_file ;;
513 keyboard)
514 keyboard_conf ;;
516 get-applist)
517 slitaz_apps_conf
518 gen_applist $2 $3 $4 ;;
520 auto)
521 autoselect_driver ;;
523 bpp)
524 check_root
525 xorg_conf_d
526 proc_cmdline
527 set_depth $2 ;;
529 *help|-h|-?)
530 emsg "
531 <b>tazx</b> - $(_ 'Configuration tool for SliTaz GNU/Linux')
533 <c 33>$(_ 'Usage:')</c> <b>tazx</b> <c 34>$(_ 'command')</c> $(_ 'parameter')
535 <c 34>$(_ 'Commands:')</c>
536 install-xorg $(_ 'Install Xorg and selected Xorg driver')
537 config-xorg $(_ 'Configure Xorg, generate configuration files')
538 bpp $(_ 'Set monitor default depth (valid parameters: 8, 15, 16 or 24)')
539 auto $(_ 'Auto-select and install Xorg driver')
540 init $(_ 'Get files for starting an X session and config the keyboard')
541 keyboard $(_ 'Generate or regenerate Xorg keyboard config')
542 "
543 ;;
545 *)
546 # User can get a new .xinitrc with tazx from cmdline.
547 case $(id -u) in
548 0)
549 config_dialog ;;
550 *)
551 msg="\Z1 $(_n 'Run tazx as root if you need to configure xorg') \Zn"
552 apps_dialog ;;
553 esac
554 # gen_xsession
555 ;;
556 esac
558 exit 0