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)."
180 ./configure --prefix ${BOXDIR}/${WORKDIR}/emp4 ${CONFIGURE_OPTIONS}
191 case "${NIGHTLY_SKIP_STEP}"
198 echo "Building server"
199 if make -k install >/dev/null
201 warn "make did not return 0"
212 cd "${BOXDIR}/${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
213 # Try to run startup utilities
219 case "${NIGHTLY_SKIP_STEP}"
224 if [ -d emp4 -a -d emp4/bin -a -d emp4/sbin -a -d emp4/var/empire ]
226 echo "Directory structure is ok"
228 warn "Directory structure is NOT ok"
232 if [ ! -f emp4/etc/empire/schedule ]
234 warn "schedule file is missing"
238 if [ ! -f emp4/etc/empire/econfig ]
240 warn "econfig file is missing"
244 if ! emp4/sbin/pconfig >emp4/etc/empire/econfig
246 warn "pconfig failed to create econfig file"
249 echo "Applying global econfig patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
250 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.econfig
252 [ -r "${i}" ] || continue
253 if "${i}" >>emp4/etc/empire/econfig
257 echo "========== ${i}: NOT OK! ${?} =========="
260 echo "Done (econfig patch All)."
263 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
264 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
266 echo "Applying system specific econfig patches from ${LOCALPATCHDIRECTORY}:"
267 for i in "${LOCALPATCHDIRECTORY}"/*.econfig
269 [ -r "${i}" ] || continue
270 if "${i}" >>emp4/etc/empire/econfig
274 echo "========== ${i}: NOT OK! ${?} =========="
277 echo "Done (econfig patch specific)."
281 cd emp4/bin || err "Could not cd to emp4/bin"
283 echo "Determining type of files in bin directory"
285 echo "Done (file *)."
288 cd ../sbin || err "Could not cd to ../sbin"
290 echo "Determining type of files in sbin directory"
292 echo "Done (file *)."
295 echo "Running files and fairland"
296 echo y | ./files -e ../etc/empire/econfig || warn "Error running files"
297 ./fairland -R 1 -e ../etc/empire/econfig 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
298 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
299 echo "Done (files & fairland)."
311 case "${NIGHTLY_SKIP_STEP}"
316 echo "Removing existing server.log and journal.log"
317 if [ -f "../var/empire/server.log" ]
319 rm "../var/empire/server.log"
321 if [ -f "../var/empire/journal.log" ]
323 rm "../var/empire/journal.log"
325 echo "Removing existing schedule"
326 if [ -f "../etc/empire/schedule" ]
328 >../etc/empire/schedule
330 echo "Starting server with -d in the background"
331 ./emp_server -R 1 -e ../etc/empire/econfig -d 2>/dev/null &
334 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
335 echo "Done (emp_server)."
345 # START GENERATE (2nd part)
347 case "${NIGHTLY_SKIP_STEP}"
352 export EMPIRE_PATH=${BOXDIR}/${WORKDIR}/emp4/bin
353 echo "Running newcap_script through empire"
354 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
356 warn "Could not run newcap_script"
357 echo "Stopping server"
361 echo "Done (newcap_script / empire)."
367 # END GENERATE (2nd part)
373 case "${NIGHTLY_SKIP_STEP}"
378 echo "Applying tests from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests"
379 cd ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/tests
382 [ -d "$i" ] || continue
386 echo "Update Turn $i starting"
389 echo "Update Turn $i completed successfully"
391 echo "Update Turn $i failed"
397 [ -x "$j" ] || continue
398 echo "Player $j Turn $i starting"
401 echo "Player $j Turn $i completed successfully"
403 echo "Player $j Turn $i failed"
420 case "${NIGHTLY_SKIP_STEP}"
424 case "${NIGHTLY_SKIP_STEP}"
429 echo "Stopping server"
432 cd "${BOXDIR}/${WORKDIR}/emp4/var/empire" || err "Could not cd to ${BOXDIR}/${WORKDIR}/emp4/var/empire"
433 echo "-- Start Server Log --"
435 echo "-- End of Server Log --"
436 echo "-- Start Journal Log --"
438 echo "-- End of Journal Log --"
439 echo "Server stopped"
452 case "${NIGHTLY_SKIP_STEP}"
457 echo "Cleaning sandbox"
458 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
459 case "${NIGHTLY_SKIP_STEP}"
462 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
465 rm -r "${WORKDIR}" || warn "Directory ${WORKDIR} could not be cleanly removed !"
466 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
467 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
468 echo "Done (cleaning)."
477 echo "Nightly build finished at `date`"