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 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 cd "${BOXDIR}/${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
211 # Try to run startup utilities
217 case "${NIGHTLY_SKIP_STEP}"
222 if [ -d emp4 -a -d emp4/bin -a -d emp4/sbin -a -d emp4/var/empire ]
224 echo "Directory structure is ok"
226 warn "Directory structure is NOT ok"
230 if [ ! -f emp4/etc/empire/econfig ]
232 warn "econfig file is missing"
236 if ! emp4/sbin/pconfig >emp4/etc/empire/econfig
238 warn "pconfig failed to create econfig file"
241 echo "Applying global econfig patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
242 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.econfig
244 [ -r "${i}" ] || continue
245 if "${i}" >>emp4/etc/empire/econfig
249 echo "========== ${i}: NOT OK! ${?} =========="
252 echo "Done (econfig patch All)."
255 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
256 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
258 echo "Applying system specific econfig patches from ${LOCALPATCHDIRECTORY}:"
259 for i in "${LOCALPATCHDIRECTORY}"/*.econfig
261 [ -r "${i}" ] || continue
262 if "${i}" >>emp4/etc/empire/econfig
266 echo "========== ${i}: NOT OK! ${?} =========="
269 echo "Done (econfig patch specific)."
273 cd emp4/bin || err "Could not cd to emp4/bin"
275 echo "Determining type of files in bin directory"
277 echo "Done (file *)."
280 cd ../sbin || err "Could not cd to ../sbin"
282 echo "Determining type of files in sbin directory"
284 echo "Done (file *)."
287 echo "Running files and fairland"
288 echo y | ./files -e ../etc/empire/econfig || warn "Error running files"
289 ./fairland -R 1 -e ../etc/empire/econfig 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
290 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
291 echo "Done (files & fairland)."
303 case "${NIGHTLY_SKIP_STEP}"
308 echo "Removing existing server.log and journal.log"
309 if [ -f "../var/empire/server.log" ]
311 rm "../var/empire/server.log"
313 if [ -f "../var/empire/journal.log" ]
315 rm "../var/empire/journal.log"
317 echo "Starting server with -d in the background"
318 ./emp_server -R 1 -e ../etc/empire/econfig -d 2>/dev/null &
321 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
322 echo "Done (emp_server)."
332 # START GENERATE (2nd part)
334 case "${NIGHTLY_SKIP_STEP}"
339 echo "Running newcap_script through empire"
340 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
342 warn "Could not run newcap_script"
343 echo "Stopping server"
347 echo "Done (newcap_script / empire)."
350 echo "TODO: Replace this with a real test script."
351 echo "Just do some rudimentary testing for now."
354 echo "Prevent updates from happening without our consent."
355 runfeed POGO peter << EOF
358 echo "Done (update stop)."
364 # END GENERATE (2nd part)
370 case "${NIGHTLY_SKIP_STEP}"
375 for PLAYER in 2 3 4 5 6 7 8 9 10
377 echo "explore for player ${PLAYER}"
378 runfeed $PLAYER << EOF >/dev/null 2>&1
386 echo "Done (explore)."
390 # Something more elaborate for player 1
391 echo "explore and more for player 1"
392 runfeed 1 << EOF >/dev/null 2>&1
446 runfeed POGO peter << EOF
459 echo "Check player 1"
469 echo "Check whether the update did anything"
470 runfeed POGO peter << EOF
478 echo "Done (check update)."
481 echo "Continue some updates for player 1"
484 echo "Turn 2 for player 1"
486 runfeed 1 << EOF >/dev/null 2>&1
505 runfeed POGO peter << EOF
518 echo "Turn 3 for player 1"
548 echo "Turn 3 for player 8"
559 runfeed POGO peter << EOF
573 echo "Turn 4 for player 1"
591 echo "Turn 4 for player 8"
599 runfeed POGO peter << EOF
613 echo "Turn 5 for player 1"
623 runfeed POGO peter << EOF
638 echo "Turn 6 for player 1"
674 echo "Turn 6 for player 8"
708 runfeed POGO peter << EOF
723 echo "Turn 7 for player 1"
746 thres c * ?c_dist=768 769
755 echo "Turn 7 for player 8"
760 thres d * ?newdes=g 1
786 runfeed POGO peter << EOF
801 echo "Turn 8 for player 1"
832 echo "Turn 8 for player 8"
845 runfeed POGO peter << EOF
860 echo "Turn 9 for player 1"
877 echo "Turn 9 for player 8"
901 runfeed POGO peter << EOF
916 echo "Turn 10 for player 1"
967 echo "Turn 10 for player 8"
982 runfeed POGO peter << EOF
997 echo "Turn 11 for player 1"
1013 echo "Turn 11 for player 8"
1026 echo "Done (Rudimentary tests)."
1038 case "${NIGHTLY_SKIP_STEP}"
1042 case "${NIGHTLY_SKIP_STEP}"
1047 echo "Stopping server"
1050 cd "${BOXDIR}/${WORKDIR}/emp4/var/empire" || err "Could not cd to ${BOXDIR}/${WORKDIR}/emp4/var/empire"
1051 echo "-- Start Server Log --"
1053 echo "-- End of Server Log --"
1054 echo "-- Start Journal Log --"
1056 echo "-- End of Journal Log --"
1057 echo "Server stopped"
1070 case "${NIGHTLY_SKIP_STEP}"
1075 echo "Cleaning sandbox"
1076 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
1077 case "${NIGHTLY_SKIP_STEP}"
1079 *REMOVE_REPOSITORY*)
1080 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
1083 rm -r "${WORKDIR}" || warn "Directory ${WORKDIR} could not be cleanly removed !"
1084 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
1085 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
1086 echo "Done (cleaning)."
1095 echo "Nightly build finished at `date`"