slitaz-tools view tinyutils/tazx @ rev 912

tazx: add default applications dialog, replace lists from tazbox.
author Xander Ziiryanoff <psychomaniak@xakep.ru>
date Wed Nov 05 19:01:28 2014 +0200 (2014-11-05)
parents f582b09fa62b
children 5bb075010572
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 dialog_end() {
137 retval=$?
138 exec 3>&-
139 # Continue or exit.
140 case $retval in
141 0) 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 \
152 --title " $(_n 'Install Xorg') " \
153 --menu "$(_n 'Tazx helps you to select your X driver.')" 16 70 8 \
154 $(fgrep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | \
155 while read x; do echo $x; _ 'driver'; done) \
156 "quit" "$(_n 'Quit')" \
157 2>&1 1>&3)
158 dialog_end
160 # Set selected value.
161 case $value in
162 quit) exit 0 ;;
163 *)
164 inst_pkg xorg-server
165 inst_pkg xorg-xf86-video-$value
166 xorg_conf_d ;;
167 esac
168 }
170 inst_pkg() {
171 CMD="sudo tazpkg -gi $@"
172 test $(id -u) = 0 && CMD="tazpkg -gi $@"
173 [ -d "$installed/$@" ] || $CMD
174 }
176 apps_dialog() {
177 . ${user_conf}
178 exec 3>&1
179 app=$($DIALOG --clear --colors \
180 --extra-label "$(_n 'Edit')" \
181 --backtitle "{ $(_n '\Z3SliTaz applications config\Zn') }" \
182 --inputmenu " " 22 52 18 WINDOW_MANAGER $WINDOW_MANAGER \
183 $(for a in EDITOR BROWSER TERMINAL FILE_MANAGER; do
184 eval n=$"$a" ; echo "$a $n";
185 done) 2>&1 1>&3)
186 dialog_end
187 case $app in
188 RENAMED*)
189 appname=$(echo $app | cut -d " " -f3)
190 app=$(echo $app | cut -d " " -f2) ;;
191 *)
192 app_name_dialog only-installed d a-item ;;
193 esac
194 if [ ! $appname = " " ]; then
195 [ ! $appname = show_ALL ] || app_name_dialog full-list d
196 if [ ! $(busybox which ${appname} 2>/dev/null) ]; then
197 inst_pkg $appname
198 if [ ! -d "$installed/$appname" ]; then
199 pknm=$(tazpkg search-pkgname /bin/$appname \
200 | grep -Ev '=|:| |/bin/')
201 inst_pkg $pknm
202 fi
203 else
204 sed '/'${app}'/s|=.*$|="'${appname}'"|' -i ${user_conf}
205 fi
206 fi
207 apps_dialog
208 }
210 app_name_dialog() {
211 bt="" sz=28 ; [ $1 = full-list ] || sz=20 \
212 bt=$(_n 'select "Show_ALL" to install additional programs')
213 exec 3>&1
214 appname=$($DIALOG --clear --colors \
215 --backtitle "\Z1${bt}\Zn" --title "${app}" \
216 --menu "" $sz 50 24 $(gen_applist $app $@) 2>&1 1>&3) \
217 dialog_end
218 }
220 gen_applist() {
221 . ${user_conf}
222 FILE_MANAGERS=" clex caja emelfm2 mc pathfinder pcmanfm pcmanfm-qt ranger spacefm thunar xfe ytree"
223 BROWSERS=" arora chrome cream dillo elinks firefox iron links lynx midori netsurf \
224 opera QtWeb qupzilla retawq seamonkey surf tazweb"
225 EDITORS=" adie beaver emacs geany jed joe juffed ht le leafpad mcedit mousepad mp-5 \
226 nano qedit SciTE vi vim xedit xfw zile"
227 TERMINALS=" aterm evilvte lxterminal mrxvt qterminal sakura stjerm tilda urxvt vte \
228 xterm yeahconsole"
229 WINDOW_MANAGERS=" awesome blackbox dwm echinus enlightenment fluxbox icewm-session jwm \
230 lxde-session karmen matchbox openbox-session pekwm ratpoison startlxqt xfwm4"
232 eval list='$'"$1"S
233 eval current='$'"$1"
234 for i in $current $(echo $list" " | sed "s| "$current" | |g") $4 ; do
235 t="<--" ; [ $(busybox which $i 2>/dev/null) ] || t=---
236 if [ $2 = only-installed ] && [ $t = --- ]; then
237 case $i in
238 a-item) i=show_ALL t=$(_n 'Get more apps') ;;
239 *) i=" " t=" " ;; esac
240 fi
241 instmsg=$(_n 'install')
242 t=$(echo $t | sed "s|---|$instmsg|g ; s| |_|g")
243 echo "$i"
244 [ $3 = yad ] || echo -e "$t"
245 done
246 }
248 # Screen configuration dialog.
249 config_dialog() {
250 . /etc/rcS.conf ; LM="ON"
251 [ $LOGIN_MANAGER = "slim" ] || LM="OFF"
253 exec 3>&1
254 value=$($DIALOG \
255 --clear --colors \
256 --title "{ $(_n 'SliTaz Xorg config') }" \
257 --menu "" 16 72 10 \
258 "xorg" "$(_n 'Install or reconfigure Xorg')" \
259 "xorg-light" "$(_n 'Install Xorg server (light version)')" \
260 "onboot" "$(_n 'AutoStart Xorg by SLiM on boot') ...| $LM" \
261 "slim" "$(_n '(Re)Start Simple Login Manager now')" \
262 "wm_apps" "$(_n 'Select & install WM|DE + applications')" \
263 "quit" "$(_n 'Quit Tazx utility')" \
264 2>&1 1>&3)
265 dialog_end
266 # Set selected value.
267 case "$value" in
268 xorg)
269 install_xorg ;;
270 xorg-light)
271 inst_pkg xorg-server-light
272 inst_pkg xorg-xf86-video-fbdev
273 xorg_conf_d ;;
274 onboot)
275 inst_pkg slim ; inst_pkg dbus
276 if [ $LM = "OFF" ] ; then
277 LM=slim
278 else LM=""
279 fi
280 sed '/LOGIN_MANAGER/s|=.*$|="'$LM'"|' -i /etc/rcS.conf
281 [ $LM = "slim" ] || LM=disabled
282 echo "start X on boot:" $(boldify $LM) ;;
283 slim)
284 inst_pkg slim ; inst_pkg dbus
285 [ ! -z $XAUTHORITY ] || stopd slim ;sleep 2; startd slim ;;
286 wm_apps)
287 slitaz_apps_conf
288 . ${user_conf}
289 apps_dialog ;;
290 *)
291 exit 0 ;;
292 esac
293 }
295 # ~/.config/slitaz/applications.conf: Missing = failed to login
296 # Make users applications.conf in /etc/skel so new added user will get
297 # a working X session. Note --> flavors can have a custom config in
298 # /etc/slitaz/applications that we must use.
299 slitaz_apps_conf() {
300 apps_conf=/etc/slitaz/applications.conf
302 if [ "$(id -u)" = 0 ]; then
303 user_conf=${apps_conf}
304 new_user_conf="/etc/skel/.config/slitaz/applications.conf"
305 mkdir -p $(dirname $user_conf); cp -f ${apps_conf} ${new_user_conf}
306 else
307 # If started by: startx and with boot opts screen=text
308 user_conf="$HOME/.config/slitaz/applications.conf"
309 if [ ! -f "$user_conf" ]; then
310 mkdir -p $(dirname $user_conf); cp ${apps_conf} ${user_conf}
311 fi
312 fi
313 }
315 # Commands
317 case "$1" in
318 install-xorg)
319 check_root
320 install_xorg
321 slitaz_apps_conf ;;
323 config-xorg)
324 check_root
325 slitaz_apps_conf
326 xorg_conf_d
327 # Handle live option: screen=
328 if grep -qs 'screen=' /proc/cmdline ; then
329 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
330 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
331 /etc/X11/xorg.conf.d/70-Screen.conf
332 fi ;;
334 init)
335 # We don't need much config files with last Xorg version, So just
336 # get files for starting an X session and config the keyboard.
337 check_root
338 slitaz_apps_conf
339 keyboard_conf
340 gen_xorg_conf_file ;;
342 keyboard)
343 echo "Generating: 40-Keyboard.conf"
344 keyboard_conf ;;
346 *help)
347 echo "Usage: $(basename $0) [install-xorg|config-xorg|init|keyboard]" ;;
350 get-applist)
351 slitaz_apps_conf
352 gen_applist $2 $3 $4 ;;
353 *)
354 # User can get a new .xinitrc with tazx from cmdline.
355 if [ $(id -u) == 0 ]; then config_dialog
356 else slitaz_apps_conf ; apps_dialog
357 fi
358 # gen_xsession
359 ;;
360 esac
362 exit 0