slitaz-tools view tinyutils/tazx @ rev 909

tazx: add slim-related menuitems
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Sun Oct 05 23:54:36 2014 +0000 (2014-10-05)
parents 27c340d6e1a0
children 14978ab4776e
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 install_slim() {
169 [ -d "$installed/slim" ] || tazpkg -gi slim
170 [ -d "$installed/dbus" ] || tazpkg -gi dbus
171 }
173 # Screen configuration dialog. TODO: menus items to enable/disable X on boot
174 # and sed /etc/rcS.conf to remove slim from RUN_DAEMONS.
175 config_dialog() {
176 . /etc/rcS.conf ; LM="ON"
177 [ $LOGIN_MANAGER = "slim" ] || LM="OFF"
179 exec 3>&1
180 value=$($DIALOG \
181 --clear --colors \
182 --title "{ $(_n 'SliTaz Xorg config') }" \
183 --menu "" 16 72 10 \
184 "xorg" "$(_n 'Install or reconfigure Xorg')" \
185 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
186 "onboot" "$(_n 'AutoStart Xorg by SLiM on boot') ...| $LM" \
187 "slim" "$(_n '(Re)Start Simple Login Manager now')" \
188 "quit" "$(_n 'Quit Tazx utility')" \
189 2>&1 1>&3)
190 retval=$?
191 exec 3>&-
193 # Continue or exit.
194 case $retval in
195 0) continue ;;
196 1|255) exit 0 ;;
197 esac
199 # Set selected value.
200 case "$value" in
201 xorg)
202 install_xorg ;;
203 xorg-light)
204 [ -d "$installed/xorg-server-light" ] || \
205 tazpkg -gi xorg-server-light
206 [ -d "$installed/xorg-xf86-video-fbdev" ] || \
207 tazpkg -gi xorg-xf86-video-fbdev
208 xorg_conf_d ;;
209 onboot)
210 install_slim
211 if [ $LM = "OFF" ] ; then
212 LM=slim
213 else
214 LM=""
215 fi
216 sed '/LOGIN_MANAGER=/s|"\([^"]*\)"|"'$LM'"|' \
217 -i /etc/rcS.conf
219 [ $LM = "slim" ] || LM=disabled
220 echo "start X on boot:" $(boldify $LM) ;;
221 slim)
222 install_slim
223 [ ! -z $XAUTHORITY ] || \
224 stopd slim ; sleep 1 ; startd slim ;;
225 *)
226 exit 0 ;;
227 esac
228 }
230 # ~/.config/slitaz/applications.conf: Missing = failed to login
231 # Make users applications.conf in /etc/skel so new added user will get
232 # a working X session. Note --> flavors can have a custom config in
233 # /etc/slitaz/applications that we must use.
234 slitaz_apps_conf() {
235 apps_conf=/etc/slitaz/applications.conf
237 if [ "$(id -u)" = 0 ]; then
238 user_conf="/etc/skel/.config/slitaz/applications.conf"
239 mkdir -p $(dirname $user_conf); cp -f ${apps_conf} ${user_conf}
240 else
241 # If started by: startx and with boot opts screen=text
242 user_conf="$HOME/.config/slitaz/applications.conf"
243 if [ ! -f "$user_conf" ]; then
244 mkdir -p $(dirname $user_conf); cp ${apps_conf} ${user_conf}
245 fi
246 fi
247 }
249 # Commands
251 case "$1" in
252 install-xorg)
253 check_root
254 install_xorg
255 slitaz_apps_conf ;;
257 config-xorg)
258 check_root
259 slitaz_apps_conf
260 xorg_conf_d
261 # Handle live option: screen=
262 if grep -qs 'screen=' /proc/cmdline ; then
263 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
264 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
265 /etc/X11/xorg.conf.d/70-Screen.conf
266 fi ;;
268 init)
269 # We don't need much config files with last Xorg version, So just
270 # get files for starting an X session and config the keyboard.
271 check_root
272 slitaz_apps_conf
273 keyboard_conf
274 gen_xorg_conf_file ;;
276 keyboard)
277 echo "Generating: 40-Keyboard.conf"
278 keyboard_conf ;;
280 *help)
281 echo "Usage: $(basename $0) [install-xorg|config-xorg|init|keyboard]" ;;
283 *)
284 # User can get a new .xinitrc with tazx from cmdline.
285 [ $(id -u) == 0 ] && config_dialog
286 slitaz_apps_conf
287 gen_xsession ;;
288 esac
290 exit 0