beta-0.89.2
[luatex.git] / source / texk / kpathsea / mktexupd
bloba4938d96eec77544ef0f9d28e458b7595d2cab84
1 #!/bin/sh
2 # mktexupd -- update ls-R with a new entry.
3 #
4 # Primarily written by Thomas Esser, Karl Berry, and Olaf Weber.
5 # Public domain.
7 version='$Id: mktexupd 34656 2014-07-18 23:38:50Z karl $'
9 # preferentially use subprograms from our own directory.
10 mydir=`echo "$0" | sed 's,/[^/]*$,,'`
11 mydir=`cd "$mydir" && pwd`
12 PATH="$mydir:$PATH"; export PATH
14 usage="Usage: $0 DIR FILE.
15 Update the ls-R file with an entry for FILE in DIR.
17 Report bugs to: tex-k@tug.org
18 TeX Live home page: <http://tug.org/texlive/>
20 mt_min_args=2
21 mt_max_args=2
23 # Common code for all scripts.
24 : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
25 : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
26 test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
27 if test ! -f "$MT_MKTEX_OPT"; then
28 echo "$0: Cannot find mktex.opt; check your installation." >&2
29 exit 1
32 . "$MT_MKTEX_OPT"
34 dir=$1
35 file=$2
36 test -d "$dir" || { echo "$0: $dir not a directory." >&2; exit 1; }
37 test -f "$dir/$file" || { echo "$0: $dir/$file not a file." >&2; exit 1; }
39 OIFS=$IFS; IFS=$SEP; set x `kpsewhich -show-path=ls-R`; shift; IFS=$OIFS
40 TEXMFLS_R=
41 for d in "$@"; do
42 case $dir in
43 "") continue;;
44 ${d}|${d}/*) TEXMFLS_R="$d"; break;;
45 esac
46 done
47 test -n "$TEXMFLS_R" || exit 0
48 db_file="$TEXMFLS_R/ls-R"
49 db_file_lc="$TEXMFLS_R/ls-r"
51 test ! -f "$db_file" && test -f "$db_file_lc" && db_file="$db_file_lc"
52 test -f "$db_file" || { mktexlsr "$TEXMFLS_R"; exit; }
53 test -w "$db_file" || { echo "$0: $db_file unwritable." >&2; exit 1; }
55 test "x`sed '1s/ $//;1q' \"$db_file\"`" = "x$ls_R_magic" \
56 || test "x`sed '1s/ $//;1q' \"$db_file\"`" = "x$old_ls_R_magic" \
57 || { echo "$0: $db_file lacks magic string \`$ls_R_magic'." >&2; exit 1; }
59 # Change `$TEXMFLS_R/' to `./'.
60 dir=`echo $dir | sed "s%^$TEXMFLS_R/%./%g"`
62 # May as well always put in a new directory entry; presumably cron will
63 # come along soon enough and clean things up.
64 echo "$dir:" >>"$db_file"
65 echo "$file" >>"$db_file"
67 exit 0