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__)\
189 #define gettimeofday(tv, tz) emp_gettimeofday((tv), (tz))' $f >$f.patched
193 git add include/emptime.h src/lib/gen/emptime.c
194 echo "Done applying controlled time patch."
198 ./configure --prefix ${BOXDIR}/${WORKDIR}/emp4 ${CONFIGURE_OPTIONS}
209 case "${NIGHTLY_SKIP_STEP}"
216 echo "Building server"
217 if make -k install >/dev/null
219 warn "make did not return 0"
230 cd "${BOXDIR}/${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
231 # Try to run startup utilities
237 case "${NIGHTLY_SKIP_STEP}"
242 if [ -d emp4 -a -d emp4/bin -a -d emp4/sbin -a -d emp4/var/empire ]
244 echo "Directory structure is ok"
246 warn "Directory structure is NOT ok"
250 if [ ! -f emp4/etc/empire/schedule ]
252 warn "schedule file is missing"
256 if [ ! -f emp4/etc/empire/econfig ]
258 warn "econfig file is missing"
262 if ! emp4/sbin/pconfig >emp4/etc/empire/econfig
264 warn "pconfig failed to create econfig file"
267 echo "Applying global econfig patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
268 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.econfig
270 [ -r "${i}" ] || continue
271 if "${i}" >>emp4/etc/empire/econfig
275 echo "========== ${i}: NOT OK! ${?} =========="
278 echo "Done (econfig patch All)."
281 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
282 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
284 echo "Applying system specific econfig patches from ${LOCALPATCHDIRECTORY}:"
285 for i in "${LOCALPATCHDIRECTORY}"/*.econfig
287 [ -r "${i}" ] || continue
288 if "${i}" >>emp4/etc/empire/econfig
292 echo "========== ${i}: NOT OK! ${?} =========="
295 echo "Done (econfig patch specific)."
299 cd emp4/bin || err "Could not cd to emp4/bin"
301 echo "Determining type of files in bin directory"
303 echo "Done (file *)."
306 cd ../sbin || err "Could not cd to ../sbin"
308 echo "Determining type of files in sbin directory"
310 echo "Done (file *)."
313 echo "Running files and fairland"
314 echo y | ./files -e ../etc/empire/econfig || warn "Error running files"
315 ./fairland -R 1 -e ../etc/empire/econfig 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
316 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
317 echo "Done (files & fairland)."
329 case "${NIGHTLY_SKIP_STEP}"
334 echo "Removing existing server.log and journal.log"
335 if [ -f "../var/empire/server.log" ]
337 rm "../var/empire/server.log"
339 if [ -f "../var/empire/journal.log" ]
341 rm "../var/empire/journal.log"
343 echo "Removing existing schedule"
344 if [ -f "../etc/empire/schedule" ]
346 >../etc/empire/schedule
348 echo "Starting server with -d in the background"
349 ./emp_server -R 1 -e ../etc/empire/econfig -d 2>/dev/null &
352 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
353 echo "Done (emp_server)."
363 # START GENERATE (2nd part)
365 case "${NIGHTLY_SKIP_STEP}"
370 export EMPIRE_PATH=${BOXDIR}/${WORKDIR}/emp4/bin
371 echo "Running newcap_script through empire"
372 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
374 warn "Could not run newcap_script"
375 echo "Stopping server"
379 echo "Done (newcap_script / empire)."
385 # END GENERATE (2nd part)
391 case "${NIGHTLY_SKIP_STEP}"
396 echo "Applying tests from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests"
397 cd ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests
400 [ -d "$i" ] || continue
404 echo "Update Turn $i starting"
407 echo "Update Turn $i completed successfully"
409 echo "Update Turn $i failed"
415 [ -x "$j" ] || continue
416 echo "Player $j Turn $i starting"
419 echo "Player $j Turn $i completed successfully"
421 echo "Player $j Turn $i failed"
438 case "${NIGHTLY_SKIP_STEP}"
442 case "${NIGHTLY_SKIP_STEP}"
447 echo "Stopping server"
450 cd "${BOXDIR}/${WORKDIR}/emp4/var/empire" || err "Could not cd to ${BOXDIR}/${WORKDIR}/emp4/var/empire"
451 echo "-- Start Server Log --"
453 echo "-- End of Server Log --"
454 echo "-- Start Journal Log --"
456 echo "-- End of Journal Log --"
457 echo "Server stopped"
470 case "${NIGHTLY_SKIP_STEP}"
475 echo "Cleaning sandbox"
476 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
477 case "${NIGHTLY_SKIP_STEP}"
480 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
483 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
484 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
487 echo "Done (cleaning)."
494 echo "Nightly build finished at `date`"