Debian Codegraph @

texmf-dist/scripts/texlive/mktexlsr

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # original mktexlsr -- create or rebuild ls-R.
3 #
4 # (If you change or delete the word `original' on the previous line,
5 # installation won't write this script over yours.)
6 #
7 # Suitable for calling from cron, as in:
8 # 0 * * * * cd /your/texmf/root && /usr/local/texlive/bin/mktexlsr
9 #
10 # Originally written as `texhash' by Thomas Esser, Okt., 1994.
11 # Public domain.
12
13 version='$Id: mktexlsr 56842 2020-11-02 23:00:54Z karl $'
14 progname=`echoscip-shell system . . echo. $0 | sedscip-shell system . . sed. 's%.*/%%'`
15
16 usage="Usage: $progname [OPTION]... [DIR]...
17
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.
22
23 Options:
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
30
31 If standard input is a terminal, --verbose is on by default.
32
33 For more information, see the \`Filename database' section of
34 Kpathsea manual available at http://tug.org/kpathsea.
35
36 Report bugs to: [email protected]
37 TeX Live home page: <http://tug.org/texlive/>
38 "
39
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 ...
45
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.
50 DOSISH=no
51 case `unamescip-shell system . . uname. -s` in
52 CYGWIN*|Cygwin*|cygwin*) ;;
53 *) if testscip-shell system . . test. -n "$COMSPEC" || testscip-shell system . . test. -n "$ComSpec"; then DOSISH=yes; fi
54 esac
55 if testscip-shell system . . test. "$DOSISH" = "no"; then SEP=':'; else SEP=';';fi
56
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
59 # mktex.opt.
60 dirname=`echoscip-shell system . . echo. $0 | sedscip-shell system . . sed. 's%/*[^/][^/]*$%%'`
61 case $dirname in
62 "") # Do nothing
63 ;;
64 /* | [A-z]:/*) # Absolute name
65 PATH="$dirname$SEP$PATH"
66 export PATH ;;
67 *) # Relative name
68 PATH="`pwdscip-shell system . . pwd.`/$dirname$SEP$PATH"
69 export PATH ;;
70 esac
71
72 if ttyscip-shell system . . tty. -s >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then verbose=true; else verbose=false; fi
73 dry_run=false
74 trees=
75
76 # initialize treefile by either mktemp or some random name
77 # code taken from pdfjam and adjusted
78 {
79 treefile=`
80 (umask 077 && mktempscip-shell system . . mktemp. "${TMPDIR-/tmp}/mktexlsrtrees.XXXXXXXXXX") 2>/dev/nullscip-shell filesystem . . `/dev/null`.
81 ` && testscip-shell system . . test. -n "$treefile" && testscip-shell system . . test. -f "$treefile"
82 } || {
83 ## We'll use awk to make random number, for portability
84 random=`awkscip-shell system . . awk. 'END { srand(); printf ("%d\n", rand()*1000000); }' /dev/nullscip-shell filesystem . . `/dev/null`.`
85 treefile="${TMPDIR-/tmp}/mktexlsrtrees$$.$random"
86 } || exit $?
87
88 trap 'cd /; rm -f $treefile; test -z "$db_dir_tmp" || rm -rf "$db_dir_tmp";
89 exit' 0 1 2 3 7 13 15
90
91 # A copy of some stuff from mktex.opt, so we can run in the presence of
92 # terminally damaged ls-R files.
93 while testscip-shell system . . test. $# -gt 0; do
94 if testscip-shell system . . test. "x$1" = x--help || testscip-shell system . . test. "x$1" = x-help; then
95 echoscip-shell system . . echo. "$usage"
96 exit 0
97 elif testscip-shell system . . test. "x$1" = x--version || testscip-shell system . . test. "x$1" = x-version; then
98 echoscip-shell system . . echo. "`basenamescip-shell system . . basename. $0` $version"
99 kpsewhich --version
100 exit 0
101 elif testscip-shell system . . test. "x$1" = x--verbose || testscip-shell system . . test. "x$1" = x-verbose; then
102 verbose=true
103 elif testscip-shell system . . test. "x$1" = x--dry-run || testscip-shell system . . test. "x$1" = x-n; then
104 dry_run=true
105 elif testscip-shell system . . test. "x$1" = x--quiet || testscip-shell system . . test. "x$1" = x--silent \
106 || testscip-shell system . . test. "x$1" = x-quiet || testscip-shell system . . test. "x$1" = x-silent ; then
107 verbose=false
108 elif testscip-shell system . . test. "x$1" = x--; then
109 :
110 elif echoscip-shell system . . echo. "x$1" | grepscip-shell system . . grep. '^x-' >/dev/nullscip-shell filesystem . . `/dev/null`.; then
111 echoscip-shell system . . echo. "$progname: unknown option \`$1', try --help if you need it." >&2
112 exit 1
113 else
114 if testscip-shell system . . test. ! -d "$1"; then
115 echoscip-shell system . . echo. "$progname: $1: not a directory, skipping." >&2
116 shift
117 continue
118 fi
119 # By saving the argument in a file, we can later get it back while
120 # supporting spaces in the name. This still doesn't support
121 # newlines in the directory names, but nobody ever complains about
122 # that, and it seems much too much trouble to use \0 terminators.
123 (umask 077
124 if echoscip-shell system . . echo. "$1" >>"$treefile"; then :; else
125 echoscip-shell system . . echo. "$progname: $treefile: could not append to arg file, goodbye." >&2
126 exit 1
127 fi
128 )
129 fi
130 shift
131 done
132
133 # mktexupd and mktexlsr make sure they're coordinated via this. A copy
134 # is found mktex.opt.
135 ls_R_magic='% ls-R -- filename database for kpathsea; do not change this line.'
136 # The old string, which should continue to work.
137 old_ls_R_magic='% ls-R -- maintained by MakeTeXls-R; do not change this line.'
138
139 {
140 # Get list of directories from the explicit arguments (now saved in
141 # $treefile), or $TEXMFDBS if no explicit args. Eliminate duplicates.
142 saveIFS=$IFS # break only at newline
143 IFS='
144 '
145 if testscip-shell system . . test. -s "$treefile"; then
146 set x `sortscip-shell system . . sort. "$treefile" | uniqscip-shell system . . uniq.`
147 else
148 set x `kpsewhich --show-path=ls-R | trscip-shell system . . tr. : '
149 ' | sortscip-shell system . . sort. | uniqscip-shell system . . uniq.`
150 fi
151 IFS=$saveIFS
152 shift
153 }
154
155 for TEXMFLS_R in "$@"; do
156 # Prepend cwd if the directory was relative.
157 case "$TEXMFLS_R" in
158 "") continue ;; # Strictly speaking, it is an error if this case is taken.
159 /* | [A-z]:/*) ;;
160 *) TEXMFLS_R="`pwdscip-shell system . . pwd.`/$TEXMFLS_R"
161 esac
162 # Allow for either ls-R and ls-r to exist. But create ls-R if we're
163 # working from scratch.
164 if testscip-shell system . . test. -f "$TEXMFLS_R/ls-R"; then
165 db_file="$TEXMFLS_R/ls-R"
166 elif testscip-shell system . . test. -f "$TEXMFLS_R/ls-r"; then
167 db_file="$TEXMFLS_R/ls-r"
168 else
169 db_file="$TEXMFLS_R/ls-R"
170 fi
171 # Follow a possible symlink to get the right filesystem.
172 # The '|| true' construct prevents an sh -e aborting.
173 db_readlink=`kpsereadlink "$TEXMFLS_R/ls-R" 2>/dev/nullscip-shell filesystem . . `/dev/null`.` || truescip-shell system . . true.
174 case "$db_readlink" in
175 "") ;;
176 /* | [A-z]:/*) db_file="$db_readlink" ;;
177 *) db_file="$TEXMFLS_R/$db_readlink"
178 esac
179 db_dir=`echoscip-shell system . . echo. "$db_file" | sedscip-shell system . . sed. 's%/[^/][^/]*$%%'` # can't rely on dirname
180
181 # want to be silent if the directory doesn't exist, since the ls-R
182 # path ordinarily contains many nonexistent directories.
183 testscip-shell system . . test. -d "$db_dir" || continue
184 testscip-shell system . . test. -w "$db_dir" || { echoscip-shell system . . echo. "$progname: $db_dir: directory not writable. Skipping..." >&2; continue; }
185
186 if testscip-shell system . . test. ! -f "$db_file"; then
187 cpscip-shell system . . cp. /dev/nullscip-shell filesystem . . `/dev/null`. "$db_file"
188 # Use same permissions as parent directory, minus x,s, or t bits.
189 chmodscip-shell system . . chmod. `kpsestat -xst "$db_dir"` "$db_file"
190 elif testscip-shell system . . test. -s "$db_file" \
191 && testscip-shell system . . test. "x`sedscip-shell system . . sed. '1s/ $//;1q' \"$db_file\"`" != "x$ls_R_magic" \
192 && testscip-shell system . . test. "x`sedscip-shell system . . sed. '1s/ $//;1q' \"$db_file\"`" != "x$old_ls_R_magic"; then
193 echoscip-shell system . . echo. "$progname: $db_file: no magic string, skipping..." >&2
194 continue
195 fi
196
197 # Skip if we cannot write the file:
198 kpseaccess -w "$db_file" || { echoscip-shell system . . echo. "$progname: $db_file: no write permission, skipping..." >&2; continue; }
199
200 db_dir_tmp="$db_dir/lsR$$.tmp"
201 (umask 077 && mkdirscip-shell system . . mkdir. "$db_dir_tmp" ) \
202 || { echoscip-shell system . . echo. "$progname: $db_dir_tmp: could not create directory, skipping..." >&2; continue; }
203 db_file_tmp="$db_dir_tmp/lsR$$.tmp"
204 rmscip-shell system . . rm. -f "$db_file_tmp"
205
206 $verbose && echoscip-shell system . . echo. "$progname: Updating $db_file... "
207 $dry_run && continue
208
209 echoscip-shell system . . echo. "$ls_R_magic" >"$db_file_tmp"
210
211 # The main task. We put ./: in the output, so top-level files can be
212 # found via ls-R. Probably irrelevant in practice. The sed command
213 # inserts the leading ./ for directory names, and removes ., .., and
214 # version control entries from the list. Also omit contents of any
215 # the version directories; sed apparently requires that we do that
216 # operation in a separate invocation. We do not try to support colons
217 # in directory names.
218 #
219 echoscip-shell system . . echo. "./:" >>"$db_file_tmp"
220 vc_dirs='\.\(bzr\|git\|hg\|svn\)\|_darcs'
221 (cd "$TEXMFLS_R" && \ls -LRa 2>/dev/nullscip-shell filesystem . . `/dev/null`.) \
222 | sedscip-shell system . . sed. -e '/^$/{n;s%^\./%%;s%^%./%;}; /^\.$/d; /^\.\.$/d; /^'$vc_dirs'$/d;' \
223 -e '/^[\.\/]*lsR[0-9]*\.tmp:*$/dscip-shell filesystem . . `/^[\.\/]*lsR[0-9]*\.tmp:*$/d`.' \
224 | sedscip-shell system . . sed. -e /$vc_dirs'.*:$/,/^$/d' \
225 >>"$db_file_tmp"
226
227 # To be really safe, a loop.
228 until PERMS=`kpsestat = "$db_file"`; do sleepscip-shell system . . sleep. 1; done
229 chmodscip-shell system . . chmod. $PERMS "$db_file_tmp"
230 rmscip-shell system . . rm. -f "$db_file"
231 mvscip-shell system . . mv. "$db_file_tmp" "$db_file"
232 rmscip-shell system . . rm. -rf "$db_dir_tmp"
233 done
234
235 $verbose && echoscip-shell system . . echo. "$progname: Done."
236 exit 0