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 $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 $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."
140 cd "${BOXDIR}/${WORKDIR}/empserver" || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver"
141 case "${NIGHTLY_SKIP_STEP}"
146 echo "Applying global patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
147 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.patch
149 [ -r "${i}" ] || continue
150 if git apply "${i}" >/dev/null
154 echo "========== ${i}: NOT OK! ${?} =========="
157 echo "Done (patch All)."
160 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
161 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
163 echo "Applying system specific patches from ${LOCALPATCHDIRECTORY}:"
164 for i in "${LOCALPATCHDIRECTORY}"/*.patch
166 [ -r "${i}" ] || continue
167 if git apply "${i}" >/dev/null
171 echo "========== ${i}: NOT OK! ${?} =========="
174 echo "Done (patch specific)."
178 git-add include/emptime.h src/lib/gen/emptime.c
181 ./configure --prefix ${BOXDIR}/${WORKDIR}/emp4 ${CONFIGURE_OPTIONS}
192 case "${NIGHTLY_SKIP_STEP}"
199 echo "Building server"
200 if make -k install >/dev/null
202 warn "make did not return 0"
213 cd "${BOXDIR}/${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
214 # Try to run startup utilities
220 case "${NIGHTLY_SKIP_STEP}"
225 if [ -d emp4 -a -d emp4/bin -a -d emp4/sbin -a -d emp4/var/empire ]
227 echo "Directory structure is ok"
229 warn "Directory structure is NOT ok"
233 if [ ! -f emp4/etc/empire/schedule ]
235 warn "schedule file is missing"
239 if [ ! -f emp4/etc/empire/econfig ]
241 warn "econfig file is missing"
245 if ! emp4/sbin/pconfig >emp4/etc/empire/econfig
247 warn "pconfig failed to create econfig file"
250 echo "Applying global econfig patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
251 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.econfig
253 [ -r "${i}" ] || continue
254 if "${i}" >>emp4/etc/empire/econfig
258 echo "========== ${i}: NOT OK! ${?} =========="
261 echo "Done (econfig patch All)."
264 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
265 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
267 echo "Applying system specific econfig patches from ${LOCALPATCHDIRECTORY}:"
268 for i in "${LOCALPATCHDIRECTORY}"/*.econfig
270 [ -r "${i}" ] || continue
271 if "${i}" >>emp4/etc/empire/econfig
275 echo "========== ${i}: NOT OK! ${?} =========="
278 echo "Done (econfig patch specific)."
282 cd emp4/bin || err "Could not cd to emp4/bin"
284 echo "Determining type of files in bin directory"
286 echo "Done (file *)."
289 cd ../sbin || err "Could not cd to ../sbin"
291 echo "Determining type of files in sbin directory"
293 echo "Done (file *)."
296 echo "Running files and fairland"
297 echo y | ./files -e ../etc/empire/econfig || warn "Error running files"
298 ./fairland -R 1 -e ../etc/empire/econfig 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
299 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
300 echo "Done (files & fairland)."
312 case "${NIGHTLY_SKIP_STEP}"
317 echo "Removing existing server.log and journal.log"
318 if [ -f "../var/empire/server.log" ]
320 rm "../var/empire/server.log"
322 if [ -f "../var/empire/journal.log" ]
324 rm "../var/empire/journal.log"
326 echo "Removing existing schedule"
327 if [ -f "../etc/empire/schedule" ]
329 >../etc/empire/schedule
331 echo "Starting server with -d in the background"
332 ./emp_server -R 1 -e ../etc/empire/econfig -d 2>/dev/null &
335 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
336 echo "Done (emp_server)."
346 # START GENERATE (2nd part)
348 case "${NIGHTLY_SKIP_STEP}"
353 export EMPIRE_PATH=${BOXDIR}/${WORKDIR}/emp4/bin
354 echo "Running newcap_script through empire"
355 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
357 warn "Could not run newcap_script"
358 echo "Stopping server"
362 echo "Done (newcap_script / empire)."
368 # END GENERATE (2nd part)
374 case "${NIGHTLY_SKIP_STEP}"
379 echo "Applying tests from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests"
380 cd ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests
383 [ -d "$i" ] || continue
387 echo "Update Turn $i starting"
390 echo "Update Turn $i completed successfully"
392 echo "Update Turn $i failed"
398 [ -x "$j" ] || continue
399 echo "Player $j Turn $i starting"
402 echo "Player $j Turn $i completed successfully"
404 echo "Player $j Turn $i failed"
421 case "${NIGHTLY_SKIP_STEP}"
425 case "${NIGHTLY_SKIP_STEP}"
430 echo "Stopping server"
433 cd "${BOXDIR}/${WORKDIR}/emp4/var/empire" || err "Could not cd to ${BOXDIR}/${WORKDIR}/emp4/var/empire"
434 echo "-- Start Server Log --"
436 echo "-- End of Server Log --"
437 echo "-- Start Journal Log --"
439 echo "-- End of Journal Log --"
440 echo "Server stopped"
453 case "${NIGHTLY_SKIP_STEP}"
458 echo "Cleaning sandbox"
459 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
460 case "${NIGHTLY_SKIP_STEP}"
463 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
466 rm -r "${WORKDIR}" || warn "Directory ${WORKDIR} could not be cleanly removed !"
467 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
468 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
469 echo "Done (cleaning)."
478 echo "Nightly build finished at `date`"