#!/bin/sh # Copyright Thomas Esser, 1999, 2002, 2003. public domain. # texlinks: script to maintain symlinks from format to engine. Interprets # the lines given in fmtutil.cnf. # History: # Mon May 10 20:52:48 CEST 2004 # kpseaccess instead of access # Thu Dec 25 22:11:53 CET 2003, te: # add version string # Tue Apr 9 22:46:34 CEST 2002, te: # do not create symlinks for cont-??, metafun and mptopdf test -f /bin/sh5 && test -z "$RUNNING_SH5" \ && { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \ && { RUNNING_SH5=true; export RUNNING_SH5; exec /bin/sh5 $0 ${1+"$@"}; } unset RUNNING_SH5 test -f /bin/bsh && test -z "$RUNNING_BSH" \ && { UNAMES=`uname -s`; test "x$UNAMES" = xAIX; } 2>/dev/null \ && { RUNNING_BSH=true; export RUNNING_BSH; exec /bin/bsh $0 ${1+"$@"}; } unset RUNNING_BSH # hack around a bug in zsh: test -n "${ZSH_VERSION+set}" && alias -g '${1+"$@"}'='"$@"' cnf=fmtutil.cnf # name of the config file version=1084215212 # seconds since `00:00:00 1970-01-01 UTC' # date '+%s' (with GNU date) progname=texlinks usage='texlinks [options] [directories] Create symbolic links format -> engine according to fmtutil setup. Valid options: --help -h show this help text --version show version string --cnffile file -f file use file as config file (default: fmtutil.cnf) --verbose -v set verbose mode on (default: off) --multiplatform -m operate in all platform specific directories (default: operate only in directory for this platform) --silent -s silently skip over existing scripts / binaries instead of creating a warning directories is an optional list of directories in which to operate. If no directories are specified the list of directories depends on the --multiplatform option. ' ############################################################################### # abort(errmsg) # print `errmsg' to stderr and exit with error code 1 ############################################################################### abort() { errmsg "texlinks: $1."; false; cleanup; } # error message to stderr: errmsg() { echo "$@" >&2; } # give message to stderr only if "verbose" mode is on: verbose_echo() { $verbose && errmsg "$@"; } # in verbose mode: show command that is executed: verbose_do() { verbose_echo "$@"; "$@"; } ############################################################################### # cleanup() # clean up the temp area and exit with proper exit status ############################################################################### cleanup() { rc=$? $needsCleanup && test -n "$tmpdir" && test -d "$tmpdir" \ && { rm -f "$tmpdir"/*; cd /; rmdir "$tmpdir"; } exit $rc } ############################################################################### # setupTmpDir() # set up a temp directory and a trap to remove it ############################################################################### setupTmpDir() { $needsCleanup && return trap 'cleanup' 1 2 3 7 13 15 needsCleanup=true } # search a binary along $PATH: check_for_binary() { testbin=$1 set x `echo "$PATH" | sed 's/^:/.:/; s/:$/:./; s/::/:.:/g; s/:/ /g'`; shift for i do if [ -x "$i/$testbin" ]; then echo "$i/$testbin" return 0 fi done return 1 } ############################################################################### # install_link(dest src) # create a symlink like ln -s dest src, but make sure that src is not # an existing binary ############################################################################### install_link() { # make symlink src -> dest dest=$1; src=$2 case $src in */mf) if test $dest = "mf-nowin" && test -f $selfautoloc/mfw; then dest="mfw" verbose_echo "both mfw and mf-nowin exists, $src linked to $dest" fi ;; esac case $src in */cont-??|*/metafun|*/mptopdf) verbose_echo "symlink $2 -> $dest skipped (special case)" ;; */csplain|*/cslatex|*/pdfcslatex|*/pdfcsplain) verbose_do rm -f "$src" cat > $src <<'eof' #!/bin/sh test -f /bin/sh5 && test -z "$RUNNING_SH5" \ && { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \ && { RUNNING_SH5=true; export RUNNING_SH5; exec /bin/sh5 $0 ${1+"$@"}; } unset RUNNING_SH5 test -f /bin/bsh && test -z "$RUNNING_BSH" \ && { UNAMES=`uname -s`; test "x$UNAMES" = xAIX; } 2>/dev/null \ && { RUNNING_BSH=true; export RUNNING_BSH; exec /bin/bsh $0 ${1+"$@"}; } unset RUNNING_BSH # hack around a bug in zsh: test -n "${ZSH_VERSION+set}" && alias -g '${1+"$@"}'='"$@"' eof cat >> $src < $tmpdir/cnf_file_ln if test -z "$dirs"; then if test $multiplatform = true; then case $selfautoloc in */bin) dirs=$selfautoloc;; *) parent=`kpsewhich --expand-var='$SELFAUTODIR'` dirs=`find $parent -type f -name kpsewhich -print \ | sed 's@/kpsewhich$@@'`;; esac else dirs=$selfautoloc fi fi for d in $dirs; do kpseaccess -w $d \ || { errmsg "$d: no write permissions. Skipping..."; continue; } # $tmpdir/cnf_file_ln has lines with "format engine" pairs set x `cat $tmpdir/cnf_file_ln`; shift while test $# != 0; do fmt=$1; engine=$2; shift; shift # Some broken shells destroy the positional arguments when calling a # shellfunction. Therefore, we save and restore them "by hand" in the # main_args_while variable. main_args_while="$@" test "x$fmt" = "x$engine" && continue if test -f "$d/$engine"; then install_link "$engine" "$d/$fmt" else verbose_echo "$d/$engine: engine does not exist. Skipping..." fi # restore positional arguments: set x $main_args_while; shift done done upd_symlinkdir } main ${1+"$@"} # set successful return code true cleanup