slitaz-tools view tinyutils/tazx @ rev 876

Fix tazx (we have no X session on rc1...
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 01 22:10:37 2014 +0200 (2014-05-01)
parents 0764c1dac3c2
children 3dd4838c69c6
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}
26 # Default value.
27 WM=${WINDOW_MANAGER}
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 # Install xorg server.
137 install_xorg() {
138 [ -f "/var/lib/tazpkg/packages.list" ] || tazpkg recharge
139 exec 3>&1
140 value=$($DIALOG \
141 --clear --colors \
142 --title " $(_n 'Install Xorg') " \
143 --menu "$(_n 'Tazx helps you to select your X driver.')" 16 70 8 \
144 $(fgrep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | \
145 while read x; do echo $x; _ 'driver'; done) \
146 "quit" "$(_n 'Quit')" \
147 2>&1 1>&3)
148 retval=$?
149 exec 3>&-
151 # Continue or exit.
152 case $retval in
153 0) continue ;;
154 1|255) exit 0 ;;
155 esac
157 # Set selected value.
158 case $value in
159 quit) exit 0 ;;
160 *)
161 [ -d "$installed/xorg-server" ] || tazpkg -gi xorg-server
162 [ -d "$installed/xorg-xf86-video-$value" ] || \
163 tazpkg -gi xorg-xf86-video-$value
164 xorg_conf_d ;;
165 esac
166 }
168 # Screen configuration dialog. TODO: menus items to enable/disable X on boot
169 # and sed /etc/rcS.conf to remove slim from RUN_DAEMONS.
170 config_dialog() {
171 exec 3>&1
172 value=$($DIALOG \
173 --clear --colors \
174 --title "{ $(_n 'SliTaz Xorg config') }" \
175 --menu "" 16 72 10 \
176 "xorg" "$(_n 'Install or reconfigure Xorg')" \
177 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
178 "quit" "$(_n 'Quit Tazx utility')" \
179 2>&1 1>&3)
180 retval=$?
181 exec 3>&-
183 # Continue or exit.
184 case $retval in
185 0) continue ;;
186 1|255) exit 0 ;;
187 esac
189 # Set selected value.
190 case "$value" in
191 xorg)
192 install_xorg ;;
193 xorg-light)
194 [ -d "$installed/xorg-server-light" ] || \
195 tazpkg -gi xorg-server-light
196 [ -d "$installed/xorg-xf86-video-fbdev" ] || \
197 tazpkg -gi xorg-xf86-video-fbdev
198 xorg_conf_d ;;
199 *)
200 exit 0 ;;
201 esac
202 }
204 # ~/.config/slitaz/applications.conf: Missing = failed to login
205 # Make users applications.conf in /etc/skel so new added user will get
206 # a working X session. Note --> flavors can have a custom config in
207 # /etc/slitaz/applications that we must use.
208 slitaz_apps_conf() {
209 apps_conf=/etc/slitaz/applications.conf
211 if [ "$(id -u)" = 0 ]; then
212 user_conf="/etc/skel/.config/slitaz/applications.conf"
213 mkdir -p $(dirname $user_conf); cp -f ${apps_conf} ${user_conf}
214 else
215 # If started by: startx and with boot opts screen=text
216 user_conf="$HOME/.config/slitaz/applications.conf"
217 if [ ! -f "$user_conf" ]; then
218 mkdir -p $(dirname $user_conf); cp ${apps_conf} ${user_conf}
219 fi
220 fi
221 }
223 # Commands
225 case "$1" in
226 install-xorg)
227 check_root
228 install_xorg
229 slitaz_apps_conf ;;
231 config-xorg)
232 check_root
233 slitaz_apps_conf
234 xorg_conf_d
235 # Handle live option: screen=
236 if grep -qs 'screen=' /proc/cmdline ; then
237 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
238 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
239 /etc/X11/xorg.conf.d/70-Screen.conf
240 fi ;;
242 init)
243 # We dont need much config files with last Xorg verrsion, So just
244 # gest files for start a X session and config the keyboard.
245 check_root
246 slitaz_apps_conf
247 keyboard_conf
248 gen_xorg_conf_file ;;
250 keybard)
251 echo "Generating: 40-Keyboard.conf"
252 keyboard_conf ;;
254 *help)
255 echo "Usage: $(basename $0) [install-xorg|config-xorg|init|keyboard]" ;;
257 *)
258 # User can get a new .xinitrc with tazx from cmdline.
259 [ $(id -u) == 0 ] && config_dialog
260 slitaz_apps_conf
261 gen_xsession ;;
262 esac
264 exit 0