home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / texlatex.zip / web2c72.zip / bin / mktexlsr < prev    next >
Text File  |  1999-11-04  |  4KB  |  125 lines

  1. #!sh
  2. # original mktexlsr -- create or rebuild ls-R.
  3. # (If you change or delete the word `original' on the previous line,
  4. # installation won't write this script over yours.)
  5. #
  6. # Suitable for calling from cron, as in:
  7. # 0 * * * * cd /your/texmf/root && /usr/local/bin/mktexlsr
  8. # unless the scripts live in a different directory than the 'access',
  9. # 'kpsestat', 'readlink', and 'kpsewhich' binaries.
  10. # Originally written as `texhash' by Thomas Esser
  11. # <te@informatik.uni-hannover.de>, Okt., 1994.
  12. # Public domain.
  13.  
  14. version='$Id: mktexlsr,v 1.21 1998/03/17 22:26:01 olaf Exp $'
  15. progname=`echo $0 | sed 's%.*/%%'`
  16. usage="Usage: $progname [DIRS ...]
  17.  
  18. Rebuild all necessary ls-R filename databases completely. If one or
  19. more arguments DIRS are given, these are used as texmf directories to
  20. build ls-R for. Else all directories in the search path for ls-R files
  21. (\$TEXMFDBS) are used."
  22.  
  23. # MS-DOS and MS-Windows define $COMSPEC or $ComSpec and use `;' to separate
  24. # directories in path lists whereas Unix uses `:'.
  25. # Create a variable that holds the right character to be used by the scripts.
  26. if test -z "$COMSPEC" && test -z "$ComSpec"; then SEP=':'; else SEP=';'; fi
  27.  
  28. # Add the location of the script to the PATH if necessary.  This must
  29. # be done before kpsewhich can be called, and thus cannot be put into
  30. # mktex.opt.
  31. dirname=`echo $0 | sed -e 's%/*[^/][^/]*$%%' -e 's%^.:%%'`
  32. case $dirname in
  33.   "") # Do nothing
  34.       ;;
  35.   /* | [A-z]:/*) # Absolute name
  36.       PATH="$dirname$SEP$PATH" ;;
  37.    *)  # Relative name
  38.       PATH="`pwd`/$dirname$SEP$PATH" ;;
  39. esac
  40.  
  41. # A copy of some stuff from mktex.opt, so we can run in the presence of
  42. # terminally damaged ls-R files.
  43. if test "x$1" = x--help || test "x$1" = x-help; then
  44.   echo "$usage"
  45.   exit 0
  46. elif test "x$1" = x--version || test "x$1" = x-version; then
  47.   echo "`basename $0` $version"
  48.   kpsewhich --version
  49.   exit 0
  50. fi
  51.  
  52. # mktexupd and mktexlsr make sure they're coordinated via this.  A copy
  53. # is found mktex.opt.
  54. ls_R_magic='% ls-R -- filename database for kpathsea; do not change this line.'
  55.  
  56.  
  57. trap 'cd / ; rm -f "$db_file_tmp"; exit' 1 2 15
  58.  
  59. test $# = 0 && {
  60.   OIFS=$IFS; IFS=$SEP; set x `kpsewhich --show-path=ls-R`; shift; IFS=$OIFS
  61. }
  62. for TEXMFLS_R in "$@"; do
  63.   # Prepend cwd if the directory was relative.
  64.   case "$TEXMFLS_R" in
  65.   "") continue ;;
  66.   /* | [A-z]:/*) ;;
  67.   *)  TEXMFLS_R="`pwd`/$TEXMFLS_R"
  68.   esac
  69.   # Follow a possible symlink to get the right filesystem, 
  70.   db_file=`readlink "$TEXMFLS_R/ls-R" 2>/dev/null`
  71.   case "$db_file" in
  72.   "") db_file="$TEXMFLS_R/ls-R" ;;
  73.   /* | [A-z]:/*) ;;
  74.   *)  db_file="$TEXMFLS_R/$db_file"
  75.   esac
  76.   db_dir=`echo "$db_file" | sed -e 's%/[^/][^/]*$%%' -e's%^.:%%'` # can't rely on dirname
  77.   db_file_tmp="$db_dir/lsR$$.tmp"
  78.  
  79.   test -d "$db_dir" || continue
  80.   test -w "$db_dir" || { echo "$progname: $db_dir: directory not writable. Skipping..." >&2; continue; }
  81.  
  82.   if test ! -f "$db_file"; then
  83.     cp /dev/null "$db_file"
  84.     # Use same permissions as parent directory, minus x,s, or t bits.
  85.     chmod `kpsestat -xst "$db_dir"` "$db_file"
  86.   fi
  87.  
  88.   # Skip if we cannot write the file:
  89.   access -w "$db_file" || { echo "$progname: $db_file: no write permission. Skipping..." >&2; continue; }
  90.  
  91.   rm -f "$db_file_tmp"
  92.  
  93.   tty -s && echo "$progname: Updating $db_file... "
  94.   echo "$ls_R_magic" >"$db_file_tmp"
  95.  
  96.   # The main task. We ls two things so the top-level directory name ends
  97.   # up in the output, so top-level files can be found via ls-R. Probably
  98.   # irrelevant in practice.
  99.   # The sed command is because on new FreeBSD/NetBSD systems, ls -LAR ./
  100.   # produces .//. Sigh.
  101.   #  (cd "$TEXMFLS_R" && \ls -LRa /dev/null ./ 2>/dev/null) |
  102.   #    sed 's%\.//%./%; /^\.$/d; /^\.\.$/d' |
  103.   #    sed 's@\.//@./@' \
  104.   #    sed '1i\
  105.   #./:
  106.   #s/.*:/\.\/&/g' \
  107.   #>>"$db_file_tmp"
  108. (cd $TEXMFLS_R && ls -LAR /dev/null ./ 2>/dev/null) \
  109. | sed 's@\.//@./@' \
  110. | sed '1i\
  111. ./:
  112. s/.*:/\.\/&/g' \
  113. >>$db_file_tmp
  114.  
  115.   # To be really safe, a loop.
  116.   until PERMS=`kpsestat = "$db_file"`; do sleep 1; done
  117.   chmod $PERMS "$db_file_tmp"
  118.   rm -f "$db_file"
  119.   mv "$db_file_tmp" "$db_file"
  120. done
  121. tty -s && echo "$progname: Done."
  122. exit 0
  123.