#! /bin/bash
# Update local repository with JSmol from a ZIP archive.
# Usage: ./update.sh <JSmol_ZIP_archive>

jsmol=$1
echo $jsmol

find . -mindepth 2 -name CVS -printf "%h\n" | sort > /tmp/olddirs
find . -mindepth 2 -type f | grep -v CVS | sort > /tmp/oldfiles

rm `find . -mindepth 2 -type f | grep -v CVS`

unzip $jsmol
cp jsmol/JSmol.min.js .
cp -r jsmol/j2s .
cp -r jsmol/js .
rm -rf jsmol 

find . -mindepth 2 -type f -printf "%h\n" | grep -v CVS | sort | uniq > /tmp/curdirs
find . -mindepth 2 -type f | grep -v CVS | sort > /tmp/curfiles

rmdirs=`comm -23 /tmp/olddirs /tmp/curdirs | sort -r`
if [ "x$rmdirs" != "x" ]; then
	cvs delete $rmdirs
fi

mkdirs=`comm -13 /tmp/olddirs /tmp/curdirs`
if [ "x$mkdirs" != "x" ]; then
	cvs add $mkdirs
fi

rmfiles=`comm -23 /tmp/oldfiles /tmp/curfiles`
if [ "x$rmfiles" != "x" ]; then
	cvs delete $rmfiles
fi

mkfiles=`comm -13 /tmp/oldfiles /tmp/curfiles`
if [ "x$mkfiles" != "x" ]; then
	cvs add $mkfiles
fi

rm /tmp/olddirs /tmp/oldfiles /tmp/curdirs /tmp/curfiles

