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 cvs 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
49 STAMP="`date +%Y%m%d%H%M%S`"
51 [ -n "${EXTRASUFFIX}" ] && WORKDIR="${WORKDIR}.${EXTRASUFFIX}"
52 LOGFILE="${LOGDIR}/${WORKDIR}.${STAMP}"
57 case "${NIGHTLY_SKIP_STEP}"
77 BOXDIR="${SCRIPTDIR}/${BOXDIR}"
81 cd "${BOXDIR}" || err "Could not chdir to ${BOXDIR}"
83 echo "Nightly build starting at `date`"
89 case "${NIGHTLY_SKIP_STEP}"
95 if [ -d "${WORKDIR}" ]
97 ! [ -d "${WORKDIR}"/empserver/.git ] || err "Invalid sandbox, missing .git directory"
100 mkdir "${WORKDIR}" || warn "Could not create ${BOXDIR}/${WORKDIR}"
102 cd "${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
104 echo "Getting source from GIT:"
106 export GITROOT=${GITROOT:= git://git.pond.sub.org/~armbru/empserver}
108 if ! [ -d empserver ]
110 while ! git clone $GITROOT empserver >/dev/null
112 sleep "`expr 5 + ${RETR}`"
113 RETR="`expr 1 + ${RETR}`"
114 [ "${RETR}" -gt 5 ] && err "git-clone Timeout after ${RETR} retres."
116 cd empserver || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver."
118 cd empserver || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver."
119 while ! git pull $GITROOT master >/dev/null
121 sleep "`expr 5 + ${RETR}`"
122 RETR="`expr 1 + ${RETR}`"
123 [ "${RETR}" -gt 5 ] && err "GIT pull Timeout after ${RETR} retres."
139 case "${NIGHTLY_SKIP_STEP}"
144 echo "Applying global patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
145 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.patch
147 [ -r "${i}" ] || continue
148 if git apply "${i}" >/dev/null
152 echo "========== ${i}: NOT OK! ${?} =========="
155 echo "Done (patch All)."
158 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
159 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
161 echo "Applying system specific patches from ${LOCALPATCHDIRECTORY}:"
162 for i in "${LOCALPATCHDIRECTORY}"/*.patch
164 [ -r "${i}" ] || continue
165 if git apply "${i}" >/dev/null
169 echo "========== ${i}: NOT OK! ${?} =========="
172 echo "Done (patch specific)."
178 ./configure --prefix ${BOXDIR}/${WORKDIR}/emp4
189 case "${NIGHTLY_SKIP_STEP}"
196 echo "Building server"
197 if make -k install >/dev/null
199 warn "make did not return 0"
210 # Try to run startup utilities
216 case "${NIGHTLY_SKIP_STEP}"
221 if [ -d ../emp4 -a -d ../emp4/bin -a -d ../emp4/sbin -a -d ../emp4/var/empire ]
223 echo "Directory structure is ok"
225 warn "Directory structure is NOT ok"
229 cd ../emp4/bin || err "Could not cd to ../emp4/bin"
231 echo "Determining type of files in bin directory"
233 echo "Done (file *)."
236 cd ../../emp4/sbin || err "Could not cd to ../../emp4/sbin"
238 echo "Determining type of files in sbin directory"
240 echo "Done (file *)."
243 echo "Running files and fairland"
244 echo y | ./files || warn "Error running files"
245 ./fairland -R 1 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
246 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
247 echo "Done (files & fairland)."
259 case "${NIGHTLY_SKIP_STEP}"
264 echo "Starting server with -d in the background"
265 ./emp_server -R 1 -d &
268 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
269 echo "Done (emp_server)."
279 # START GENERATE (2nd part)
281 case "${NIGHTLY_SKIP_STEP}"
286 echo "Running newcap_script through empire"
287 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
289 warn "Could not run newcap_script"
290 echo "Stopping server"
294 echo "Done (newcap_script / empire)."
297 echo "TODO: Replace this with a real test script."
298 echo "Just do some rudimentary testing for now."
301 echo "Prevent updates from happening without our consent."
302 runfeed POGO peter << EOF
305 echo "Done (update stop)."
311 # END GENERATE (2nd part)
317 case "${NIGHTLY_SKIP_STEP}"
322 for PLAYER in 2 3 4 5 6 7 8 9 10
324 echo "explore for player ${PLAYER}"
325 runfeed $PLAYER << EOF >/dev/null 2>&1
333 echo "Done (explore)."
337 # Something more elaborate for player 1
338 echo "explore and more for player 1"
339 runfeed 1 << EOF >/dev/null 2>&1
389 runfeed POGO peter << EOF
401 echo "Check player 1"
411 echo "Check whether the update did anything"
412 runfeed POGO peter << EOF
419 echo "Done (check update)."
422 echo "Continue some updates for player 1"
425 echo "Turn 2 for player 1"
427 runfeed 1 << EOF >/dev/null 2>&1
447 runfeed POGO peter << EOF
459 echo "Turn 3 for player 1"
483 runfeed POGO peter << EOF
495 echo "Done (player 1)."
497 echo "TODO: turn 4/5 (tech/assault)..."
499 echo "Done (Rudimentary tests)."
511 case "${NIGHTLY_SKIP_STEP}"
515 case "${NIGHTLY_SKIP_STEP}"
520 echo "Stopping server"
536 case "${NIGHTLY_SKIP_STEP}"
541 echo "Cleaning sandbox"
542 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
543 case "${NIGHTLY_SKIP_STEP}"
546 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
549 rm -r "${WORKDIR}" || warn "Directory ${WORKDIR} could not be cleanly removed !"
550 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
551 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
552 echo "Done (cleaning)."
561 echo "Nightly build finished at `date`"