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/schedule ]
232 warn "schedule file is missing"
236 if [ ! -f emp4/etc/empire/econfig ]
238 warn "econfig file is missing"
242 if ! emp4/sbin/pconfig >emp4/etc/empire/econfig
244 warn "pconfig failed to create econfig file"
247 echo "Applying global econfig patches from ${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"
248 for i in "${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/All"/*.econfig
250 [ -r "${i}" ] || continue
251 if "${i}" >>emp4/etc/empire/econfig
255 echo "========== ${i}: NOT OK! ${?} =========="
258 echo "Done (econfig patch All)."
261 LOCALPATCHDIRECTORY="${BOXDIR}/${WORKDIR}/empserver/src/scripts/nightly/patches/${INSTANCE}"
262 if [ -n "${LOCALPATCHDIRECTORY}" -a -d "${LOCALPATCHDIRECTORY}/." ]
264 echo "Applying system specific econfig patches from ${LOCALPATCHDIRECTORY}:"
265 for i in "${LOCALPATCHDIRECTORY}"/*.econfig
267 [ -r "${i}" ] || continue
268 if "${i}" >>emp4/etc/empire/econfig
272 echo "========== ${i}: NOT OK! ${?} =========="
275 echo "Done (econfig patch specific)."
279 cd emp4/bin || err "Could not cd to emp4/bin"
281 echo "Determining type of files in bin directory"
283 echo "Done (file *)."
286 cd ../sbin || err "Could not cd to ../sbin"
288 echo "Determining type of files in sbin directory"
290 echo "Done (file *)."
293 echo "Running files and fairland"
294 echo y | ./files -e ../etc/empire/econfig || warn "Error running files"
295 ./fairland -R 1 -e ../etc/empire/econfig 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
296 [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
297 echo "Done (files & fairland)."
309 case "${NIGHTLY_SKIP_STEP}"
314 echo "Removing existing server.log and journal.log"
315 if [ -f "../var/empire/server.log" ]
317 rm "../var/empire/server.log"
319 if [ -f "../var/empire/journal.log" ]
321 rm "../var/empire/journal.log"
323 echo "Removing existing schedule"
324 if [ -f "../etc/empire/schedule" ]
326 >../etc/empire/schedule
328 echo "Starting server with -d in the background"
329 ./emp_server -R 1 -e ../etc/empire/econfig -d 2>/dev/null &
332 kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
333 echo "Done (emp_server)."
343 # START GENERATE (2nd part)
345 case "${NIGHTLY_SKIP_STEP}"
350 echo "Running newcap_script through empire"
351 runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
353 warn "Could not run newcap_script"
354 echo "Stopping server"
358 echo "Done (newcap_script / empire)."
361 echo "TODO: Replace this with a real test script."
362 echo "Just do some rudimentary testing for now."
368 # END GENERATE (2nd part)
374 case "${NIGHTLY_SKIP_STEP}"
379 for PLAYER in 2 3 4 5 6 7 8 9 10
381 echo "explore for player ${PLAYER}"
382 runfeed $PLAYER << EOF >/dev/null 2>&1
390 echo "Done (explore)."
394 # Something more elaborate for player 1
395 echo "explore and more for player 1"
396 runfeed 1 << EOF >/dev/null 2>&1
450 runfeed POGO peter << EOF
461 echo "Check player 1"
471 echo "Check whether the update did anything"
472 runfeed POGO peter << EOF
480 echo "Done (check update)."
483 echo "Continue some updates for player 1"
486 echo "Turn 2 for player 1"
488 runfeed 1 << EOF >/dev/null 2>&1
507 runfeed POGO peter << EOF
518 echo "Turn 3 for player 1"
548 echo "Turn 3 for player 8"
559 runfeed POGO peter << EOF
571 echo "Turn 4 for player 1"
589 echo "Turn 4 for player 8"
597 runfeed POGO peter << EOF
609 echo "Turn 5 for player 1"
619 runfeed POGO peter << EOF
632 echo "Turn 6 for player 1"
668 echo "Turn 6 for player 8"
702 runfeed POGO peter << EOF
715 echo "Turn 7 for player 1"
738 thres c * ?c_dist=768 769
747 echo "Turn 7 for player 8"
752 thres d * ?newdes=g 1
778 runfeed POGO peter << EOF
791 echo "Turn 8 for player 1"
822 echo "Turn 8 for player 8"
835 runfeed POGO peter << EOF
848 echo "Turn 9 for player 1"
865 echo "Turn 9 for player 8"
889 runfeed POGO peter << EOF
902 echo "Turn 10 for player 1"
953 echo "Turn 10 for player 8"
968 runfeed POGO peter << EOF
981 echo "Turn 11 for player 1"
997 echo "Turn 11 for player 8"
1010 echo "Done (Rudimentary tests)."
1022 case "${NIGHTLY_SKIP_STEP}"
1026 case "${NIGHTLY_SKIP_STEP}"
1031 echo "Stopping server"
1034 cd "${BOXDIR}/${WORKDIR}/emp4/var/empire" || err "Could not cd to ${BOXDIR}/${WORKDIR}/emp4/var/empire"
1035 echo "-- Start Server Log --"
1037 echo "-- End of Server Log --"
1038 echo "-- Start Journal Log --"
1040 echo "-- End of Journal Log --"
1041 echo "Server stopped"
1054 case "${NIGHTLY_SKIP_STEP}"
1059 echo "Cleaning sandbox"
1060 cd "${BOXDIR}" || err "Could not cd back to sandbox root !"
1061 case "${NIGHTLY_SKIP_STEP}"
1063 *REMOVE_REPOSITORY*)
1064 rm -rf `find "${WORKDIR}" -maxdepth 1 ! -name .git` || warn "Directory ${WORKDIR} could not be forcibly removed !"
1067 rm -r "${WORKDIR}" || warn "Directory ${WORKDIR} could not be cleanly removed !"
1068 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
1069 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
1070 echo "Done (cleaning)."
1079 echo "Nightly build finished at `date`"