#! /bin/bash
### ====================================================================
### Create binary distributions of TeX Live 2016 in the FTP/HTTP tree.
### Only those for which tex is newer than an existing tar file are
### recreated.
###
### Usage:
###	cd $prefix/texlive/2017/bin
###	./make-texlive-binary-distributions.sh [ dirs ]
###
### [04-Feb-2017] -- adapt from 2016 for TeX Live 2017 builds
### [26-Apr-2016] -- revise to test dates of both tex and asy
### [17-Apr-2016] -- original version
### ====================================================================

prefix=${prefix-/usr/uumath}
test -d $prefix/bin || prefix=/usr/local

PATH=$prefix/bin:/bin:/usr/bin
export PATH

TLYEAR=2017

FTPDIR=/u/ftp/pub/texlive-utah-${TLYEAR}/bin

cd $prefix/texlive/${TLYEAR}/bin
dirs="$@"
test -z "$dirs" && dirs="`find * -prune -type d`"

for d in $dirs
do
    test -f $d/tex || continue

    rebuild=no
    test ! -f $FTPDIR/$d.tar.xz                          && rebuild=yes
    test              \( $d/tex -nt $FTPDIR/$d.tar.xz \) && rebuild=yes
    test -f $d/asy -a \( $d/asy -nt $FTPDIR/$d.tar.xz \) && rebuild=yes

    if test $rebuild = yes
    then
	echo ====== making $FTPDIR/$d.tar.xz

	XZ=-9 tar cfJ $FTPDIR/$d.tar.xz $d
	touch -r $d/tex $FTPDIR/$d.tar.xz
	ls -l $FTPDIR/$d.tar.xz
    else
	touch -r $d/tex $FTPDIR/$d.tar.xz
    fi
done
