Added example scripts missing from last commit (NPOTB).

This commit is contained in:
Nicholas Hastings 2012-05-27 11:39:50 -04:00
parent 55b4854cd4
commit fdec003973
5 changed files with 293 additions and 0 deletions

View File

@ -0,0 +1,15 @@
Some example scripts for using this fork of gdc. These are based on some of my live scripts.
Hopefully these are helpful to someone.
gdc_auto.sh
A wrapper script, meant to be cronned. It will run the game's gdc script for games listed in the "games" array. If an update is was detected, it will write the gdc results and a log file as well as email everyone in the "email_all" and "email_<game>" arrays.
gdc_core.sh
This is meant to be called by gdc game scripts, rather than invoked directly. It handles logic common to all games, including invokation of the update check, update download, and gdc.
updatecheck.pl </path/to/steam.inf>
This is used by the gdc_core script, but can also be used standalone. Given the path to a steam.inf file, it will check to see if the game is up to date. Exit codes are as follows (zero and one would ideally be reversed, but I don't want to break existing scripts): 0 - Updated needed. 1 - Up to date. 2 - Failed to parse steam.inf. 3 - Steam Web API gave bad response code (maybe down?)
gdc_<game>.sh, gdc_cstrike.sh [update|auto]
The included example gdc_cstrike.sh is a game script. It can be copied to create others. The game script defines vars specific to the game, such as download name, gamedir name, path to game relative to download dir, etc.. By default, it will not attempt any update; it will just check using the existing files. Ran with "auto", it will update if necessary, and stop if up to date. Ran with "update" will force an update before running.

View File

@ -0,0 +1,83 @@
#!/bin/bash
LOG_DESTINATION=/var/gdclog
if [ -e gdc.lock ] ; then
echo -e "GDC already running.\n"
exit 1
fi
touch gdc.lock
games=(
"CStrike"
)
email_test=(
"self@example.com"
)
email_all=(
"self@example.com"
)
email_cstrike=(
"css-op@example.com"
"css-op2@example.com"
"css-op3@example.com"
)
for i in "${games[@]}"
do
lcgame=$(echo $i | tr '[A-Z]' '[a-z]')
filename=$(date +%Y-%m-%d-%H%M%S)-${lcgame}.log
fullfilename=log/$filename
./gdc_${lcgame}.sh auto | tee -a ${fullfilename}
if [ ${PIPESTATUS[0]} -ne 0 ] ; then
echo -e "No change. Removing useless log.\n"
rm $fullfilename
else
cp $fullfilename $LOG_DESTINATION
if [ "$1" == "test" ] ; then
for j in "${email_test[@]}"
do
echo -e "Sending test email to ${j}\n"
mutt -s "$i GDC update" $j < $fullfilename
done
if [ "$2" == "log" ] ; then
# when testing, don't write to log unless we really want the bot to show it
echo $(date +%s),${filename},$i >> ~/gdclog
fi
else
# log for pickup by bot
echo $(date +%s),${filename},$i >> ~/gdclog
for j in "${email_all[@]}"
do
echo -e "Sending email to ${j}\n"
mutt -s "$i GDC update" $j < $fullfilename
done
varname=email_$lcgame
eval k=\${#$varname[@]}
max=($k - 1)
for (( m=0; m < $max; m++ ));
do
eval k=\${$varname[m]}
echo -e "Sending email to ${k}\n"
mutt -s "$i GDC update" $k < $fullfilename
done
fi # just testing
fi
done
rm -f gdc.lock

View File

@ -0,0 +1,102 @@
#!/bin/bash
# Do not run this file directly. It is meant to be called by other scripts
SM_PATH=/home/gdc/sourcemod-central
ENGINE_BIN=${ENGINE_PATH}/bin/engine
GAME_BIN=${ENGINE_PATH}/${GAME_DIR}/bin/server
STEAMINF=${ENGINE_PATH}/${GAME_DIR}/steam.inf
BIN_EXT=""
if [ $MOD == 1 ] ; then
BIN_EXT="_i486"
fi
echo -e "Checking game ${GAME_DIR}...\n"
if [ $MOD == 0 ] && [ "$1" == "auto" ] ; then
./updatecheck.pl "${STEAMINF}"
if [ $? -ne 0 ] ; then
exit 1
elif [ ! -e ${STEAMINF}.new ] ; then
echo -e "Update (maybe) available but no steam.inf.new written!\n"
fi
fi
export RDTSC_FREQUENCY="disabled"
export LD_LIBRARY_PATH=".:${ENGINE_PATH}/bin:$LD_LIBRARY_PATH"
UPDATE=0
if [ "$1" == "update" ] ; then
UPDATE=1
elif [ "$1" == "auto" ] ; then
UPDATE=1
fi
if [ ${UPDATE} -eq 1 ] ; then
cd ${DD_PATH}
if [ $MOD == 0 ] ; then
#workaround for DD1 "bug" (won't redownload file of same name/size)
rm -f ${STEAMINF}.old
mv ${STEAMINF} ${STEAMINF}.old
fi
for i in 1 2 3 4 5
do
mono DepotDownloader.exe \
-game "${DD_GAME}" \
-dir ${DD_DIR} \
-filelist server.txt \
-all-platforms
if [ $? == 0 ] ; then
break
elif [ $i == 5 ] ; then
echo -e "Update failed five times; giving up ¯\(º_º)/¯\n"
break
fi
echo -e "Update failed. Trying again in 30 seconds...\n"
sleep 30
done
fi
if [ "$1" == "auto" ] ; then
DOWNLOADED_VER=`grep -E "^(Patch)?Version=(([0-9]\.?)+)" ${STEAMINF} | grep -Eo "([0-9]\.?)+" | sed s/[^0-9]//g`
EXPECTED_VER=`cat ${STEAMINF}.new`
if [ ${DOWNLOADED_VER} != ${EXPECTED_VER} ] ; then
echo -e "Download resulted with version ${DOWNLOADED_VER}, but expected ${EXPECTED_VER}. Exiting.\n"
exit 1
fi
fi
# update sourcemod
cd ${SM_PATH}/tools/gdc-psyfork
hg pull -u
echo -e "\n"
for i in "${gamedata_files[@]}"
do
./Release/gdc \
-g ${GAME_DIR} \
-e ${ENGINE_NAME} \
-f ${SM_PATH}/gamedata/$i \
-b ${GAME_BIN}${BIN_EXT}.so \
-x ${ENGINE_BIN}${BIN_EXT}.so \
-w ${GAME_BIN}.dll \
-y ${ENGINE_BIN}.dll
echo -e "------------------------------------------------------\n"
echo -e "\n"
done
if [ ! -e ${STEAMINF} ] ; then
mv ${STEAMINF}.old ${STEAMINF}
fi
if [ "$1" == "auto" ] && [ -e ${STEAMINF}.new ] ; then
rm ${STEAMINF}.new
fi
exit 0

View File

@ -0,0 +1,36 @@
#!/bin/bash
# Path to DepotDownloader
DD_PATH=/home/gdc/dd
# Path for DepotDownloader to download to, relative to DD_PATH
DD_DIR=source
# Game to use for DepotDownloader -game param
DD_GAME="Counter-Strike Source"
# Absolute path to game's engine directory
ENGINE_PATH=${DD_PATH}/${DD_DIR}/css
# Game's directory name
GAME_DIR=cstrike
# SM gamedata engine name
ENGINE_NAME=orangebox_valve
# List of gamedata files to run checks on
gamedata_files=(
"sdktools.games/game.cstrike.txt"
"sdktools.games/engine.ep2valve.txt"
"sm-cstrike.games.txt"
)
# Is game a 2006/2007 "mod" ?
# If so, bin names are adjusted with _i486 suffix and no update check will be done
MOD=0
# DO NOT EDIT BELOW THIS LINE
source ./gdc_core.sh $1 $2 $3 $4
exit $?

View File

@ -0,0 +1,57 @@
#!/usr/bin/perl
use LWP;
use LWP::UserAgent;
use HTTP::Request;
open(STEAMINF, "<", $ARGV[0]);
my $appid = 0;
my $version = "";
while (<STEAMINF>) {
if ($_ =~ /^(?:Patch)?Version\s*=\s*([0-9\.]+)/) {
$version = $1;
} elsif ($_ =~ /appID\s*=\s*([0-9]+)/) {
$appid = $1;
}
}
close STEAMINF;
if ($appid == 0 || $version eq "") {
print "Failed to parse steam.inf\n";
exit 2;
}
my $request = new HTTP::Request(
'GET',
sprintf("http://api.steampowered.com/ISteamApps/UpToDateCheck/v0001/?appid=%d&version=%s&format=xml",
$appid,
$version
)
);
my $ua = new LWP::UserAgent;
my $response = $ua->request($request);
if (!$response->is_success())
{
printf("Bad response code: %d\n", $response->code());
exit 3;
}
$version =~ s/\.//g;
if ($response->content() =~ /<up_to_date>\s*false\s*<\/up_to_date>/) {
printf("We are outdated (v%s)\n", $version);
if ($response->content() =~ /<required_version>\s*([0-9\.]+)\s*<\/required_version>/) {
my $newversion = $1;
printf("Latest is v%s\n", $newversion);
open(my $f, ">", $ARGV[0].".new");
print $f $newversion;
}
exit 0;
} else {
printf("We are up to date (v%s)\n", $version);
exit 1;
}