summaryrefslogtreecommitdiff
path: root/Master/bin/powerpc-aix/mktexlsr
blob: 663c36c1598581bc2c7ef13198cabeb21ac101eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
# original mktexlsr -- create or rebuild ls-R.
# 
# (If you change or delete the word `original' on the previous line,
# installation won't write this script over yours.)
#
# Suitable for calling from cron, as in:
# 0 * * * * cd /your/texmf/root && /usr/local/bin/mktexlsr
# unless the scripts live in a different directory than the 'kpseaccess',
# 'kpsestat', 'kpsereadlink', and 'kpsewhich' binaries.
# 
# Originally written as `texhash' by Thomas Esser
# <te@dbs.uni-hannover.de>, Okt., 1994.
# Public domain.

version='$Id: mktexlsr,v 1.46 2005/06/21 14:32:26 olaf Exp $'
progname=`echo $0 | sed 's%.*/%%'`
usage="Usage: $progname [DIRS ...]

Rebuild all necessary ls-R filename databases completely. If one or
more arguments DIRS are given, these are used as texmf directories to
build ls-R for. Else all directories in the search path for ls-R files
(\$TEXMFDBS) are used."

# MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
# directories in path lists whereas Unix uses `:'.  Make an exception for
# Cygwin, which pretends to be UNIX.
# Create a variable that holds the right character to be used by the scripts.
DOSISH=no
case `uname -s` in
  CYGWIN*|Cygwin*|cygwin*) ;;
  *) if test -n "$COMSPEC" || test -n "$ComSpec"; then DOSISH=yes; fi
esac
if test "$DOSISH" = "no"; then SEP=':'; else SEP=';';fi


# Add the location of the script to the PATH if necessary.  This must
# be done before kpsewhich can be called, and thus cannot be put into
# mktex.opt.
dirname=`echo $0 | sed 's%/*[^/][^/]*$%%'`
case $dirname in
  "") # Do nothing
      ;;
  /* | [A-z]:/*) # Absolute name
      PATH="$dirname$SEP$PATH"
      export PATH ;;
   *)  # Relative name
      PATH="`pwd`/$dirname$SEP$PATH"
      export PATH ;;
esac

# A copy of some stuff from mktex.opt, so we can run in the presence of
# terminally damaged ls-R files.
if test "x$1" = x--help || test "x$1" = x-help; then
  echo "$usage"
  exit 0
elif test "x$1" = x--version || test "x$1" = x-version; then
  echo "`basename $0` $version"
  kpsewhich --version
  exit 0
fi

# mktexupd and mktexlsr make sure they're coordinated via this.  A copy
# is found mktex.opt.
ls_R_magic='% ls-R -- filename database for kpathsea; do not change this line.'
# The old string, which should continue to work.
old_ls_R_magic='% ls-R -- maintained by MakeTeXls-R; do not change this line.'

trap 'cd / ; test -z "$db_dir_tmp" || rm -rf "$db_dir_tmp"; exit' 0 1 2 3 7 13 15

# Get list of directories from $TEXMFDBS; eliminate duplicates.
test $# = 0 && {
  OIFS=$IFS
  IFS='
'
  set x `kpsewhich --show-path=ls-R | tr : '
' | sort | uniq`; shift
  IFS=$OIFS
}

for TEXMFLS_R in "$@"; do
  # Prepend cwd if the directory was relative.
  case "$TEXMFLS_R" in
  "") continue ;;  # Strictly speaking, it is an error if this case is taken.
  /* | [A-z]:/*) ;;
  *)  TEXMFLS_R="`pwd`/$TEXMFLS_R"
  esac
  # Allow for ls-R and ls-r to exist.  But create ls-R if we're working
  # from scratch.
  if test -f "$TEXMFLS_R/ls-R"; then
    db_file="$TEXMFLS_R/ls-R"
  elif test -f "$TEXMFLS_R/ls-r"; then
    db_file="$TEXMFLS_R/ls-r"
  else
    db_file="$TEXMFLS_R/ls-R"
  fi
  # Follow a possible symlink to get the right filesystem. 
  # The '|| true' construct prevents an sh -e aborting.
  db_readlink=`kpsereadlink "$TEXMFLS_R/ls-R" 2>/dev/null` || true
  case "$db_readlink" in
  "") ;;
  /* | [A-z]:/*) db_file="$db_readlink" ;;
  *)  db_file="$TEXMFLS_R/$db_readlink"
  esac
  db_dir=`echo "$db_file" | sed 's%/[^/][^/]*$%%'` # can't rely on dirname

  test -d "$db_dir" || continue
  test -w "$db_dir" || { echo "$progname: $db_dir: directory not writable. Skipping..." >&2; continue; }

  if test ! -f "$db_file"; then
    cp /dev/null "$db_file"
    # Use same permissions as parent directory, minus x,s, or t bits.
    chmod `kpsestat -xst "$db_dir"` "$db_file"
  elif test -s "$db_file" \
       && test "x`sed '1s/
$//;1q' \"$db_file\"`" != "x$ls_R_magic" \
       && test "x`sed '1s/
$//;1q' \"$db_file\"`" != "x$old_ls_R_magic"; then
    echo "$progname: $db_file lacks magic string. Skipping..." >&2
    continue
  fi

  # Skip if we cannot write the file:
  kpseaccess -w "$db_file" || { echo "$progname: $db_file: no write permission. Skipping..." >&2; continue; }

  db_dir_tmp="$db_dir/lsR$$.tmp"
  (umask 077 && mkdir "$db_dir_tmp" ) \
    || { echo "$progname: could not create directory '$db_dir_tmp'. Skipping..." >&2; continue; }
  db_file_tmp="$db_dir_tmp/lsR$$.tmp"
  rm -f "$db_file_tmp"

  tty -s && echo "$progname: Updating $db_file... " >&2
  echo "$ls_R_magic" >"$db_file_tmp"

  # The main task. We put ./: in the output, so top-level files can be
  # found via ls-R. Probably irrelevant in practice.
  # The sed command inserts the leading ./ for directory names, and
  # removes ., .., and .svn entries from the list.  Also omit contents
  # of any .svn directories; sed apparently requires that we do that
  # operation in a separate invocation.
  # We do not try to support colons in directory names.
  # 
  echo "./:" >>"$db_file_tmp"
  (cd "$TEXMFLS_R" && \ls -LRa 2>/dev/null) \
   | sed -e '/^$/{n;s%^\./%%;s%^%./%;}; /^\.$/d; /^\.\.$/d; /^\.svn$/d;' \
        -e '/^[\.\/]*lsR[0-9]*\.tmp:*$/d' \
   | sed -e '/\.svn.*:$/,/^$/d' \
   >>"$db_file_tmp"

  # To be really safe, a loop.
  until PERMS=`kpsestat = "$db_file"`; do sleep 1; done
  chmod $PERMS "$db_file_tmp"
  rm -f "$db_file"
  mv "$db_file_tmp" "$db_file"
  rm -rf "$db_dir_tmp"
done
tty -s && echo "$progname: Done." >&2
exit 0