#!/bin/sh

LOGFILE=logs/generate-cve-logfile.txt.`date +"%Y-%m-%d:%H-%M-%S"`

cd cve
# the cve script occasionally manages to commit and tag, but not to push for some reason
git push -q
git push -q --tags
# if the cve script failed before, do its git actions again before it consumes 2GB memory
if git status . | grep modified > /dev/null; 
then
	git add * >/dev/null 2>&1
	git commit -q -m "intermediate sync" >/dev/null 2>&1
	git tag deploy-0.22.`date +'%Y%m%d%H%m%S'`
	git push
	git push --tags
fi
cd ..
perl bin/generate-cve-dirs.pl >$LOGFILE 2>&1

if ! grep SUCCESS $LOGFILE >/dev/null ; then
	echo "bin/generate-cve-dirs.pl failed:"
	tail -n 100 $LOGFILE
else
	rm $LOGFILE
fi
