#! /bin/sh -
### ====================================================================
### Make a new TeX Live daily snapshot (but do nothing if it already
### exists), rsync'ing differences from a base snapshot to save time.
###
### Usage:
###	./make-texlive-snapshot-2023.sh
###
### [04-Feb-2025] -- adapt from make-texlive-snapshot-2024.sh for 2025 builds
### [05-Mar-2024] -- adapt from make-texlive-snapshot-2023.sh for 2024 builds
### [18-Feb-2023] -- adapt from make-texlive-snapshot-2022.sh for 2023 builds
### [05-Jan-2022] -- adapt from make-texlive-snapshot-2021.sh for 2022 builds
### [06-Jan-2021] -- adapt from make-texlive-snapshot-2020.sh for 2021 builds
### [23-Dec-2019] -- adapt from make-texlive-snapshot-2019.sh for 2020 builds
### [25-Mar-2019] -- adapt from make-texlive-snapshot-2018.sh for 2019 builds
### [17-Jan-2018] -- adapt from make-texlive-snapshot-2017.sh for 2018 builds
### [04-Feb-2017] -- adapt from make-texlive-snapshot-2016.sh for 2017 builds
### [04-Mar-2016] -- adapt from make-texlive-snapshot-2015.sh for 2016 builds
### [28-Mar-2015] -- update for 2015
### [19-Apr-2012] -- original version
### ====================================================================

IFS='
 	'

PATH=/usr/uumath/bin:/usr/local/bin:/bin:/usr/bin
export PATH

date

YMD=`date +%Y%m%d`
BASESHOT=${BASESHOT:=texlive-20250204}
SNAPSHOT=texlive-$YMD
YEAR=`date +%Y`
test -d $YEAR || mkdir $YEAR

## Create a corresponding log directory if one does not yet exist
test -d logs/$YEAR/$SNAPSHOT || mkdir -p logs/$YEAR/$SNAPSHOT

test -d $YEAR/$SNAPSHOT && echo $YEAR/$SNAPSHOT already exists && exit 1

cd $YEAR
mkdir $SNAPSHOT || exit 1

## For faster rsync, copy the base snapshot, if it exists, into the new
## snapshot directory, so we only have to transfer updates.
if test -d ../$BASESHOT
then
    cd $SNAPSHOT
    (cd ../$BASESHOT; tar cf - . ) | tar xf -
    cd ..
fi

## Suppress useless display of directories by final grep stage
date
time /usr/local/bin/rsync -a --delete --exclude=.svn tug.org::tldevsrc/Build/source $SNAPSHOT 2>&1 | grep -v '/$'

date
time env GZIP=-9 tar cfz ../$SNAPSHOT.tar.gz $SNAPSHOT

date
test -r $BASESHOT -a -r $SNAPSHOT && diff -r $BASESHOT $SNAPSHOT > foo.dif.$YMD 2>&1

cd ..

ls -l $SNAPSHOT.tar.gz

echo DONE ...
date
