#!/bin/sh # Script to install and remove texmf tarballs # Copyright (C) 2006, 2007 Marco Kuhlmann # A texmf tarball is a tar.gz file that contains a TDS-compliant # directory structure. set -e # global variables OWNERSHIP="${OWNERSHIP:-root:wheel}" TGTDIR="${TGTDIR:-$(kpsexpand '$TEXMFLOCAL')}" UPDMAP="${UPDMAP:-updmap-sys --quiet}" me="$(basename $0)" # log MESSAGE # Logs MESSAGE to the standard error stream. function log() { echo "$me: $1" >&2 } # check_tgtdir # Check whether the TGTDIR variable points to a valid directory. function check_tgtdir() { if test "x${TGTDIR}" = "x"; then log "no target directory given" exit 1 fi if ! test -d "${TGTDIR}"; then log "target directory (\$TGTDIR) does not exist" exit 1 fi log "target directory is ${TGTDIR}" } # check_pkgfile PKGFILE # Check whether PKGFILE exists. function check_pkgfile() { if ! test -f "$1"; then log "package file '$1' does not exist" exit 1 fi } # get_contents PKGFILE # Lists the contents of PKGFILE in a temporary file and returns the # name of that file. function get_contents() { tmp=$(mktemp texmftool.XXXX) for x in $(tar --list --gzip --file "$1"); do echo "${TGTDIR}/$x" done > "${tmp}" echo "${tmp}" } # get_fontmaps CONTENTS # Returns the names of the map files listed in CONTENTS. function get_fontmaps() { for f in $(cat "$1" | grep ".*.map$"); do echo "$(basename $f)" done } # finish RUN_MKTEXLSR RUN_UPDMAP # update the filename database and recreate the fontmap function finish() { if test "$1" = "yes"; then log "updating filename database ..." mktexlsr "${TGTDIR}" >/dev/null 2>&1 if test "$2" = "yes"; then log "recreating fontmap ..." ${UPDMAP} fi fi } # install PKGFILE TGTDIR # installs the texmf tarball PKGFILE into the TGTDIR texmf tree function install() { check_tgtdir run_mktexlsr="no" run_updmap="no" for pkgfile in $@; do check_pkgfile="${pkgfile}" tmp=$(get_contents "${pkgfile}") log "installing '$(basename ${pkgfile})' ..." log " extracting package contents ..." cat "${pkgfile}" | (cd "${TGTDIR}"; tar --extract --gzip) log " setting the permissions of the extracted files ..." cat "${tmp}" | xargs chown "${OWNERSHIP}" for map in $(get_fontmaps "${tmp}"); do log " enabling font map '${map}' ..." ${UPDMAP} --nomkmap --enable Map "${map}" run_updmap="yes" done rm -f "${tmp}" run_mktexlsr="yes" done finish "${run_mktexlsr}" "${run_updmap}" exit 0 } # remove PKGFILE TGTDIR # removes the texmf tarball PKGFILE from the TGTDIR texmf tree function remove() { check_tgtdir run_mktexlsr="no" run_updmap="no" for pkgfile in $@; do check_pkgfile "${pkgfile}" tmp=$(get_contents "${pkgfile}") log "removing '$(basename ${pkgfile})' ..." for map in $(get_fontmaps "${tmp}"); do log " disabling font map '${map}' ..." ${UPDMAP} --nomkmap --disable "${map}" run_updmap="yes" done log " removing package contents ..." for f in $(cat "${tmp}"); do if test -f "$f"; then echo "$f" fi done | xargs rm log " deleting empty directories ..." for d in $(cat "${tmp}" | sed '1!G;h;$!d'); do if test -d "$d" && test "x$(ls $d)" = "x"; then echo "$d" fi done | xargs rm -d rm -f "${tmp}" run_mktexlsr="yes" done finish "${run_mktexlsr}" "${run_updmap}" exit 0 } case "$1" in install) shift; install $@ ;; remove) shift; remove $@ ;; esac log "unknown command '$1'" exit 1