tools/gdc-psyfork/example-scripts/gdc_auto.sh
changeset 3514 377c7da70d7c
child 3902 691bd6a50850
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/gdc-psyfork/example-scripts/gdc_auto.sh	Sun May 27 11:39:50 2012 -0400
     1.3 @@ -0,0 +1,83 @@
     1.4 +#!/bin/bash
     1.5 +
     1.6 +LOG_DESTINATION=/var/gdclog
     1.7 +
     1.8 +if [ -e gdc.lock ] ; then
     1.9 +	echo -e "GDC already running.\n"
    1.10 +	exit 1
    1.11 +fi
    1.12 +
    1.13 +touch gdc.lock
    1.14 +
    1.15 +games=(
    1.16 +	"CStrike"
    1.17 +)
    1.18 +
    1.19 +email_test=(
    1.20 +	"[email protected]"
    1.21 +)
    1.22 +
    1.23 +email_all=(
    1.24 +	"[email protected]"
    1.25 +)
    1.26 +
    1.27 +email_cstrike=(
    1.28 +	"[email protected]"
    1.29 +	"[email protected]"
    1.30 +	"[email protected]"
    1.31 +)
    1.32 +
    1.33 +for i in "${games[@]}"
    1.34 +do
    1.35 +	lcgame=$(echo $i | tr '[A-Z]' '[a-z]')
    1.36 +
    1.37 +	filename=$(date +%Y-%m-%d-%H%M%S)-${lcgame}.log
    1.38 +	fullfilename=log/$filename
    1.39 +
    1.40 +	./gdc_${lcgame}.sh auto | tee -a ${fullfilename}
    1.41 +
    1.42 +	if [ ${PIPESTATUS[0]} -ne 0 ] ; then
    1.43 +	       	echo -e "No change. Removing useless log.\n"
    1.44 +	        rm $fullfilename
    1.45 +	else
    1.46 +		cp $fullfilename $LOG_DESTINATION
    1.47 +
    1.48 +
    1.49 +		if [ "$1" == "test" ] ; then
    1.50 +			for j in "${email_test[@]}"
    1.51 +			do
    1.52 +				echo -e "Sending test email to ${j}\n"
    1.53 +				mutt -s "$i GDC update" $j < $fullfilename
    1.54 +			done
    1.55 +
    1.56 +			if [ "$2" == "log" ] ; then
    1.57 +				# when testing, don't write to log unless we really want the bot to show it
    1.58 +				echo $(date +%s),${filename},$i >> ~/gdclog
    1.59 +			fi
    1.60 +		else
    1.61 +			# log for pickup by bot
    1.62 +			echo $(date +%s),${filename},$i >> ~/gdclog
    1.63 +
    1.64 +			for j in "${email_all[@]}"
    1.65 +			do
    1.66 +				echo -e "Sending email to ${j}\n"
    1.67 +			        mutt -s "$i GDC update" $j < $fullfilename
    1.68 +			done
    1.69 +
    1.70 +			varname=email_$lcgame
    1.71 +			eval k=\${#$varname[@]}
    1.72 +
    1.73 +			max=($k - 1)
    1.74 +
    1.75 +			for (( m=0; m < $max; m++ ));
    1.76 +			do
    1.77 +				eval k=\${$varname[m]}
    1.78 +				echo -e "Sending email to ${k}\n"
    1.79 +				mutt -s "$i GDC update" $k < $fullfilename
    1.80 +			done
    1.81 +		fi  # just testing
    1.82 +
    1.83 +	fi
    1.84 +done
    1.85 +
    1.86 +rm -f gdc.lock