dvitomp fix from Akira
[mplib] / src / texk / kpathsea / mktexupd
1 #!/bin/sh
2 # mktexupd -- update ls-R with a new entry.
3
4 # te@dbs.uni-hannover.de and kb@mail.tug.org. Public domain.
5
6 version='$Id: mktexupd,v 1.20 2004/12/19 12:41:13 olaf Exp $'
7 usage="Usage: $0 DIR FILE.
8   Update the ls-R file with an entry for FILE in DIR."
9 mt_min_args=2
10 mt_max_args=2
11
12 # Common code for all scripts.
13 : ${MT_TEXMFMAIN=`kpsewhich --expand-path='$TEXMFMAIN'`}
14 : ${MT_MKTEX_OPT=`kpsewhich --format='web2c files' mktex.opt`}
15 test -n "$MT_MKTEX_OPT" || MT_MKTEX_OPT="$MT_TEXMFMAIN/web2c/mktex.opt"
16 if test ! -f "$MT_MKTEX_OPT"; then
17   echo "$0: Cannot find mktex.opt; check your installation." >&2
18   exit 1
19 fi
20
21 . "$MT_MKTEX_OPT"
22
23 dir=$1
24 file=$2
25 test -d "$dir" || { echo "$0: $dir not a directory." >&2; exit 1; }
26 test -f "$dir/$file" || { echo "$0: $dir/$file not a file." >&2; exit 1; }
27
28 OIFS=$IFS; IFS=$SEP; set x `kpsewhich  -show-path=ls-R`; shift; IFS=$OIFS
29 TEXMFLS_R=
30 for d in "$@"; do
31   case $dir in
32     "") continue;;
33     ${d}|${d}/*) TEXMFLS_R="$d"; break;;
34   esac
35 done
36 test -n "$TEXMFLS_R" || exit 0
37 db_file="$TEXMFLS_R/ls-R"
38 db_file_lc="$TEXMFLS_R/ls-r"
39
40 test ! -f "$db_file" && test -f "$db_file_lc" && db_file="$db_file_lc"
41 test -f "$db_file" || { mktexlsr "$TEXMFLS_R"; exit; }
42 test -w "$db_file" || { echo "$0: $db_file unwritable." >&2; exit 1; }
43
44 test "x`sed '1s/\r$//;1q' \"$db_file\"`" = "x$ls_R_magic" \
45   || test "x`sed '1s/\r$//;1q' \"$db_file\"`" = "x$old_ls_R_magic" \
46   || { echo "$0: $db_file lacks magic string \`$ls_R_magic'." >&2; exit 1; }
47
48 # Change `$TEXMFLS_R/' to `./'.
49 dir=`echo $dir | sed "s%^$TEXMFLS_R/%./%g"`
50
51 # May as well always put in a new directory entry; presumably cron will
52 # come along soon enough and clean things up.
53 echo "$dir:" >>"$db_file"
54 echo "$file" >>"$db_file"
55
56 exit 0