slitaz-tools view tinyutils/tazx @ rev 920

clean tags
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Fri Nov 14 21:53:07 2014 +0000 (2014-11-14)
parents 14a1aa90effb
children ccb6cf783ff2
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
19 . /etc/slitaz/applications.conf
21 installed="$PKGS_DB/installed"
23 export TEXTDOMAIN='slitaz-tools' #i18n
24 : ${DIALOG=dialog --timeout 60}
26 WM_i18n=$(_n 'Window Manager:'| sed s/://)
27 INST_i18n=$(_n 'Install Xorg' | sed 's|Xorg||;s|X.org||;s| ||')
29 # Default user for config files in Live mode, id is 1000 since it is
30 # created by /etc/init.d/bootopts.sh.
31 USER=$(cat /etc/passwd | grep 1000 | cut -d ":" -f 1)
33 #
34 # Functions
35 #
37 # Save chunk of xorg.conf into specified file
38 save_chunk() {
39 sed -e '/Section "'${1#*-}'"/,/EndSection/!d' \
40 -e "s/EndSection/EndSection\n/" $xorg_template > \
41 $xorg_config/$1.conf
42 }
44 gen_xorg_conf_file() {
45 # Create a xorg.conf if needed.
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 }
55 # Generate or regenerate 40-Keyboard.conf
56 keyboard_conf() {
57 # Configure the keyboard with the right keymap.
58 keymap=$(cat /etc/keymap.conf)
59 keyboard_config="/etc/X11/xorg.conf.d/40-Keyboard.conf"
60 variant=""
61 # this XkbOption moved from 40-evdev.conf (xorg-xf86-input-evdev)
62 options="terminate:ctrl_alt_bksp"
63 gettext "Creating:"; echo -n " $keyboard_config"
64 mkdir -p $(dirname $keyboard_config)
65 case "$keymap" in
66 fr_CH-latin1)
67 # Swiss FrenCH
68 layout="ch"; variant="fr" ;;
69 uk)
70 # English UK
71 layout="gb" ;;
72 ru)
73 # Russian
74 layout="us,ru"
75 options="grp:ctrl_shift_toggle, grp_led:scroll, $options" ;;
76 ua)
77 # Ukrainian
78 layout="us,ua,ru"
79 options="grp:ctrl_shift_toggle, $options" ;;
80 slovene)
81 # Slovenian
82 layout="si"; options="grp:alt_shift_toggle, $options" ;;
83 us-acentos)
84 layout="us"; variant="intl" ;;
85 *)
86 # Use clean /etc/keymap.conf value.
87 keymap=${keymap%-latin1}
88 keymap=${keymap%-lat2}
89 keymap=${keymap%-lat6}
90 layout=${keymap%-abnt2}
91 esac
92 cat > $keyboard_config << EOC
93 Section "InputClass"
94 Identifier "Keyboard Defaults"
95 MatchIsKeyboard "yes"
96 Option "XkbLayout" "$layout"
97 Option "XkbVariant" "$variant"
98 Option "XkbOptions" "$options"
99 EndSection
100 EOC
101 status
102 [ x$variant == x ] && sed -i '/XkbVariant/d' ${keyboard_config}
103 }
105 # Populate xorg.conf.d.
106 xorg_conf_d() {
107 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
108 xorg_config=/etc/X11/xorg.conf.d
110 # Define the xorg.conf.new place.
111 xorg_template=/root/xorg.conf.new
113 # Obtain a default configuration file from Xorg.
114 Xorg -configure :2
116 # Backup existing config.
117 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
119 # Put the different sections in separate files in the config directory.
120 save_chunk 10-ServerLayout
121 sed -i '/Core/d' $xorg_config/10-ServerLayout.conf
122 save_chunk 20-Files
123 save_chunk 30-Module
124 save_chunk 50-Monitor
125 save_chunk 60-Device
126 save_chunk 70-Screen
128 # Remove the template.
129 rm $xorg_template
131 # Keyboard & xorg.conf
132 keyboard_conf
133 gen_xorg_conf_file
134 }
136 dialog_end() {
137 retval=$?
138 exec 3>&-
139 # Continue or exit.
140 case $retval in
141 0|3) continue ;;
142 1|255) exit 0 ;;
143 esac
144 }
146 # Install xorg server.
147 install_xorg() {
148 [ -f "/var/lib/tazpkg/packages.list" ] || tazpkg recharge
149 exec 3>&1
150 value=$($DIALOG \
151 --clear --colors --scrollbar --default-item "$1" \
152 --title " $(_n 'Install Xorg') " \
153 --menu "$(_n 'Tazx helps you to select your X driver.')" 16 70 8 \
154 Auto_select "$(_n 'Auto configuring Xorg...' | sed 's/X//;s/org//;s|...$||;s| |_|')" \
155 $(fgrep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | \
156 while read x; do echo $x; _ 'driver'; done) \
157 "quit" "$(_n 'Quit')" \
158 2>&1 1>&3)
159 dialog_end
161 # Set selected value.
162 case $value in
163 quit) exit 0 ;;
164 *)
165 [ ! $value = Auto_select ] || autoselect_driver IN_List
166 inst_pkg xorg-server
167 inst_pkg xorg-xf86-video-$value
168 xorg_conf_d ;;
169 esac
170 }
172 autoselect_driver() {
173 inst_pkg pciutils
174 for v in AMD ATI Intel NVIDIA SiS VMware; do
175 hw=$(echo $(lspci | grep VGA | grep $v | sed s/[^aA-zZ]//g)--)
176 if [ ! $hw = -- ]; then case $v in
177 AMD|ATI)d=ati;;
178 Intel) d=intel;;
179 NVIDIA) d=nouveau;;
180 SiS) d=sis;;
181 VMware) d=vmware;;
182 esac ; fi
183 done
184 DEVICE=$(_ 'driver')
185 [ ! $(echo $d | wc -w) = 0 ] || \
186 $DIALOG --colors --msgbox "\Z1 $(_n 'Failed to setup $DEVICE') \Zn (unknown hardware)" 5 68
188 [ $1 = sh ] || install_xorg $d
189 }
191 inst_pkg() {
192 pkg="$@" && colorize 5 $(_ 'Installing pkg: $pkg')
193 CMD="sudo tazpkg -gi $@"
194 test $(id -u) = 0 && CMD="tazpkg -gi $@"
195 [ -d "$installed/$@" ] || $CMD
196 }
198 apps_dialog() {
199 . ${user_conf}
200 exec 3>&1
201 app=$($DIALOG --clear --colors --backtitle "$msg" \
202 --title "{\Z3 $(_n '${INST_i18n}: ${WM_i18n} + applications') \Zn}" \
203 --inputmenu "" 21 52 18 \
204 $(for a in WINDOW_MANAGER EDITOR BROWSER TERMINAL FILE_MANAGER; do
205 eval n='$'"$a" ; echo "$a $n";
206 done) 2>&1 1>&3)
207 dialog_end
208 case $app in
209 RENAME*)appname=$(echo $app | cut -d " " -f3)
210 app=$(echo $app | cut -d " " -f2) ;;
211 *)
212 app_name_dialog only-installed d a-item ;;
213 esac
214 if [ ! $appname = " " ]; then
215 [ ! $appname = show_ALL ] || app_name_dialog full-list d
216 if [ ! $(busybox which ${appname} 2>/dev/null) ]; then
217 inst_pkg $appname
218 [ -d "$installed/$appname" ] || inst_pkg \
219 $(tazpkg search-pkgname /bin/$appname | grep -Ev '=|:| |/bin/')
220 else
221 sed '/'${app}'/s|=.*$|="'${appname}'"|' -i ${user_conf}
222 fi
223 fi
224 msg=''; apps_dialog
225 }
227 app_name_dialog() {
228 sz=28 ; [ $1 = full-list ] || sz=18
229 exec 3>&1
230 appname=$($DIALOG --clear --colors --title "${app}" \
231 --menu "" $sz 50 24 $(gen_applist $app $@) 2>&1 1>&3) \
232 dialog_end
233 }
235 gen_applist() {
236 . ${user_conf}
237 FILE_MANAGERS="clex caja emelfm2 mc pathfinder pcmanfm pcmanfm-qt ranger spacefm thunar xfe ytree"
238 BROWSERS="arora chrome cream dillo elinks firefox firefox-official iron links lynx \
239 midori netsurf opera QtWeb qupzilla retawq seamonkey surf tazweb"
240 EDITORS="adie beaver emacs geany jed joe juffed ht le leafpad mcedit mousepad mp-5 \
241 nano qedit SciTE vi vim xedit xfw zile"
242 TERMINALS="aterm evilvte lxterminal mrxvt qterminal sakura stjerm tilda urxvt vte \
243 xterm yeahconsole"
244 WINDOW_MANAGERS="awesome blackbox compiz dwm echinus enlightenment fluxbox icewm jwm \
245 lxde-session lxqt karmen matchbox openbox-session pekwm ratpoison xfwm4"
247 eval list='$'"$1"S
248 eval current='$'"$1"
249 for i in $current $(echo ' '$list' ' | sed "s| "$current" | |g") $4 ; do
250 t="<--" ; [ $(busybox which $i 2>/dev/null) ] || t=---
251 if [ $2 = only-installed ] && [ $t = --- ]; then
252 case $i in
253 a-item) i=show_ALL t="+"${INST_i18n};;
254 *) i=" " t=" " ;; esac
255 fi
256 echo "$i"
257 [ $3 = yad ] || echo -e "$(echo $t | sed "s|---|${INST_i18n}|g ; s| ||g")"
258 done
259 }
261 # Screen configuration dialog.
262 config_dialog() {
263 . /etc/rcS.conf ; LM="ON"
264 [ $LOGIN_MANAGER = "slim" ] || LM="OFF"
266 exec 3>&1
267 value=$($DIALOG \
268 --clear --colors \
269 --title "{ $(_n 'SliTaz Xorg config') }" \
270 --menu "" 16 72 10 \
271 "xorg" "$(_n 'Install or reconfigure Xorg')" \
272 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
273 "onboot" "$(_n 'AutoStart Xorg by SLiM on boot') ...| \Z5$LM\Zn" \
274 "slim" "$(_n '(Re)Start Simple Login Manager now')" \
275 "wm_apps" "$(_n '${INST_i18n}: ${WM_i18n} + applications')" \
276 "quit" "$(_n 'Quit Tazx utility')" \
277 2>&1 1>&3)
278 dialog_end
279 # Set selected value.
280 case "$value" in
281 xorg)
282 install_xorg ;;
283 xorg-light)
284 inst_pkg xorg-server-light
285 inst_pkg xorg-xf86-video-fbdev
286 xorg_conf_d ;;
287 onboot)
288 inst_pkg slim ; inst_pkg dbus
289 if [ $LM = "OFF" ] ; then
290 LM=slim
291 else LM=""
292 fi
293 sed '/LOGIN_MANAGER/s|=.*$|="'$LM'"|' -i /etc/rcS.conf
294 [ $LM = "slim" ] || LM=disabled
295 echo "start X on boot:" $(boldify $LM) ;;
296 slim)
297 inst_pkg slim ; inst_pkg dbus
298 [ ! -z $XAUTHORITY ] || stopd slim ;sleep 2; startd slim ;;
299 wm_apps)
300 slitaz_apps_conf ; apps_dialog ;;
301 *)
302 exit 0 ;;
303 esac
304 }
306 # ~/.config/slitaz/applications.conf: Missing = failed to login
307 # Make users applications.conf in /etc/skel so new added user will get
308 # a working X session. Note --> flavors can have a custom config in
309 # /etc/slitaz/applications that we must use.
310 slitaz_apps_conf() {
311 apps_conf=/etc/slitaz/applications.conf
313 if [ "$(id -u)" = 0 ]; then
314 user_conf=${apps_conf}
315 new_user_conf="/etc/skel/.config/slitaz/applications.conf"
316 mkdir -p $(dirname $user_conf); cp -f ${apps_conf} ${new_user_conf}
317 else
318 # If started by: startx and with boot opts screen=text
319 user_conf="$HOME/.config/slitaz/applications.conf"
320 if [ ! -f "$user_conf" ]; then
321 mkdir -p $(dirname $user_conf); cp ${apps_conf} ${user_conf}
322 fi
323 fi
324 [ -f "$HOME/.xinitrc" ] || inst_pkg slitaz-configs-base --forced
325 }
327 # Commands
329 case "$1" in
330 install-xorg)
331 check_root
332 install_xorg
333 slitaz_apps_conf ;;
335 config-xorg)
336 check_root
337 slitaz_apps_conf
338 xorg_conf_d
339 # Handle live option: screen=
340 if grep -qs 'screen=' /proc/cmdline ; then
341 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
342 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
343 /etc/X11/xorg.conf.d/70-Screen.conf
344 fi ;;
346 init)
347 # We don't need much config files with last Xorg version, So just
348 # get files for starting an X session and config the keyboard.
349 check_root
350 slitaz_apps_conf
351 keyboard_conf
352 gen_xorg_conf_file ;;
354 keyboard)
355 echo "Generating: 40-Keyboard.conf"
356 keyboard_conf ;;
358 get-applist)
359 slitaz_apps_conf
360 gen_applist $2 $3 $4 ;;
361 auto)
362 autoselect_driver sh
363 inst_pkg xorg-server
364 inst_pkg xorg-xf86-video-${d} ;;
365 bpp)
366 check_root
367 xorg_conf_d
368 case "$2" in 8|15|16|24) colors=$2 ;;
369 *) exec 3>&1 && colors=$($DIALOG --menu " " 12 12 12 \
370 24 truecolor 16 hicolor 15 hicolor 8 256colors 2>&1 1>&3) ; dialog_end ;;
371 esac
372 sed 's|Monitor.*"$|&\n\tDefaultDepth '$colors'|' \
373 -i ${xorg_config}/70-Screen.conf ;;
374 *help)
375 echo "Usage: $(basename $0) [install-xorg|bpp|auto|config-xorg|init|keyboard]" ;;
376 *)
377 # User can get a new .xinitrc with tazx from cmdline.
378 if [ $(id -u) == 0 ]; then
379 slitaz_apps_conf
380 config_dialog
381 else msg="\Z1 $(_n 'Run tazx as root if you need to configure xorg') \Zn"
382 slitaz_apps_conf
383 apps_dialog
384 fi
385 # gen_xsession
386 ;;
387 esac
389 exit 0