5 # Skip certain parts of this script by exporting the variable
6 # "NIGHTLY_SKIP_STEP" containing the following possible substrings,
7 # preventing the named behaviour:
9 # REDIRECT - Redirect all output to a logfile
10 # CHECKOUT - Fill the sandbox with a fresh checkout
11 # PATCH - Apply the patches for this system (global + specific)
12 # BUILD - Build everything
13 # GENERATE - Generate a new world
14 # SERVERSTART - Start the server
15 # TESTSCRIPT - Run the testscript
16 # SERVERSTOP - Stop the server if it was started by this script
17 # CLEANUP - Remove the contents of the sandbox
18 # REMOVE_REPOSITORY Removes the git repository when cleaning up
26 echo "Usage: ${PROGNAME} <configfile>" >&2;
45 [ -f "${SCRIPTDIR}/common.sh" ] || { echo "Broken config ?" >&2; exit 1; }
46 . "${SCRIPTDIR}"/common.sh
50 STAMP="`date +%Y%m%d%H%M%S`"
52 [ -n "${EXTRASUFFIX}" ] && WORKDIR="${WORKDIR}.${EXTRASUFFIX}"
53 LOGFILE="${LOGDIR}/${WORKDIR}.${STAMP}"
58 case "${NIGHTLY_SKIP_STEP}"
78 BOXDIR="${SCRIPTDIR}/${BOXDIR}"
82 cd "${BOXDIR}" || err "Could not chdir to ${BOXDIR}"
84 echo "Nightly build starting at `date`"
90 case "${NIGHTLY_SKIP_STEP}"
96 if [ -d "${WORKDIR}" ]
98 [ -d "${WORKDIR}"/empserver/.git ] || err "Invalid sandbox, missing .git directory"
100 echo making directory
101 mkdir "${WORKDIR}" || warn "Could not create ${BOXDIR}/${WORKDIR}"
103 cd "${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
105 echo "Getting source from GIT:"
107 export GITROOT=${GITROOT:= git://git.pond.sub.org/~armbru/empserver}
109 if ! [ -d empserver ]
111 while ! git clone --quiet $GITROOT empserver >/dev/null
113 sleep "`expr 5 + ${RETR}`"
114 RETR="`expr 1 + ${RETR}`"
115 [ "${RETR}" -gt 5 ] && err "git clone Timeout after ${RETR} retres."
117 cd empserver || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver."
119 cd empserver || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver."
120 while ! git pull --quiet $GITROOT master >/dev/null
122 sleep "`expr 5 + ${RETR}`"
123 RETR="`expr 1 + ${RETR}`"
124 [ "${RETR}" -gt 5 ] && err "GIT pull Timeout after ${RETR} retres."
129 echo "Commit `git describe --match 'v*' --always`"
141 cd "${BOXDIR}/${WORKDIR}/empserver" || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver"
142 case "${NIGHTLY_SKIP_STEP}"
147 echo "Applying global patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
148 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.patch
150 [ -r "${i}" ] || continue
151 if git apply "${i}" >/dev/null
155 echo "========== ${i}: NOT OK! ${?} =========="
158 echo "Done (patch All)."
161 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
162 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
164 echo "Applying system specific patches from ${LOCALPATCHDIRECTORY}:"
165 for i in "${LOCALPATCHDIRECTORY}"/*.patch
167 [ -r "${i}" ] || continue
168 if git apply "${i}" >/dev/null
172 echo "========== ${i}: NOT OK! ${?} =========="
175 echo "Done (patch specific)."
178 echo "Apply controlled time patch."
179 for f in `git-ls-files | grep -E '\.[ch](\.in)?$' | xargs grep -l \>`
181 n=`grep -n '^[ ]*#[ ]*include\>' $f | tail -n 1 | sed 's/:.*//'`
185 #include "emptime.h"\
187 #define time(timer) emp_time((timer), __FUNCTION__)' $f >$f.patched
191 git add include/emptime.h src/lib/gen/emptime.c
192 echo "Done applying controlled time patch."
196 ./configure --prefix ${BOXDIR}/${WORKDIR}/emp4 ${CONFIGURE_OPTIONS}
207 case "${NIGHTLY_SKIP_STEP}"
214 echo "Building server"
215 if make -k install >/dev/null
217 warn "make did not return 0"
228 cd "${BOXDIR}/${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
229 # Try to run startup utilities
235 case "${NIGHTLY_SKIP_STEP}"
240 if [ -d emp4 -a -d emp4/bin -a -d emp4/sbin -a -d emp4/var/empire ]
242 echo "Directory structure is ok"
244 warn "Directory structure is NOT ok"
248 if [ ! -f emp4/etc/empire/schedule ]
250 warn "schedule file is missing"
254 if [ ! -f emp4/etc/empire/econfig ]
256 warn "econfig file is missing"
260 if ! emp4/sbin/pconfig >emp4/etc/empire/econfig
262 warn "pconfig failed to create econfig file"
265 echo "Applying global econfig patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
266 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.econfig
268 [ -r "${i}" ] || continue
269 if "${i}" >>emp4/etc/empire/econfig
273 echo "========== ${i}: NOT OK! ${?} =========="
276 echo "Done (econfig patch All)."
279 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
280 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
282 echo "Applying system specific econfig patches from ${LOCALPATCHDIRECTORY}:"
283 for i in "${LOCALPATCHDIRECTORY}"/*.econfig
285 [ -r "${i}" ] || continue
286 if "${i}" >>emp4/etc/empire/econfig
290 echo "========== ${i}: NOT OK! ${?} =========="
293 echo "Done (econfig patch specific)."
297 cd emp4/bin || err "Could not cd to emp4/bin"
299 echo "Determining type of files in bin directory"
301 echo "Done (file *)."
304 cd ../sbin || err "Could not cd to ../sbin"
306 echo "Determining type of files in sbin directory"
308 echo "Done (file *)."
311 echo "Running files and fairland"
312 echo y | ./files -e ../etc/empire/econfig || warn "Error running files"
313 ./fairland -R 1 -e ../etc/empire/econfig 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
314 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
315 echo "Done (files & fairland)."
327 case "${NIGHTLY_SKIP_STEP}"
332 echo "Removing existing server.log and journal.log"
333 if [ -f "../var/empire/server.log" ]
335 rm "../var/empire/server.log"
337 if [ -f "../var/empire/journal.log" ]
339 rm "../var/empire/journal.log"
341 echo "Removing existing schedule"
342 if [ -f "../etc/empire/schedule" ]
344 >../etc/empire/schedule
346 echo "Starting server with -d in the background"
347 ./emp_server -R 1 -e ../etc/empire/econfig -d 2>/dev/null &
350 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
351 echo "Done (emp_server)."
361 # START GENERATE (2nd part)
363 case "${NIGHTLY_SKIP_STEP}"
368 export EMPIRE_PATH=${BOXDIR}/${WORKDIR}/emp4/bin
369 echo "Running newcap_script through empire"
370 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
372 warn "Could not run newcap_script"
373 echo "Stopping server"
377 echo "Done (newcap_script / empire)."
383 # END GENERATE (2nd part)
389 case "${NIGHTLY_SKIP_STEP}"
394 echo "Applying tests from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests"
395 cd ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests
398 [ -d "$i" ] || continue
402 echo "Update Turn $i starting"
405 echo "Update Turn $i completed successfully"
407 echo "Update Turn $i failed"
413 [ -x "$j" ] || continue
414 echo "Player $j Turn $i starting"
417 echo "Player $j Turn $i completed successfully"
419 echo "Player $j Turn $i failed"
436 case "${NIGHTLY_SKIP_STEP}"
440 case "${NIGHTLY_SKIP_STEP}"
445 echo "Stopping server"
448 cd "${BOXDIR}/${WORKDIR}/emp4/var/empire" || err "Could not cd to ${BOXDIR}/${WORKDIR}/emp4/var/empire"
449 echo "-- Start Server Log --"
451 echo "-- End of Server Log --"
452 echo "-- Start Journal Log --"
454 echo "-- End of Journal Log --"
455 echo "Server stopped"
468 case "${NIGHTLY_SKIP_STEP}"
473 echo "Cleaning sandbox"
474 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
475 case "${NIGHTLY_SKIP_STEP}"
478 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
481 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
482 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
485 echo "Done (cleaning)."
492 echo "Nightly build finished at `date`"