slitaz-tools view tinyutils/tazx @ rev 856

Edit tinyutils
author Paul Issott <paul@slitaz.org>
date Fri Apr 18 20:01:11 2014 +0100 (2014-04-18)
parents 66de501eccc6
children 0746b6a94061
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 # Populate xorg.conf.d.
45 xorg_conf_d() {
46 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
47 xorg_config=/etc/X11/xorg.conf.d
49 # Define the xorg.conf.new place.
50 xorg_template=/root/xorg.conf.new
52 # Obtain a default configuration file from Xorg.
53 Xorg -configure :2
55 # Backup existing config.
56 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
58 # Put the different sections in separate files in the config directory.
59 save_chunk 10-ServerLayout
60 sed -i '/Core/d' $xorg_config/10-ServerLayout.conf
61 save_chunk 20-Files
62 save_chunk 30-Module
63 save_chunk 50-Monitor
64 save_chunk 60-Device
65 save_chunk 70-Screen
67 # Remove the template.
68 rm $xorg_template
70 # Configure the keyboard with the right keymap.
71 keymap=$(cat /etc/keymap.conf)
72 keyboard_config=$xorg_config/40-Keyboard.conf
73 variant=""
74 # this XkbOption moved from 40-evdev.conf (xorg-xf86-input-evdev)
75 options="terminate:ctrl_alt_bksp"
76 case $keymap in
77 fr_CH-latin1)
78 # Swiss FrenCH
79 layout="ch"; variant="fr" ;;
80 uk)
81 # English UK
82 layout="gb" ;;
83 ru)
84 # Russian
85 layout="us,ru"
86 options="grp:ctrl_shift_toggle, grp_led:scroll, $options" ;;
87 ua)
88 # Ukrainian
89 layout="us,ua,ru"
90 options="grp:ctrl_shift_toggle, $options" ;;
91 slovene)
92 # Slovenian
93 layout="si"; options="grp:alt_shift_toggle, $options" ;;
94 us-acentos)
95 layout="us"; variant="intl" ;;
96 *)
97 # Use clean /etc/keymap.conf value.
98 keymap=${keymap%-latin1}
99 keymap=${keymap%-lat2}
100 keymap=${keymap%-lat6}
101 layout=${keymap%-abnt2}
102 esac
104 cat > $keyboard_config << EOC
105 Section "InputClass"
106 Identifier "Keyboard Defaults"
107 MatchIsKeyboard "yes"
108 Option "XkbLayout" "$layout"
109 Option "XkbVariant" "$variant"
110 Option "XkbOptions" "$options"
111 EndSection
112 EOC
113 [ x$variant == x ] && sed -i '/XkbVariant/d' $keyboard_config
115 # Create a xorg.conf if needed.
116 if [ ! -f /etc/X11/xorg.conf ]; then
117 cat > /etc/X11/xorg.conf << EOT
118 # You can put here your own Xorg configurations. This config file is read
119 # before all files in /etc/X11/xorg.conf.d and will NOT be erased by any
120 # updates.
121 EOT
122 fi
123 }
125 # Install xorg server.
126 install_xorg() {
127 [ -f "/var/lib/tazpkg/packages.list" ] || tazpkg recharge
128 exec 3>&1
129 value=$($DIALOG \
130 --clear --colors \
131 --title " $(_n 'Install Xorg') " \
132 --menu "$(_n 'Tazx helps you to select your X driver.')" 16 70 8 \
133 $(fgrep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | \
134 while read x; do echo $x; _ 'driver'; done) \
135 "quit" "$(_n 'Quit')" \
136 2>&1 1>&3)
137 retval=$?
138 exec 3>&-
140 # Continue or exit.
141 case $retval in
142 0) continue ;;
143 1|255) exit 0 ;;
144 esac
146 # Set selected value.
147 case $value in
148 quit) exit 0 ;;
149 *)
150 [ -d "$installed/xorg-server" ] || tazpkg -gi xorg-server
151 [ -d "$installed/xorg-xf86-video-$value" ] || \
152 tazpkg -gi xorg-xf86-video-$value
153 xorg_conf_d ;;
154 esac
155 }
157 # Screen configuration dialog. TODO: menus items to enable/disable X on boot
158 # and sed /etc/rcS.conf to remove slim from RUN_DAEMONS.
159 config_dialog() {
160 exec 3>&1
161 value=$($DIALOG \
162 --clear --colors \
163 --title "{ $(_n 'SliTaz Xorg config') }" \
164 --menu "" 16 72 10 \
165 "xorg" "$(_n 'Install or reconfigure Xorg')" \
166 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
167 "quit" "$(_n 'Quit Tazx utility')" \
168 2>&1 1>&3)
169 retval=$?
170 exec 3>&-
172 # Continue or exit.
173 case $retval in
174 0) continue ;;
175 1|255) exit 0 ;;
176 esac
178 # Set selected value.
179 case "$value" in
180 xorg)
181 install_xorg ;;
182 xorg-light)
183 [ -d "$installed/xorg-server-light" ] || \
184 tazpkg -gi xorg-server-light
185 [ -d "$installed/xorg-xf86-video-fbdev" ] || \
186 tazpkg -gi xorg-xf86-video-fbdev
187 xorg_conf_d ;;
188 *)
189 exit 0 ;;
190 esac
191 }
193 # ~/.xinitrc for X login from a DM.
194 creat_xinitrc() {
195 apps_conf=/etc/slitaz/applications.conf
196 user_conf="$HOME/.config/slitaz/applications.conf"
197 xinitrc="$HOME/.xinitrc"
198 if [ ! -f "$user_conf" ]; then
199 mkdir -p $(dirname $user_conf); cp ${apps_conf} ${user_conf}
200 fi
201 if [ ! -f "$xinitrc" ]; then
202 cp /etc/skel/.xinitrc ${xinitrc}
203 fi
205 # Make .xinitrc and config for /etc/skel so new added user will get
206 # a working X session.
207 if test $(id -u) = 0; then
208 user_conf="/etc/skel/.config/slitaz/applications.conf"
209 mkdir -p $(dirname $user_conf); cp -f ${apps_conf} ${user_conf}
210 fi
212 # In Live mode default user needs a xinitrc, since tazx is executed
213 # only by root.
214 user_conf="/home/$USER/.config/slitaz/applications.conf"
215 xinitrc="/home/$USER/.xinitrc"
216 if [ ! -f "$user_conf" ]; then
217 mkdir -p $(dirname $user_conf); cp ${apps_conf} ${user_conf}
218 chown -R $USER.users $(dirname $user_conf)
219 fi
220 if [ ! -f "$xinitrc" ]; then
221 cp -f /etc/skel/.xinitrc ${xinitrc}
222 chown $USER.users ${xinitrc}
223 fi
224 }
226 # Create ~/.xsession to keep the configuration selected (used
227 # only by startx, Slim login manager uses .xinitrc).
228 creat_xsession() {
229 local xsession=$HOME/.xsession
230 [ -f "$xsession" ] && cp -f ${xsession} ${xsession}.bak
231 cat > ${xsession} << EOT
232 # ~/.xsession: Start X session manually on your system with: startx
233 #
234 Xorg &
235 #xterm &
236 exec $WM
237 EOT
238 chmod 700 ${xsession}
239 }
241 # Commands
243 case "$1" in
244 install-xorg)
245 check_root
246 install_xorg
247 creat_xinitrc
248 creat_xsession ;;
250 config-xorg)
251 check_root
252 creat_xinitrc
253 creat_xsession
254 xorg_conf_d
255 # Handle live option: screen=
256 if grep -qs screen= /proc/cmdline ; then
257 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
258 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
259 /etc/X11/xorg.conf.d/70-Screen.conf
260 fi ;;
262 *help)
263 echo "Usage: $(basename $0) [install-xorg|config-xorg|]" ;;
265 *)
266 # User can get a new .xinitrc with tazx from cmdline.
267 [ $(id -u) == 0 ] && config_dialog
268 creat_xinitrc
269 creat_xsession ;;
270 esac
272 exit 0