Skip to content

Instantly share code, notes, and snippets.

@agrif
Created August 3, 2011 01:53
Show Gist options
  • Save agrif/1121711 to your computer and use it in GitHub Desktop.
Save agrif/1121711 to your computer and use it in GitHub Desktop.
#!/bin/bash
# for emcee, called with the following arguments:
# gen-testrender.sh repourl branch linkname
# --
# usually, this means
# gen-testrender.sh git://github.com/brownan/Minecraft-Overviewer.git master brownan.master
# ----------------------
# ---- BEGIN CONFIG ----
# ----------------------
# local output, and associated web address
# and how long to keep renders around, in days
OUTPUT_DIR="/var/www/org/overviewer/htdocs/renders"
OUTPUT_WEB="http://overviewer.org/renders"
CACHE_TIME=1
# where to store the Overviewer repo, and where to log commands
OUTNAME=`date +%s`
LOGFILE=$OUTNAME.log
# link name to set in the output_dir, usually the branch name
#OUTLINK="other"
OUTLINK=$3
# where to find the exmaple
MAPDIR="../mco-addons/exmaple"
# what repo and branch to use for rendering
#REPO="git://github.com/brownan/Minecraft-Overviewer.git"
REPO=$1
#BRANCH="master"
BRANCH=$2
# python to use, and extra arguments to overviewer
PYTHON_CMD=python2.6
OVERVIEWER_ARGS=""
# --------------------
# ---- END CONFIG ----
# --------------------
# normalize current directory, and redirect our outputs
cd `dirname $0`
exec 3>&1 1>$LOGFILE 2>&1
# ubiquitus "clean up and return error" command
die()
{
rm -rf `dirname $0`/$OUTNAME
echo "render failed" >3
exit 1
}
# fetch the latest exmaple, (external command)
# and store it's SHA1
./gen-exmaple.sh || die
MAPHASH=`cat ../mco-addons/.git/refs/heads/master | cut -c1-7`
# clone our repo and copy in settings.py
git clone $REPO $OUTNAME || die
if [ -e settings.py ]; then
cp settings.py $OUTNAME/ || die
fi
# fetch and store the latest terrain.png (external command)
./gen-terrainpng.sh || die
# enter the checked-out repo
pushd $OUTNAME || die
# checkout the branch we want, and construct the overviewer-map hash
git checkout $BRANCH || die
MAINHASH=`git rev-parse HEAD | cut -c1-7`
WEBNAME=$MAINHASH-$MAPHASH
# if the render already exists, cleanup and exit
if [ -d $OUTPUT_DIR/$WEBNAME ]; then
# echo the web address
echo $OUTPUT_WEB/$WEBNAME >&3
# pop out, and remove the log / repo
popd
rm -rf $OUTNAME
rm -f $LOGFILE
# update the named link mtime
rm -f $OUTPUT_DIR/$OUTLINK
ln -s $WEBNAME $OUTPUT_DIR/$OUTLINK
exit 0
fi
# build overviewer, and pop out
$PYTHON_CMD setup.py build || die
popd || die
# construct a list of supported rendermodes
RENDERMODES=`$PYTHON_CMD ./$OUTNAME/overviewer.py --list-rendermodes | awk -- '{print $1}' | tr '\n' ',' | sed 's/.$//'`
# render!
$PYTHON_CMD ./$OUTNAME/overviewer.py --rendermodes=$RENDERMODES $OVERVIEWER_ARGS $MAPDIR $OUTPUT_DIR/$WEBNAME || die
# clean up the repo and log
rm -rf $OUTNAME
rm -f $LOGFILE
# touch renders with active links
touch `find $OUTPUT_DIR -maxdepth 1 -mindepth 1 -type l`
# clean up old renders
find $OUTPUT_DIR/ -maxdepth 1 -mindepth 1 -mtime +${CACHE_TIME} -type d | xargs rm -rf 1>/dev/null 2>&1
# remove broken links
find -L $OUTPUT_DIR -maxdepth 1 -mindepth 1 -type l -delete
# update the named link mtime
rm -f $OUTPUT_DIR/$OUTLINK
ln -s $WEBNAME $OUTPUT_DIR/$OUTLINK
# print the output url
echo $OUTPUT_WEB/$WEBNAME >&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment