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
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 cd "${BOXDIR}/${WORKDIR}/empserver" || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver"
140 case "${NIGHTLY_SKIP_STEP}"
145 echo "Applying global patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
146 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.patch
148 [ -r "${i}" ] || continue
149 if git apply "${i}" >/dev/null
153 echo "========== ${i}: NOT OK! ${?} =========="
156 echo "Done (patch All)."
159 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
160 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
162 echo "Applying system specific patches from ${LOCALPATCHDIRECTORY}:"
163 for i in "${LOCALPATCHDIRECTORY}"/*.patch
165 [ -r "${i}" ] || continue
166 if git apply "${i}" >/dev/null
170 echo "========== ${i}: NOT OK! ${?} =========="
173 echo "Done (patch specific)."
179 ./configure --prefix ${BOXDIR}/${WORKDIR}/emp4 ${CONFIGURE_OPTIONS}
190 case "${NIGHTLY_SKIP_STEP}"
197 echo "Building server"
198 if make -k install >/dev/null
200 warn "make did not return 0"
211 cd "${BOXDIR}/${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
212 # Try to run startup utilities
218 case "${NIGHTLY_SKIP_STEP}"
223 if [ -d emp4 -a -d emp4/bin -a -d emp4/sbin -a -d emp4/var/empire ]
225 echo "Directory structure is ok"
227 warn "Directory structure is NOT ok"
231 if [ ! -f emp4/etc/empire/schedule ]
233 warn "schedule file is missing"
237 if [ ! -f emp4/etc/empire/econfig ]
239 warn "econfig file is missing"
243 if ! emp4/sbin/pconfig >emp4/etc/empire/econfig
245 warn "pconfig failed to create econfig file"
248 echo "Applying global econfig patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
249 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.econfig
251 [ -r "${i}" ] || continue
252 if "${i}" >>emp4/etc/empire/econfig
256 echo "========== ${i}: NOT OK! ${?} =========="
259 echo "Done (econfig patch All)."
262 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
263 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
265 echo "Applying system specific econfig patches from ${LOCALPATCHDIRECTORY}:"
266 for i in "${LOCALPATCHDIRECTORY}"/*.econfig
268 [ -r "${i}" ] || continue
269 if "${i}" >>emp4/etc/empire/econfig
273 echo "========== ${i}: NOT OK! ${?} =========="
276 echo "Done (econfig patch specific)."
280 cd emp4/bin || err "Could not cd to emp4/bin"
282 echo "Determining type of files in bin directory"
284 echo "Done (file *)."
287 cd ../sbin || err "Could not cd to ../sbin"
289 echo "Determining type of files in sbin directory"
291 echo "Done (file *)."
294 echo "Running files and fairland"
295 echo y | ./files -e ../etc/empire/econfig || warn "Error running files"
296 ./fairland -R 1 -e ../etc/empire/econfig 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
297 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
298 echo "Done (files & fairland)."
310 case "${NIGHTLY_SKIP_STEP}"
315 echo "Removing existing server.log and journal.log"
316 if [ -f "../var/empire/server.log" ]
318 rm "../var/empire/server.log"
320 if [ -f "../var/empire/journal.log" ]
322 rm "../var/empire/journal.log"
324 echo "Removing existing schedule"
325 if [ -f "../etc/empire/schedule" ]
327 >../etc/empire/schedule
329 echo "Starting server with -d in the background"
330 ./emp_server -R 1 -e ../etc/empire/econfig -d 2>/dev/null &
333 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
334 echo "Done (emp_server)."
344 # START GENERATE (2nd part)
346 case "${NIGHTLY_SKIP_STEP}"
351 echo "Running newcap_script through empire"
352 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
354 warn "Could not run newcap_script"
355 echo "Stopping server"
359 echo "Done (newcap_script / empire)."
362 echo "TODO: Replace this with a real test script."
363 echo "Just do some rudimentary testing for now."
369 # END GENERATE (2nd part)
375 case "${NIGHTLY_SKIP_STEP}"
380 for PLAYER in 2 3 4 5 6 7 8 9 10
382 echo "explore for player ${PLAYER}"
383 runfeed $PLAYER << EOF >/dev/null 2>&1
391 echo "Done (explore)."
395 # Something more elaborate for player 1
396 echo "explore and more for player 1"
397 runfeed 1 << EOF >/dev/null 2>&1
451 runfeed POGO peter << EOF
462 echo "Check player 1"
472 echo "Check whether the update did anything"
473 runfeed POGO peter << EOF
481 echo "Done (check update)."
484 echo "Continue some updates for player 1"
487 echo "Turn 2 for player 1"
489 runfeed 1 << EOF >/dev/null 2>&1
508 runfeed POGO peter << EOF
519 echo "Turn 3 for player 1"
549 echo "Turn 3 for player 8"
560 runfeed POGO peter << EOF
572 echo "Turn 4 for player 1"
590 echo "Turn 4 for player 8"
598 runfeed POGO peter << EOF
610 echo "Turn 5 for player 1"
620 runfeed POGO peter << EOF
633 echo "Turn 6 for player 1"
669 echo "Turn 6 for player 8"
703 runfeed POGO peter << EOF
716 echo "Turn 7 for player 1"
739 thres c * ?c_dist=768 769
748 echo "Turn 7 for player 8"
753 thres d * ?newdes=g 1
779 runfeed POGO peter << EOF
792 echo "Turn 8 for player 1"
823 echo "Turn 8 for player 8"
836 runfeed POGO peter << EOF
849 echo "Turn 9 for player 1"
866 echo "Turn 9 for player 8"
890 runfeed POGO peter << EOF
903 echo "Turn 10 for player 1"
954 echo "Turn 10 for player 8"
969 runfeed POGO peter << EOF
982 echo "Turn 11 for player 1"
998 echo "Turn 11 for player 8"
1011 echo "Done (Rudimentary tests)."
1023 case "${NIGHTLY_SKIP_STEP}"
1027 case "${NIGHTLY_SKIP_STEP}"
1032 echo "Stopping server"
1035 cd "${BOXDIR}/${WORKDIR}/emp4/var/empire" || err "Could not cd to ${BOXDIR}/${WORKDIR}/emp4/var/empire"
1036 echo "-- Start Server Log --"
1038 echo "-- End of Server Log --"
1039 echo "-- Start Journal Log --"
1041 echo "-- End of Journal Log --"
1042 echo "Server stopped"
1055 case "${NIGHTLY_SKIP_STEP}"
1060 echo "Cleaning sandbox"
1061 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
1062 case "${NIGHTLY_SKIP_STEP}"
1064 *REMOVE_REPOSITORY*)
1065 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
1068 rm -r "${WORKDIR}" || warn "Directory ${WORKDIR} could not be cleanly removed !"
1069 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
1070 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
1071 echo "Done (cleaning)."
1080 echo "Nightly build finished at `date`"