Skip to content

Instantly share code, notes, and snippets.

@plietar
Created April 24, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plietar/2483135 to your computer and use it in GitHub Desktop.
Save plietar/2483135 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
# La ou est installé stechec
prefix="/usr/"
# Default values
map="$prefix/share/stechec/prolo2011/maps/map1"
repo=$(pwd)
# Stechec settings
rules="tron"
library="tron_gui"
# Number of programs
count=2
# This is the array of the revisions
revs=(HEAD HEAD)
usage()
{
cat << EOF
usage : $0 [-r repo] [-m map] [rev [rev]]
Runs two revisions of a git repositiory on a local stechec server.
OPTIONS:
-r Path to the git repository, defaults to the curent working directory
-m Path to the map to use, default to "$map"
rev Revisions of the each opponents, defaults to HEAD
EOF
}
while getopts 'hm:r:' OPTION; do
case $OPTION in
h)
usage; exit
;;
m)
map=$(readlink -f $OPTARG)
;;
r)
repo=$(readlink -f $OPTARG)
;;
esac
done
# Shift everything
shift $((OPTIND-1))
pushd $repo
if [ $(git rev-parse --is-inside-work-tree) -eq "false" ]; then
echo "'$repo' is not a git repository"
exit 1
fi
for ((i=0; i<$count; i++)); do
if [ $# -eq 0 ]; then
break
fi
revs[$i]=$(git rev-parse $1)
shift
done
popd
echo ${revs[@]}
declare -a dirs
conf=$(mktemp)
# clone, build and configure the client
for ((i=0; i<$count; i++))
do
dir=$(mktemp -d)
dirs[$i]=$dir
echo $dir
pushd $dir
mkdir clone
pushd $repo
git archive ${revs[$i]} | tar -x -C $dir/clone
popd
cp -R $prefix/share/stechec/files includes
make -C clone
popd
# Create the configuration for this client
cat << EOF >> $conf
[client_$((i+1))]
rules=$rules
path=$dir/clone
library=champion
verbose=1
EOF
done
cat << EOF >> $conf
[client_$(($count+1))]
rules=$rules
path=$prefix/lib
library=$library
verbose=1
spectator=1
[server]
nb_spectator=1
verbose=0
[tron]
map=$map
EOF
run $conf
rm -f $conf
rm -Rf ${dirs[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment