diff options
Diffstat (limited to 'support/TeX4ht/source/update-htfonts')
-rwxr-xr-x | support/TeX4ht/source/update-htfonts | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/support/TeX4ht/source/update-htfonts b/support/TeX4ht/source/update-htfonts new file mode 100755 index 0000000000..20c37cbb3a --- /dev/null +++ b/support/TeX4ht/source/update-htfonts @@ -0,0 +1,130 @@ +#!/bin/sh +# $Id: update-htfonts 1061 2022-01-20 22:17:17Z karl $ +# Public domain. Originally written by Karl Berry, 2022. + +# don't bother with real option parsing. +if test $# -ne 3; then +cat <<END_USAGE +Usage: $0 [ diff | update ] HTF-DEVDIR HTF-INSTDIR +END_USAGE + exit 1 +fi + +cp="cp -pv" +mkdir="mkdir -v" +svn=svn + +if test x"$1" = xdiff; then + shift + do_updates=false + cp="echo would $cp" + mkdir="echo would $mkdir" + svn="echo would $svn" + +elif test x"$1" = xupdate; then + shift + do_updates=true +else + echo "$0: first arg must be \`diff' or \`update', not: $1" >&2 + exit 1 +fi + +devdir=$1 +instdir=$2 +verbose=true +tmp=/tmp/htdif # prefix + +if test ! -d "$devdir"; then + echo "$0: devdir not a directory: $devdir" >&2 + exit 1 +fi +if test ! -d "$instdir"; then + echo "$0: instdir not a directory: $instdir" >&2 + exit 1 +fi + + +# Function to copy SRC to DEST, or fail. Just calls $cp. +# +copy_file () { + src=$1; dest=$2 + # + # show diff from (older) DEST to newer (SRC). + diff -u0 "$dest" "$src" >>$tmp.0 + # + if $cp "$src" "$dest"; then :; else + echo "$0: copy ($cp) failed: $src -> $dest" >&2 + exit 1 + fi +} + +# Function to compare SRC to DEST. Return zero if equivalent, +# nonzero if different (or DEST does not exist, etc.). +# +# Remove a timestamp string from both files for comparison: +# YYYY-MM-DD-HH:MM or just YYYY-MM-DD +# +htf_same () { + src=$1; dest=$2; + # + src_filtered=$tmp.s`basename "$src"` + dest_filtered=$tmp.d`basename "$dest"` + # + sed 's/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]\(-[0-9][0-9]:[0-9][0-9]\)*//' \ + $src >$src_filtered || exit 1 + sed 's/20[0-9][0-9]-[0-9][0-9]-[0-9][0-9]\(-[0-9][0-9]:[0-9][0-9]\)*//' \ + $dest >$dest_filtered || exit 1 + cmp -s "$src_filtered" "$dest_filtered" +} + +# Iterate through all files in the dev directory. +echo "$0: comparing $devdir" +echo "$0: to $instdir" +>$tmp.0 # accumulate diffs here +# +find "$devdir" -type f -print | sort | while read devf; do + instf=`echo "$devf" | sed "s,^$devdir/,$instdir/,"` + if test -r "$instf"; then + # we have a file in both directories; see if they are the same (enough). + if htf_same "$devf" "$instf"; then + : # $verbose && echo "`basename \"$devf\"`: same ($devf == $instf)" + else + $verbose && echo "`basename \"$devf\"`: diff ($devf != $instf)" + copy_file "$devf" "$instf" + fi + + else + # no destination file. see if we have the containing directory. + destdirf=`dirname "$instf"` + if test -d "$destdirf"; then + # have directory, so add file. + $verbose && echo "newfile ($devf -> $instf)" + copy_file "$devf" "$instf" + $svn add "$devf" + else + # don't even have directory. create it, then copy file. + $mkdir "$destdirf" + $verbose && echo "newdir ($devf -> $destdirf)" + if test ! -d "$destdirf"; then + echo "$0: could not make dest dir: $destdirf (for $devf->$instf)" >&2 + exit 1 + fi + $svn add "$destdirf" + copy_file "$devf" "$instf" + $svn add $devf + fi + fi +done + +# check for extra files in $instdir +(cd "$devdir" && find . -type f -print | sort) >$tmp.devdir || exit 1 +(cd "$instdir" && find . -type f -print | sort) >$tmp.instdir || exit 1 + +echo "Files in devdir and not in instdir (should be empty):" +comm -23 $tmp.devdir $tmp.instdir + +echo "Files in instdir and not in devdir, you should remove:" +comm -13 $tmp.devdir $tmp.instdir +# maybe better to leave it for manual removal? + +echo "Done." |