#!/bin/ksh93 . /lib/svc/share/smf_exit_codes.sh # License: CDDL 1.0 (see http://opensource.org/licenses/cddl-1.0) # Copyright 2015 Jens Elkner. # To force an update manually, remove the file /var/texlive/tstamp and restart # this aka texhash-updatis aka texhash-update service. TEXPKG_DIR='/var/texlive' # The idea is, that each tex package installs a file into this directory and # has the SMF actuator 'restart_fmri svc:/application/texhash-update:default' # attached in the coresponding IPS manifest. Based on the directory # modification time (file added|removed) and the file name 'tstamp' the service # decides, whether to it should update all configs, or not. # The name of the file delivered by a package needs to be uniq to avoid # interference with other packages, so e.g. ${PKGNAME//\//_} - but remember # 'tstamp' is reserved for this package (texhash-update). # Since IPS has no postinstall support and it would be too cumbersome to mimic # it (there is no way, to leave a file on uninstall unless preserved, but than # its content may change -> unreliable), the important config files get rebuilt # completely, if needed. # The file must be a shell snippet, which defines the following variables: # MAP= # Whitespace separated list of Map file names to add to web2c/updmap.cfg # MIXEDMAP= # Whitespace separated list of MixedMap file names to add to web2c/updmap.cfg # KANJIMAP= # Whitespace separated list of KanjiMap file names to add to web2c/updmap.cfg # FORMAT=( ) # Indexed array with all the lines which need to be add to web2c/fmtutil.cnf # on a as is base. So they need to follow the format rules of this file! # HYPHEN=() # Indexed array with where each entry is a whitespace separated record with # the following fields: # (0)fromPkgName (1)name (2)synonyms (3)lefthyphmin=2 (4)righthyphmin=3 # (5)file (6)filePatterns (7)fileExceptions (8)luaspecial # The field 6..8 are optional. Since position are important, one may use a # '-' to mark a field as empty/unset. Field (8) may contain whitespaces, # however, since field splitting is made on whitespaces one need to use the # octal reprensentation (i.e. '\040') to get the full value passed properly! # E.g. "disabled:only\ for\ 8bit" => "disabled:only\040for\0408bit" - since # the value gets quoted automatically, DON'T quote it (here it is just used # for better readability). # Execution order is: texhash; mtxrun; updmap; fmtutil # Make sure, that source snippets do not overwrite typeset -r BASEDIR='@CLIENT_BASEDIR@' \ TEXHASH="${BASEDIR}/bin/mktexlsr" \ KPSEWHICH="${BASEDIR}/bin/kpsewhich" \ UPDMAP="${BASEDIR}/bin/updmap" \ FMTUTIL="${BASEDIR}/bin/fmtutil" \ MTXRUN="${BASEDIR}/bin/mtxrun" \ TSTAMP='tstamp' typeset -A -r MAPNAME=( [MAP]=Map [MIXEDMAP]=MixedMap [KANJIMAP]=KanjiMap ) export PATH="${BASEDIR}/bin:${PATH}" # otherwise the perl util runs will fail function getConfig { [[ -f $1 ]] || return 0 typeset -n MAPR=$2 MIXEDMAPR=$3 KANJIMAPR=$4 FORMATR=$5 HYPHENR=$6 typeset MAP= MIXEDMAP= KANJIMAP= FORMAT= HYPHEN= . "$1" MAPR+=" ${MAP}" MIXEDMAPR+=" ${MIXEDMAP}" KANJIMAPR+=" ${KANJIMAP}" FORMATR+=( "${FORMAT[@]}" ) HYPHENR+=( "${HYPHEN[@]}" ) } function writeConfigs { typeset -n MAP=$1 MIXEDMAP=$2 KANJIMAP=$3 FORMAT=$4 HYPHEN=$5 typeset A M V X Y= DAT DEF LUA for X in MAP MIXEDMAP KANJIMAP ; do typeset -n M=$X [[ -z $M ]] && continue for V in $M ; do Y+="\n${MAPNAME[$X]} $V" done done if [[ -n $Y ]]; then V=$(web2c/updmap.cfg fi Y= for X in "${FORMAT[@]}"; do [[ -z $X ]] && continue Y+="\n$X" done if [[ -n $Y ]]; then V=$(web2c/fmtutil.cnf fi Y="${HYPHEN[@]}" [[ -n $Y ]] || return 0 X=$( 0x07ddLanguage X=$(tex/generic/config/language.dat print "${DEF}\n\\uselanguage {USenglish}" >tex/generic/config/language.def if [[ -n ${LUA} ]]; then X=$(tex/generic/config/language.dat.lua fi } function updateFontconfig { typeset C X CFG= FPATH= DIST integer OK=1 TEXMFROOT=${ ${KPSEWHICH} -expand-var='$TEXMFROOT' ; } [[ -z ${TEXMFROOT} ]] && TEXMFROOT="${BASEDIR}/share/texmf" FPATH=${ ${KPSEWHICH} -expand-var='$FONTCONFIG_PATH' ; } [[ -z ${FPATH} ]] && FPATH="${TEXMFROOT}/var/fonts/conf" CFG="${FPATH}/texlive-fontconfig.conf" # since this might be manually changed, we do not overwrite blindly but # create only if missing. if [[ ! -e ${CFG} ]]; then DIST=${ ${KPSEWHICH} -expand-var='$TEXMFDIST' ; } [[ -z ${DIST} ]] && DIST="${TEXMFROOT}/dist" C=' ' for X in opentype truetype type1 ; do C+="\t${DIST}/fonts/$X\n" done C+='' if [[ ! -d ${FPATH} ]]; then mkdir -p "${FPATH}" || OK=0 fi (( OK )) && print "$C" >"${CFG}" || OK=0 (( OK )) || print -u2 "# Unable to create ${CFG}:\n$C\n" fi } function updateDBs { for X in ${TEXHASH} ${KPSEWHICH} ; do if [[ ! -x $X ]]; then print -u2 "'$X' is not executable - texhash updates skipped." # This is not an error - the base package might not have been # installed yet or got removed. return ${SMF_EXIT_OK} fi done [[ -d ${TEXPKG_DIR} ]] || mkdir -p ${TEXPKG_DIR} || \ return ${SMF_EXIT_ERR_PERM} cd ${TEXPKG_DIR} || exit ${SMF_EXIT_ERR_PERM} # We insist on a real file: -ot test works for real files, only # (stats the entry, not dst ...). [[ -f ${TSTAMP} && ${TSTAMP} -nt . ]] && return ${SMF_EXIT_OK} if [[ -e ${TSTAMP} && ! -f ${TSTAMP} ]]; then rm -f ${TSTAMP} || return ${SMF_EXIT_ERR_PERM} fi typeset DIRS=${ ${KPSEWHICH} --show-path=ls-R ; } if [[ -n ${DIRS} ]]; then ${TEXHASH} ${DIRS//:/ } && touch ${TSTAMP} # mtxrun (conTeXt) is not part of the base package, so take care ... [[ -x ${MTXRUN} ]] && ${MTXRUN} --generate #${MTXRUN} --script font --reload # ??? fi typeset FILES= for X in ~(N)${TEXPKG_DIR}/* ; do [[ -n $X ]] && FILES+=" $X" done [[ -z ${FILES} ]] && return ${SMF_EXIT_OK} typeset MAP= MIXEDMAP= KANJIMAP= FORMAT= HYPHEN= \ DIST=${ ${KPSEWHICH} -expand-var='$TEXMFDIST' ; } [[ -z ${DIST} ]] && DIST="${BASEDIR}/share/texmf/dist" if [[ ! -d ${DIST}/web2c ]]; then print -u2 "Invalid TEXMFDIST directory '${DIST}'" return ${SMF_EXIT_ERR_FATAL} fi [[ -d ${DIST%/*}/config/web2c ]] || mkdir -p ${DIST%/*}/config/web2c [[ -d ${DIST%/*}/local ]] || mkdir -p ${DIST%/*}/local cd "${DIST}" for X in ${FILES} ; do getConfig $X MAP MIXEDMAP KANJIMAP FORMAT HYPHEN done writeConfigs MAP MIXEDMAP KANJIMAP FORMAT HYPHEN ${UPDMAP} --sys --syncwithtrees --nohash