new beta-0.90.0
[luatex.git] / source / texk / texlive / tl_scripts / texconfig-dialog.sh
blobbaa46bbecb557b6d2b6772931f0e779bac66333d
1 #!/bin/sh
2 # $Id: texconfig-dialog.sh 40066 2016-03-18 22:29:48Z karl $
3 # texconfig-dialog
4 # Originally written by Thomas Esser. Public domain.
5 # Now maintained as part of TeX Live; correspondence to tex-live@tug.org.
7 # invoke the right shell:
9 test -f /bin/ksh && test -z "$RUNNING_KSH" \
10 && { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \
11 && { RUNNING_KSH=true; export RUNNING_KSH; exec /bin/ksh $0 ${1+"$@"}; }
12 unset RUNNING_KSH
14 test -f /bin/bsh && test -z "$RUNNING_BSH" \
15 && { UNAMES=`uname -s`; test "x$UNAMES" = xAIX; } 2>/dev/null \
16 && { RUNNING_BSH=true; export RUNNING_BSH; exec /bin/bsh $0 ${1+"$@"}; }
17 unset RUNNING_BSH
19 # hack around a bug in zsh:
20 test -n "${ZSH_VERSION+set}" && alias -g '${1+"$@"}'='"$@"'
22 # preferentially use subprograms from our own directory.
23 mydir=`echo "$0" | sed 's,/[^/]*$,,'`
24 mydir=`cd "$mydir" && pwd`
25 PATH="$mydir:$PATH"; export PATH
27 # the version string
28 version='$Id: texconfig-dialog.sh 40066 2016-03-18 22:29:48Z karl $'
30 : ${PAGER=more}
31 progname=texconfig-dialog
32 tmpdir=${TMPDIR-${TEMP-${TMP-/tmp}}}/tcdtmp.$$
33 log=$tmpdir/log
34 tmpmenu=$tmpdir/tmpmenu
35 needsCleanup=false
37 ###############################################################################
38 # cleanup()
39 # clean up the temp area and exit with proper exit status
40 ###############################################################################
41 cleanup()
43 rc=$1
44 $needsCleanup && test -n "$tmpdir" && test -d "$tmpdir" \
45 && { cd / && rm -rf "$tmpdir"; }
46 # use clear rather than reset since we cannot easily save and restore
47 # the terminal settings, which is what would be ideal. See thread
48 # starting at http://tug.org/pipermail/tex-live/2016-March/037852.html.
49 termCtl clear
50 (exit $rc); exit $rc
53 ###############################################################################
54 # setupTmpDir()
55 # set up a temp directory and a trap to remove it
56 ###############################################################################
57 setupTmpDir()
59 case $needsCleanup in
60 true) return;;
61 esac
63 trap 'cleanup 1' 1 2 3 7 13 15
64 needsCleanup=true
65 (umask 077; mkdir "$tmpdir") \
66 || abort "could not create directory \`$tmpdir'"
69 ###############################################################################
70 # abort(errmsg)
71 # print `errmsg' to stderr and exit with error code 1
72 ###############################################################################
73 abort()
75 echo "$progname: $1." >&2
76 cleanup 1
79 logexec()
81 (echo; echo ">>> Executing \`$@' <<<") >> $log
82 "$@" 2>&1 | tee -a $log
85 ###############################################################################
86 # runDialog(args, ...)
87 # execute the right dialog program with the right default parameters
88 ###############################################################################
89 runDialog()
91 if test -n "$DIALOG_PROG"; then
92 termCtl clear
93 $DIALOG_PROG --title "TeX setup utility" ${1+"$@"}
94 runDialogRc=$?
95 termCtl clear
96 else
97 abort "could not find dialog or whiptail program to run"
99 (exit $runDialogRc)
100 return $runDialogRc
103 ###############################################################################
104 # findDialog(void)
105 # set DIALOG_PROG to the system dialog program, or the empty string.
106 ###############################################################################
107 findDialog()
109 for bin in whiptail dialog
111 binLoc=`texconfig findprog $bin`
112 case $binLoc in
113 "") DIALOG_PROG="";;
114 *) DIALOG_PROG=$binLoc; break;;
115 esac
116 done
119 ###############################################################################
120 # mktexdir(args)
121 # call mktexdir script, disable all features (to prevent sticky directories)
122 ###############################################################################
123 mktexdir()
125 MT_FEATURES=none "$TEXMFMAIN/web2c/mktexdir" "$@" >&2
128 ###############################################################################
129 # termCtl(arg)
130 # some convenience utilities for terminal control
131 ###############################################################################
132 termCtl()
134 case $1 in
135 clear)
136 test -n "$NO_CLEAR" && return
137 tty >/dev/null 2>&1 && clear
139 reset)
140 test -n "$NO_CLEAR" && return
141 reset 2>/dev/null
142 stty sane 2>/dev/null
143 reset 2>/dev/null
144 termCtl clear
146 readln)
147 echo
148 echo "press return to continue..."
149 read a
151 esac
154 ###############################################################################
155 # menuMain(void)
156 # the main menu
157 ###############################################################################
158 menuMain()
160 cat <<-'eof'
161 The interactive texconfig utility will be started now. Make sure
162 your screen has at least 24 rows and 80 columns. If texconfig
163 crashes now, you can still set up your TeX system using the
164 batch mode of texconfig. Try 'texconfig help' to get a list
165 of options.
167 The interactive mode works best with a real vt100 terminal or
168 inside an xterm window.
170 More likely these days, you're better off using tlmgr.
171 See http://tug.org/texlive/tlmgr.html.
173 termCtl readln
175 while :; do
176 logMessage='view logfile'
178 runDialog \
179 --menu "
180 Hint: all output of external commands (e.g. tex) is logged into
181 a file. You can look at this file using "LOG". If cursor keys make
182 trouble, you may have more luck with +/- and TAB.
184 23 80 14 \
185 EXIT 'exit' \
186 PAPER 'default paper: A4 or letter (us)' \
187 MODE 'default metafont mode and resolution' \
188 REHASH 'rebuild filename databases' \
189 FORMATS 'edit format definitions' \
190 HYPHENATION 'customize hyphenation' \
191 DVIPS 'dvips configuration' \
192 FAQ 'view frequently asked questions + answers' \
193 CONF 'show configuration' \
194 LOG "$logMessage" \
195 2>"$tmpmenu" || break
197 case `cat "$tmpmenu"` in
198 EXIT)
199 break
201 PAPER)
202 menuPaper
204 MODE)
205 menuMode
207 REHASH)
208 logexec texconfig rehash
209 termCtl readln
211 FORMATS)
212 texconfig formats
213 termCtl readln
215 HYPHENATION)
216 menuHyphenation
218 DVIPS)
219 menuDvips
221 FAQ)
222 texconfig faq
223 termCtl readln
225 CONF)
226 logexec texconfig conf
227 termCtl readln
229 LOG)
230 <"$log" eval $PAGER
231 termCtl readln
233 esac
234 done
237 menuGetMode()
239 # we need eval to get the command line right... :-(
240 eval \
241 runDialog \
242 --menu \""
243 Chosse a mode to be used when metafont generates font bitmaps. The resolution is the most important point, but there might
244 be differences between modes of the same resolution. See the comments in the file modes.mf for more details.
245 \"" \
246 23 80 14 \
247 `texconfig mode-list` 2>"$tmpmenu"
250 menuMode()
252 menuGetMode
253 mode=`cat "$tmpmenu"`
255 if test -n "$mode"; then
256 logexec texconfig mode "$mode"
257 termCtl readln
261 menuDvips()
263 menuDvipsDest=ps
265 while :; do
266 case $menuDvipsDest in
268 menuDvipsPrinterOpt=
269 menuDvipsMsg="
270 dvips GLOBAL section. Define the most common default settings (config.ps).
271 To define settings for a specific printer, first ADD a printer definition,
272 then CHANGE it.
276 menuDvipsPrinterOpt="-P $menuDvipsDest"
277 menuDvipsMsg="
278 dvips settings for printer $menuDvipsDest (config.$menuDvipsDest). Define
279 local settings for this printer. To switch back to global settings mode,
280 select GLOBAL.
283 esac
285 runDialog \
286 --menu "$menuDvipsMsg
287 You can use dvips for non PostScript printers, if you can setup your
288 printing system to convert PostScript to a format that your printer can
289 handle. Maybe, you can use GhostScript to do the conversion (if your
290 printer is supported)." \
291 23 80 9 \
292 RETURN 'back to the main menu' \
293 DEST 'define default destination of the generated Postscript' \
294 MODE 'change metafont mode/resolution' \
295 OFFSET 'shift output by some offset' \
296 PAPER 'define the default paper' \
297 GLOBAL 'change global settings (config.ps)' \
298 CHANGE 'change printer settings (config.$PRINTER)' \
299 ADD 'add a printer configuration' \
300 DEL 'remove a printer configuration' \
301 2>"$tmpmenu" || break
303 menuDvipsAns=`cat "$tmpmenu"`
304 case $menuDvipsAns in
305 RETURN)
306 break
308 DEST)
309 runDialog --inputbox "Enter the command to print.
311 In general, you need a command like 'lpr' or 'lpr -Pfoo'.
313 NOTE: If you just press return, printing will be disabled and the output saved to a file by default.
314 " 23 80 2>"$tmpmenu"
315 if test $? = 0; then
316 menuDvipsAns=`cat "$tmpmenu"`
317 case $menuDvipsAns in
319 menuDvipsPrintOpt=-
322 menuDvipsPrintOpt=$menuDvipsAns
324 esac
325 logexec texconfig dvips $menuDvipsPrinterOpt printcmd "$menuDvipsPrintOpt"
326 termCtl readln
329 MODE)
330 menuGetMode
331 mode=`cat "$tmpmenu"`
333 if test -n "$mode"; then
334 logexec texconfig dvips $menuDvipsPrinterOpt mode "$mode"
335 termCtl readln
338 OFFSET)
339 runDialog --inputbox "Enter a dimension pair (a rightwards offset and a downwards
340 offset), e.g. 2mm,-0.5in (right 2mm and up .5in):" 23 80 2>"$tmpmenu"; menuDvipsAns=`cat "$tmpmenu"`
341 case $menuDvipsAns in
342 "") : ;;
344 logexec texconfig dvips $menuDvipsPrinterOpt offset "$menuDvipsAns"
345 termCtl readln
347 esac
349 PAPER)
350 eval runDialog \
351 --menu \'\\n\\nChoose the default papersize definition for dvips.\\n\\n\' \
352 23 80 8 `texconfig dvips paper-list` \
353 2>"$tmpmenu"
354 paper=`cat "$tmpmenu"`
355 if test -n "$paper"; then
356 logexec texconfig dvips paper "$paper"
357 termCtl readln
360 GLOBAL)
361 menuDvipsDest=ps
363 CHANGE)
364 runDialog --inputbox "Printer name (for future settings of DEST / MODE / OFFSET)" 23 80 2>"$tmpmenu"
365 menuDvipsAns=`cat $tmpmenu`
366 case $menuDvipsAns in
367 "") : ;;
368 *) menuDvipsDest=$menuDvipsAns;;
369 esac
371 ADD)
372 runDialog --inputbox "Printer name (for printer to add)" 23 80 2>"$tmpmenu"
373 menuDvipsAns=`cat $tmpmenu`
374 case $menuDvipsAns in
375 "") : ;;
377 logexec texconfig dvips add $menuDvipsAns
378 termCtl readln
380 esac
382 DEL)
383 runDialog --inputbox "Printer name (for printer to delete)" 23 80 2>"$tmpmenu"
384 menuDvipsAns=`cat $tmpmenu`
385 case $menuDvipsAns in
386 "") : ;;
388 logexec texconfig dvips del $menuDvipsAns
389 termCtl readln
391 esac
393 esac
394 done
397 menuPaper()
399 runDialog \
400 --menu "
401 Select your default paper format.
403 23 80 14 \
404 RETURN 'return to the main menu' \
405 A4 'ISO A4 (210x297mm)' \
406 LETTER 'US (8.5x11in)' 2>"$tmpmenu"
408 p=`cat "$tmpmenu"`
409 case $p in
411 logexec texconfig paper a4
412 termCtl readln
414 LETTER)
415 logexec texconfig paper letter
416 termCtl readln
418 esac
421 menuHyphenation()
423 runDialog \
424 --menu "
425 Choose format to set up hyphenation for.
427 23 80 14 \
428 `texconfig hyphen-list | sed 's@\(.*\)@\1 \1@'` 2>"$tmpmenu"
429 p=`cat "$tmpmenu"`
430 case $p in
432 return
435 texconfig hyphen "$p"
436 termCtl readln
437 esac
440 # main()
442 case $1 in
443 help|--help)
444 cat <<-eof
445 Usage: $progname [--help|--version]
447 exit 0
449 --version)
450 cat <<-eof
451 $progname version $version.
453 exit 0
455 esac
458 : ${TEXMFCONFIG=`kpsewhich -var-value=TEXMFCONFIG`}
459 : ${TEXMFVAR=`kpsewhich -var-value=TEXMFVAR`}
460 : ${TEXMFMAIN=`kpsewhich -var-value=TEXMFMAIN`}
461 export TEXMFCONFIG TEXMFVAR TEXMFMAIN
463 setupTmpDir
464 echo "$progname: started `date`" > $log
465 findDialog
467 test -d "$TEXMFCONFIG" \
468 || mktexdir "$TEXMFCONFIG" >/dev/null 2>&1 \
469 || echo "$progname: directory \`$TEXMFCONFIG' (from TEXMFCONFIG variable) does not exist and cannot be created" >&2
471 canWriteConfig=false
472 if test -d "$TEXMFCONFIG"; then
473 if test -w "$TEXMFCONFIG"; then
474 canWriteConfig=true
475 else
476 echo "$progname: directory \`$TEXMFCONFIG' (from TEXMFCONFIG variable) is not writable."
477 echo "$progname: configuration data cannot be changed." >&2
481 test -d "$TEXMFVAR" \
482 || mktexdir "$TEXMFVAR" >/dev/null 2>&1 \
483 || echo "$progname: directory \`$TEXMFVAR' (from TEXMFVAR variable) does not exist and cannot be created" >&2
485 canWriteVardata=false
486 if test -d "$TEXMFVAR"; then
487 if test -w "$TEXMFVAR"; then
488 canWriteVardata=true
489 else
490 echo "$progname: directory \`$TEXMFVAR' (from TEXMFVAR variable) is not writable."
491 echo "$progname: cached variable runtime data files cannot be written." >&2
495 menuMain
496 cleanup 0