2 # original mktexlsr -- create or rebuild ls-R.
4 # (If you change or delete the word `original' on the previous line,
5 # installation won't write this script over yours.)
7 # Suitable for calling from cron, as in:
8 # 0 * * * * cd /your/texmf/root && /usr/local/texlive/bin/mktexlsr
10 # Originally written as `texhash' by Thomas Esser, Okt., 1994.
13 version
='$Id: mktexlsr 36855 2015-04-14 12:15:08Z preining $'
14 progname
=`echo $0 | sed 's%.*/%%'`
16 usage
="Usage: $progname [OPTION]... [DIR]...
18 Rebuild ls-R filename databases used by TeX. If one or more arguments
19 DIRS are given, these are used as the directories in which to build
20 ls-R. Else all directories in the search path for ls-R files
21 (\$TEXMFDBS) are used.
24 --dry-run do not actually update anything
25 --help display this help and exit
26 --quiet cancel --verbose
27 --silent same as --quiet
28 --verbose explain what is being done
29 --version output version information and exit
31 If standard input is a terminal, --verbose is on by default.
33 For more information, see the \`Filename database' section of
34 Kpathsea manual available at http://tug.org/kpathsea.
36 Report bugs to: tex-k@tug.org
37 TeX Live home page: <http://tug.org/texlive/>
40 # The simple PATH-prepending approach we take in other scripts doesn't
41 # handle DOS/Windows, but we don't use the shell scripts on Windows
42 # anyway, and does anyone want current TL on DOS or DJGPP? Maybe they
43 # can maintain their own changes if so. Leaving this code though, since
44 # it's always been here ...
46 # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
47 # directories in path lists whereas Unix uses `:'. Make an exception for
48 # Cygwin, which pretends to be UNIX.
49 # Create a variable that holds the right character to be used by the scripts.
52 CYGWIN
*|Cygwin
*|cygwin
*) ;;
53 *) if test -n "$COMSPEC" ||
test -n "$ComSpec"; then DOSISH
=yes; fi
55 if test "$DOSISH" = "no"; then SEP
=':'; else SEP
=';';fi
57 # Add the location of the script to the PATH if necessary. This must
58 # be done before kpsewhich can be called, and thus cannot be put into
60 dirname=`echo $0 | sed 's%/*[^/][^/]*$%%'`
64 /* |
[A-z
]:/*) # Absolute name
65 PATH
="$dirname$SEP$PATH"
68 PATH
="`pwd`/$dirname$SEP$PATH"
72 if tty
-s; then verbose
=true
; else verbose
=false
; fi
76 treefile
="${TMPDIR-/tmp}/mktexlsrtrees$$.tmp"
77 trap 'cd /; rm -f $treefile; test -z "$db_dir_tmp" || rm -rf "$db_dir_tmp";
80 # A copy of some stuff from mktex.opt, so we can run in the presence of
81 # terminally damaged ls-R files.
82 while test $# -gt 0; do
83 if test "x$1" = x--help ||
test "x$1" = x-help
; then
86 elif test "x$1" = x--version ||
test "x$1" = x-version
; then
87 echo "`basename $0` $version"
90 elif test "x$1" = x--verbose ||
test "x$1" = x-verbose
; then
92 elif test "x$1" = x--dry-run ||
test "x$1" = x-n
; then
94 elif test "x$1" = x--quiet ||
test "x$1" = x--silent \
95 ||
test "x$1" = x-quiet ||
test "x$1" = x-silent
; then
97 elif test "x$1" = x--
; then
99 elif echo "x$1" |
grep '^x-' >/dev
/null
; then
100 echo "$progname: unknown option \`$1', try --help if you need it." >&2
103 if test ! -d "$1"; then
104 echo "$progname: $1: not a directory, skipping." >&2
108 # By saving the argument in a file, we can later get it back while
109 # supporting spaces in the name. This still doesn't support
110 # newlines in the directory names, but nobody ever complains about
111 # that, and it seems much too much trouble to use \0 terminators.
113 if echo "$1" >>"$treefile"; then :; else
114 echo "$progname: $treefile: could not append to arg file, goodbye." >&2
122 # mktexupd and mktexlsr make sure they're coordinated via this. A copy
123 # is found mktex.opt.
124 ls_R_magic
='% ls-R -- filename database for kpathsea; do not change this line.'
125 # The old string, which should continue to work.
126 old_ls_R_magic
='% ls-R -- maintained by MakeTeXls-R; do not change this line.'
129 # Get list of directories from the explicit arguments (now saved in
130 # $treefile), or $TEXMFDBS if no explicit args. Eliminate duplicates.
131 saveIFS
=$IFS # break only at newline
134 if test -s "$treefile"; then
135 set x
`sort "$treefile" | uniq`
137 set x
`kpsewhich --show-path=ls-R | tr : '
144 for TEXMFLS_R
in "$@"; do
145 # Prepend cwd if the directory was relative.
147 "") continue ;; # Strictly speaking, it is an error if this case is taken.
149 *) TEXMFLS_R
="`pwd`/$TEXMFLS_R"
151 # Allow for either ls-R and ls-r to exist. But create ls-R if we're
152 # working from scratch.
153 if test -f "$TEXMFLS_R/ls-R"; then
154 db_file
="$TEXMFLS_R/ls-R"
155 elif test -f "$TEXMFLS_R/ls-r"; then
156 db_file
="$TEXMFLS_R/ls-r"
158 db_file
="$TEXMFLS_R/ls-R"
160 # Follow a possible symlink to get the right filesystem.
161 # The '|| true' construct prevents an sh -e aborting.
162 db_readlink
=`kpsereadlink "$TEXMFLS_R/ls-R" 2>/dev/null` || true
163 case "$db_readlink" in
165 /* |
[A-z
]:/*) db_file
="$db_readlink" ;;
166 *) db_file
="$TEXMFLS_R/$db_readlink"
168 db_dir
=`echo "$db_file" | sed 's%/[^/][^/]*$%%'` # can't rely on dirname
170 # want to be silent if the directory doesn't exist, since the ls-R
171 # path ordinarily contains many nonexistent directories.
172 test -d "$db_dir" ||
continue
173 test -w "$db_dir" ||
{ echo "$progname: $db_dir: directory not writable. Skipping..." >&2; continue; }
175 if test ! -f "$db_file"; then
176 cp /dev
/null
"$db_file"
177 # Use same permissions as parent directory, minus x,s, or t bits.
178 chmod `kpsestat -xst "$db_dir"` "$db_file"
179 elif test -s "$db_file" \
180 && test "x`sed '1s/
$//;1q' \"$db_file\"`" != "x$ls_R_magic" \
181 && test "x`sed '1s/
$//;1q' \"$db_file\"`" != "x$old_ls_R_magic"; then
182 echo "$progname: $db_file: no magic string, skipping..." >&2
186 # Skip if we cannot write the file:
187 kpseaccess
-w "$db_file" ||
{ echo "$progname: $db_file: no write permission, skipping..." >&2; continue; }
189 db_dir_tmp
="$db_dir/lsR$$.tmp"
190 (umask 077 && mkdir
"$db_dir_tmp" ) \
191 ||
{ echo "$progname: $db_dir_tmp: could not create directory, skipping..." >&2; continue; }
192 db_file_tmp
="$db_dir_tmp/lsR$$.tmp"
195 $verbose && echo "$progname: Updating $db_file... "
198 echo "$ls_R_magic" >"$db_file_tmp"
200 # The main task. We put ./: in the output, so top-level files can be
201 # found via ls-R. Probably irrelevant in practice. The sed command
202 # inserts the leading ./ for directory names, and removes ., .., and
203 # version control entries from the list. Also omit contents of any
204 # the version directories; sed apparently requires that we do that
205 # operation in a separate invocation. We do not try to support colons
206 # in directory names.
208 echo "./:" >>"$db_file_tmp"
209 vc_dirs
='\.\(bzr\|git\|hg\|svn\)\|_darcs'
210 (cd "$TEXMFLS_R" && \
ls -LRa 2>/dev
/null
) \
211 |
sed -e '/^$/{n;s%^\./%%;s%^%./%;}; /^\.$/d; /^\.\.$/d; /^'$vc_dirs'$/d;' \
212 -e '/^[\.\/]*lsR[0-9]*\.tmp:*$/d' \
213 |
sed -e /$vc_dirs'.*:$/,/^$/d' \
216 # To be really safe, a loop.
217 until PERMS
=`kpsestat = "$db_file"`; do sleep 1; done
218 chmod $PERMS "$db_file_tmp"
220 mv "$db_file_tmp" "$db_file"
224 $verbose && echo "$progname: Done."