#!/bin/bash

#	Script to rebuild the current user's sandbox

#	Set environment
umask 002
export MACHTYPE=`uname -m`
export PATH=/usr/local/bin:/bin:/usr/bin:/cluster/bin/${MACHTYPE}:${HOME}/bin/${MACHTYPE}:/cluster/bin:/cluster/bin/scripts:${HOME}/bin:${HOME}/bin/scripts/
if [ -z "${USER}" ]; then
	USER="otto"
	export USER
fi

#	Clean up the source tree
#cd $HOME/kent/src && make clean > /dev/null 2> /dev/null && rm -f tags

#	Update the source tree
cd $HOME/kent
git pull > $HOME/git.pull.output 2>&1
if [ $? -ne 0 ]; then
    echo "git pull failed, see $HOME/git.pull.output" | \
        mail -s 'Git pull error on kent tree' "gbauto@ucsc.edu"
    printf "git pull failed, see $HOME/git.pull.output\n" 1>&2
    exit 255
fi

#	Build the CGIs
#cd ~/kent/src
#make -j 40 cgi > ~/daily.out 2>&1
#	If there are any errors, they will come via separate email from cron
#egrep -y "erro|warn" ~/daily.out | grep -v "\-Werror" | \
#	grep -v "gbWarn.o" | grep -v "disabling jobserver mode"
#make tags-all >/dev/null 2>&1

#	Update htdocs
#cd ~/kent/src/hg/htdocs
#make user >/dev/null 2>&1

#	Update trackDb
#	Errors with context will be reported by cron
#cd ~/kent/src/hg/makeDb/trackDb/
#make update |& grep -i -B20 error
