slitaz-tools view tinyutils/tazx @ rev 939

tazbox: fix subox icon when ~/.local/share/applications is absent; fix working with freegeoip; write full list of icons used; all other files: 2015 and insert blank lines.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Apr 17 07:35:02 2015 +0300 (2015-04-17)
parents e5d5980ecf4e
children 3be081525506
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=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 [ -z $(busybox which lxpanel) ] || 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
280 }
283 # Install specified package.
285 inst_pkg() {
286 pkg="$@"
287 colorize 3 $(_ 'Installing pkg: $pkg')
289 case $(id -u) in
290 0) CMD="tazpkg -gi $@" ;;
291 *) CMD="sudo tazpkg -gi $@" ;;
292 esac
293 [ -d "$INSTALLED/$@" ] || $CMD
294 }
297 # Select/install Window Manager and favorite applications.
299 apps_dialog() {
300 slitaz_apps_conf
301 . $user_conf
303 exec 3>&1
305 app=$($DIALOG --clear --colors --backtitle "$msg" \
306 --title "{\Z3 $(_n 'Install Window Manager and applications') \Zn}" \
307 --inputmenu "" 21 52 18 \
308 $(for a in WINDOW_MANAGER EDITOR BROWSER TERMINAL FILE_MANAGER; do
309 eval n='$'$a; echo $a $n;
310 done) 2>&1 1>&3)
311 dialog_end
313 case $app in
314 RENAMED*) # like: RENAMED EDITOR myeditor
315 appname=$(echo $app | cut -d" " -f3)
316 app=$(echo $app | cut -d" " -f2) ;;
317 *)
318 app_name_dialog only-installed ;;
319 esac
321 if [ $appname != " " ]; then
322 if [ $appname = show_ALL ]; then
323 app_name_dialog full-list
324 inst_pkg $appname
325 fi
326 if [ -z $(busybox which $appname) ]; then
327 inst_pkg $appname
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=
497 proc_cmdline()
498 {
499 if grep -qs 'screen=' /proc/cmdline ; then
500 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
501 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
502 -i ${xorg_config}/70-Screen.conf
503 elif grep -qs 'video=' /proc/cmdline ; then
504 MODE="$(sed 's/.*video=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
505 DEPTH=$(sed 's/.*video=.*-\([0-9]*\).*/\1/' < /proc/cmdline)
506 sed "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
507 -i ${xorg_config}/70-Screen.conf
508 set_depth $DEPTH
509 fi
510 }
513 set_depth()
514 {
515 case "$1" in
516 8|15|16|24|32) colors=$1 ;;
517 *)
518 exec 3>&1
519 colors=$($DIALOG --menu " " 12 12 12 \
520 32 truecolor 24 truecolor 16 hicolor 15 hicolor 8 256colors 2>&1 1>&3)
521 dialog_end ;;
522 esac
523 sed 's|Monitor.*"$|&\n\tDefaultDepth '$colors'|' -i ${xorg_config}/70-Screen.conf
524 }
528 # Commands
530 case "$1" in
531 install-xorg)
532 check_root
533 install_xorg
534 slitaz_apps_conf ;;
536 config-xorg)
537 check_root
538 slitaz_apps_conf
539 xorg_conf_d
540 proc_cmdline ;;
542 init)
543 # We don't need much config files with last Xorg version, So just
544 # get files for starting an X session and config the keyboard.
545 check_root
546 slitaz_apps_conf
547 keyboard_conf
548 gen_xorg_conf_file ;;
550 keyboard)
551 keyboard_conf ;;
553 get-applist)
554 slitaz_apps_conf
555 gen_applist $2 $3 $4 ;;
557 auto)
558 autoselect_driver ;;
560 bpp)
561 check_root
562 xorg_conf_d
563 proc_cmdline
564 set_depth $2 ;;
566 xkb)
567 xkb ;;
570 *help|-h|-?)
571 emsg "
572 <b>tazx</b> - $(_ 'Configuration tool for SliTaz GNU/Linux')
574 <c 33>$(_ 'Usage:')</c> <b>tazx</b> <c 34>$(_ 'command')</c> $(_ 'parameter')
576 <c 34>$(_ 'Commands:')</c>
577 install-xorg $(_ 'Install Xorg and selected Xorg driver')
578 config-xorg $(_ 'Configure Xorg, generate configuration files')
579 bpp $(_ 'Set monitor default depth (valid parameters: 8, 15, 16 or 24)')
580 auto $(_ 'Auto-select and install Xorg driver')
581 init $(_ 'Get files for starting an X session and config the keyboard')
582 keyboard $(_ 'Generate or regenerate Xorg keyboard config')
583 "
584 ;;
586 *)
587 # User can get a new .xinitrc with tazx from cmdline.
588 case $(id -u) in
589 0)
590 config_dialog ;;
591 *)
592 msg="\Z1 $(_n 'Run tazx as root if you need to configure xorg') \Zn"
593 apps_dialog ;;
594 esac
595 # gen_xsession
596 ;;
597 esac
599 exit 0