#!/bin/bash # tl-list-format-deps # Create format dependencies # (C) 2015 Norbert Preining # public domain # # check necessary files before we start if ! command -v tlpfiles >/dev/null 2>&1 ; then echo "tlpfiles program not found, exiting!" >&2 exit 1 fi texmfvar=`kpsewhich -var-value TEXMFSYSVAR` texmfroot=`kpsewhich -var-value TEXMFROOT` out=format-deps.`date +%Y%m%d%H%M` if [ -r $out ] ; then echo "output file $out already exists, exiting" >&2 exit 1 else touch $out fi # rebuild all formats with recorder output # needs recent fmtutil! read -p "Should we rebuild all formats with recorder option? (can only be skipped if uptodate .fls/.ofl files are already available!) Y/n: " -t 5 yn case $yn in [Nn]* ) echo "skipping format rebuild!" ;; * ) echo "Rebuilding formats ... please wait a bit!" ; fmtutil-sys --recorder --all --quiet ;; esac # temp dir for created files td=`mktemp -d` # first strip all irrelevant info from the .fls for i in $texmfvar/web2c/*/*.fls $texmfvar/web2c/*/*.ofl ; do fmt=$(basename $i .fls) fmt=$(basename $fmt .ofl) grep -v ^PWD $i | \ grep -v ^OUTPUT | \ awk '{print$2}' | \ sed -e "s!$texmfroot/!!" | \ grep -v '^\./texsys.aux' | \ grep -v '^texmf.cnf' | \ grep -v '^texmf-config' | \ grep -v '^texmf-var' | \ grep -v '^texmf/' | \ cat > $td/$fmt.input done # next collect all files used of all, and uniq them usedfls=`cat $td/*.input | sort | uniq` tlpfiles -fullpath -pkgof "$usedfls" > $td/file-to-pkg for i in $td/*.input ; do fmt=$(basename $i .input) for f in `cat $i` ; do fnd=`grep -P "\t$f" $td/file-to-pkg` if [ -n "$fnd" ] ; then pkg=$(echo $fnd | awk '{print$1}') echo $pkg >> $td/$fmt.packages.tmp echo "$pkg:$f" >> $td/$fmt.input.with-pkgs else echo "cannot find $f for $fmt!" >&2 fi done sort $td/$fmt.packages.tmp | uniq > $td/$fmt.packages echo $fmt >> $out echo "------------" >> $out cat $td/$fmt.packages >> $out echo >> $out rm $td/$fmt.packages.tmp done echo "Output stored in $out" echo "Temporary files in $td, please remove if not needed."