]> git.pond.sub.org Git - empserver/blob - src/scripts/nightly/nightlybuild.sh
Don't try running 'cvs co' more than 5 times, since it might be a local
[empserver] / src / scripts / nightly / nightlybuild.sh
1 #!/bin/sh
2 #
3 # Blame it on marcolz
4 #
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:
8 #
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 #
19
20 # For some reason, solaris sh exits as soon as both stderr and stdout
21 # are redirected to file at the exec, so if we run on solaris, use ksh
22 # for this script.
23 #
24 INTERPRETER="$_"
25
26 case "$INTERPRETER"
27 in
28         */ksh|ksh)
29                 ;;
30         *)
31                 if  [ "`uname`" = "SunOS" ]
32                 then
33                         exec ksh "$0" "$@"
34                 fi
35         ;;
36 esac
37
38 PROGNAME="$0"
39 CVS_RSH=ssh
40 export CVS_RSH
41 TERM="${TERM:-vt100}"
42 export TERM
43
44 usage() {
45         echo "Usage: ${PROGNAME} <configfile>" >&2;
46         exit 1;
47 }
48
49 [ $# -lt 1 ] && usage
50
51 [ -f "$1" ] || usage
52
53 # Source config file
54 case "$1"
55 in
56         */*)
57                 . "$1"
58                 ;;
59         *)
60                 . ./"$1"
61                 ;;
62 esac
63
64 [ -f "${SCRIPTDIR}/common.sh" ] || { echo "Broken config ?" >&2; exit 1; }
65 . "${SCRIPTDIR}"/common.sh
66
67
68 STAMP="`date +%Y%m%d%H%M%S`"
69 WORKDIR="${EMPTARGET}.${ARCH}"
70 [ -n "${EXTRASUFFIX}" ] && WORKDIR="${WORKDIR}.${EXTRASUFFIX}"
71 LOGFILE="${LOGDIR}/${WORKDIR}.${STAMP}"
72
73 #
74 # START REDIRECT
75 #
76 case "${NIGHTLY_SKIP_STEP}"
77 in
78         *REDIRECT*) ;;
79         *)
80
81 # Log everything
82 exec > "${LOGFILE}"
83 exec 2>&1
84
85                 ;;
86 esac
87 #
88 # END REDIRECT
89 #
90
91 case "${BOXDIR}"
92 in
93         /*)
94                 ;;
95         *)
96                 BOXDIR="${SCRIPTDIR}/${BOXDIR}"
97                 ;;
98 esac
99
100 cd "${BOXDIR}" || err "Could not chdir to ${BOXDIR}"
101
102 echo "Nightly build starting at `date`"
103
104
105 #
106 # START CHECKOUT
107 #
108 case "${NIGHTLY_SKIP_STEP}"
109 in
110         *CHECKOUT*) ;;
111         *)
112
113 # Make sandbox
114 mkdir "${WORKDIR}" || warn "Could not create ${BOXDIR}/${WORKDIR}"
115 cd "${WORKDIR}" || err "Could not cd to ${BOXDIR}/${WORKDIR}"
116
117 echo "Getting source from CVS:"
118 # Extract source
119 RETR=0
120 while ! cvs -z3 -d:ext:"${SFLOGIN}"@cvs.sourceforge.net:/cvsroot/empserver co empserver >/dev/null
121 do
122         sleep "`expr 5 + ${RETR}`"
123         RETR="`expr 1 + ${RETR}`"
124         [ "${RETR}" -gt 5 ] && err "CVS Timeout after ${RETR} retres."
125 done
126 echo "Done (CVS)."
127 echo ""
128
129                 ;;
130 esac
131 #
132 # END CHECKOUT
133 #
134
135 #
136 # START PATCH
137 #
138 case "${NIGHTLY_SKIP_STEP}"
139 in
140         *PATCH*) ;;
141         *)
142
143 echo "Applying global patches from patches/All:"
144 for i in "${SCRIPTDIR}/patches/All"/*.patch
145 do
146         [ -r "${i}" ] || continue
147         if patch -Np0 < "${i}" >/dev/null
148         then
149                 echo "${i}: OK"
150         else
151                 echo "========== ${i}: NOT OK! ${?} =========="
152         fi
153 done
154 echo "Done (patch All)."
155 echo ""
156
157 # Run local patches ${LOCALPATCHDIR}/*.patch
158 case "${LOCALPATCHDIR}"
159 in
160         /*)
161                 ;;
162         *)
163                 LOCALPATCHDIR="${SCRIPTDIR}/${LOCALPATCHDIR}"
164                 ;;
165 esac
166
167 if [ -n "${LOCALPATCHDIR}" -a -d "${LOCALPATCHDIR}/." ]
168 then
169         echo "Applying system specific patches from ${LOCALPATCHDIR}:"
170         for i in "${LOCALPATCHDIR}"/*.patch
171         do
172                 [ -r "${i}" ] || continue
173                 if patch -Np0 < "${i}" >/dev/null
174                 then
175                         echo "${i}: OK"
176                 else
177                         echo "========== ${i}: NOT OK! ${?} =========="
178                 fi
179         done
180         echo "Done (patch specific)."
181         echo ""
182 fi
183
184 cd empserver || err "Could not cd to ${BOXDIR}/${WORKDIR}/empserver."
185
186 # Prep build.conf
187 echo "Preparing build.conf"
188 sed     -e "s,^USERNAME = .*$,USERNAME = ${EMPLOGIN}," \
189         -e "s,^HOSTNAME = .*$,HOSTNAME = localhost," \
190         -e "s,^IPADDR = .*$,IPADDR = 127.0.0.1," \
191         -e "s,^PORTNUM = .*$,PORTNUM = ${EMPPORT}," \
192         -e "s,^EMPDIR = .*$,EMPDIR = ${BOXDIR}/${WORKDIR}/emp4," \
193         < build.conf > build.conf.new && \
194         mv build.conf.new build.conf || \
195         err "Could not prep build.conf"
196 echo "Done (build.conf)."
197 echo ""
198
199                 ;;
200 esac
201 #
202 # END PATCH
203 #
204
205 #
206 # START BUILD
207 #
208 case "${NIGHTLY_SKIP_STEP}"
209 in
210         *BUILD*) ;;
211         *)
212
213 # TODO: this should be fixed another way...
214 echo "Generating empty Makedepends."
215 touch src/client/Makedepend src/doconfig/Makedepend src/lib/as/Makedepend src/lib/commands/Makedepend src/lib/common/Makedepend src/lib/empthread/Makedepend src/lib/gen/Makedepend src/lib/global/Makedepend src/lib/lwp/Makedepend src/lib/player/Makedepend src/lib/subs/Makedepend src/lib/update/Makedepend src/server/Makedepend src/util/Makedepend || err "Could tot touch Makedepends"
216 echo "Done (touch)."
217 echo ""
218
219 # Start the build
220 echo "Building server"
221 if make "${EMPTARGET}" >/dev/null
222 then
223         warn "make did not return 0"
224 fi
225 echo "Done (make)."
226 echo ""
227
228                 ;;
229 esac
230 #
231 # END BUILD
232 #
233
234 # Try to run startup utilities
235 for onetime in 1
236 do
237         #
238         # START GENERATE
239         #
240         case "${NIGHTLY_SKIP_STEP}"
241         in
242                 *GENERATE*) ;;
243                 *)
244
245         if [ -d ../emp4 -a -d ../emp4/bin -a -d ../emp4/data ]
246         then
247                 echo "Directory structure is ok"
248         else
249                 warn "Directory structure is NOT ok"
250                 break
251         fi
252
253         cd ../emp4/bin || err "Could not cd to ../emp4/bin"
254
255         echo "Determining type of files in bindir"
256         file *
257         echo "Done (file *)."
258         echo ""
259
260         echo "Running files and fairland"
261         echo y | ./files || warn "Error running files"
262         ./fairland -R 0 10 30 >/dev/null || { warn "Error running fairland" ; break ; }
263         [ -s "newcap_script" ] || { warn "fairland did not produce newcap_script" ; break ; }
264         echo "Done (files & fairland)."
265         echo ""
266
267                         ;;
268         esac
269         #
270         # END GENERATE
271         #
272
273         #
274         # START SERVERSTART
275         #
276         case "${NIGHTLY_SKIP_STEP}"
277         in
278                 *SERVERSTART*) ;;
279                 *)
280
281         echo "Starting server with -d in the background"
282         ./emp_server -d &
283         PID="$!"
284         sleep 1
285         kill -0 "${PID}" || { warn "emp_server not running ?" ; break ; }
286         echo "Done (emp_server)."
287         echo ""
288
289                         ;;
290         esac
291         #
292         # END SERVERSTART
293         #
294
295         #
296         # START GENERATE (2nd part)
297         #
298         case "${NIGHTLY_SKIP_STEP}"
299         in
300                 *GENERATE*) ;;
301                 *)
302
303         echo "Running newcap_script through emp_client"
304         runfeed POGO peter < newcap_script >/dev/null 2>&1 ||
305                 {
306                         warn "Could not run newcap_script"
307                         echo "Stopping server"
308                         trykill $PID
309                         break
310                 }
311         echo "Done (newcap_script / emp_client)."
312         echo ""
313         
314         echo "TODO: Replace this with a real test script."
315         echo "Just do some rudimentary testing for now."
316         echo ""
317
318         echo "Prevent updates from happening without our consent."
319         runfeed POGO peter << EOF
320 disable
321 EOF
322         echo "Done (update stop)."
323         echo ""
324         
325                         ;;
326         esac
327         #
328         # END GENERATE (2nd part)
329         #
330
331         #
332         # START TESTSCRIPT
333         #
334         case "${NIGHTLY_SKIP_STEP}"
335         in
336                 *TESTSCRIPT*) ;;
337                 *)
338
339         for PLAYER in 2 3 4 5 6 7 8 9 10
340         do
341                 echo "explore for player ${PLAYER}"
342                 runfeed $PLAYER << EOF >/dev/null 2>&1
343 break
344 expl c 0,0 1 uh
345 desi 1,-1 +
346 mov c 0,0 205 uh
347 desi 1,-1 g
348 cen *
349 EOF
350                 echo "Done (explore)."
351                 echo ""
352         done
353
354         # Something more elaborate for player 1
355         echo "explore and more for player 1"
356         runfeed 1 << EOF >/dev/null 2>&1
357 break
358 expl c 0,0 1 uh
359 expl c 2,0 1 jh
360 expl c 2,0 1 uh
361 expl c 2,0 1 nh
362 expl c 2,0 1 bh
363 expl c 0,0 1 yh
364 expl c 0,0 1 gh
365 expl c 0,0 1 bh
366 desi * ?ne=- +
367 expl c 2,0 1 bnh
368 expl c 2,0 1 bbh
369 expl c 0,0 1 bgh
370 expl c 0,0 1 ggh
371 expl c 0,0 1 gyh
372 expl c 0,0 1 yyh
373 expl c 2,0 1 yyh
374 expl c 2,0 1 uyh
375 expl c 2,0 1 uuh
376 desi * ?ne=- +
377 expl c 2,0 1 bbnh
378 expl c 2,0 1 uuuh
379 expl c 2,0 1 yyyh
380 expl c 0,0 1 yyyh
381 expl c 0,0 1 yygh
382 expl c 0,0 1 yggh
383 expl c 0,0 1 gggh
384 expl c 0,0 1 ggbh
385 desi * ?ne=- +
386 expl c 0,0 1 ggggh
387 expl c 0,0 1 gggbh
388 expl c 0,0 1 ggbbh
389 desi * ?ne=- +
390 mov u 0,0 75 jh
391 demob 0:2,0 55 y
392 desi 2,0 m
393 mov c 0,0 767 -3,-1
394 desi -3,-1 g
395 mov c 0,0 270 1,-1
396 mov c 2,0 274 1,-1
397 desi 1,-1 m
398 deliver i 2,0 120 u
399 dist 2,-2 2,0
400 thre i 2,-2 1000
401 EOF
402
403         echo "Run an update"
404         runfeed POGO peter << EOF
405 power new
406 cen * ?own#0
407 reso * ?own#0
408 enable
409 force 1
410 disable
411 EOF
412         echo "Done (force)."
413         echo ""
414
415         sleep 10
416         echo "Check player 1"
417         runfeed 1 << EOF
418 real 0 -12:10,-5:5
419 cen *
420 map #
421 read y
422 EOF
423         echo "Done (check)."
424         echo ""
425
426         echo "Check whether the update did anything"
427         runfeed POGO peter << EOF
428 power new
429 cen * ?own#0
430 reso * ?own#0
431 read
432 y
433 EOF
434         echo "Done (check update)."
435         echo ""
436
437         echo "Continue some updates for player 1"
438         echo ""
439
440         echo "Turn 2 for player 1"
441
442         runfeed 1 << EOF >/dev/null 2>&1
443 desi -3,-1 b
444 mov i 1,-1 120 2,-2
445 mov i 1,-1 4 jh
446 mov c -3,-1 435 2,-2
447 deli i 2,0 0 u
448 deli i 1,-1 0 u
449 mov c -3,-1 80 3,-1
450 mov c 1,-1 256 4,-2
451 mov c 2,0 230 3,-1
452 mov c 1,-1 409 3,-1
453 desi 2,-2 k
454 desi 3,-1 j
455 dist # 4,-2
456 thre h 2,-2 1
457 thre l 3,-1 1
458 desi 4,-2 h
459 EOF
460
461         echo "Run an update"
462         runfeed POGO peter << EOF
463 power new
464 cen * ?own#0
465 reso * ?own#0
466 enable
467 force 1
468 disable
469 EOF
470         echo "Done (force)."
471         echo ""
472         sleep 10
473
474         echo "Turn 3 for player 1"
475         runfeed 1 << EOF
476 cen *
477 map #
478 read y
479 build sh 4,-2 frg
480 mov l 3,-1 1 -8,0
481 mov l 4,-2 193 -8,0
482 mov i 1,-1 1 2,-2
483 mov c 2,-2 377 -8,0
484 desi -8,0 l
485 thre l -8,0 150
486 mov c -3,-1 627 -2,0
487 mov c 3,-1 139 -2,0
488 mov c 4,-2 292 uh
489 mov c 2,-2 36 -7,1
490 mov c 3,-1 29 -7,1
491 mov c 2,0 191 -7,1
492 mov c 2,0 125 5,-3
493 mov u 2,0 99 yh
494 deliver o 5,-3 0 b
495 deliver d -2,0 0 y
496 desi -7,1 h
497 desi 5,-3 o
498 desi -2,0 g
499 budg h 1
500 prod *
501 EOF
502
503         echo "Run an update"
504         runfeed POGO peter << EOF
505 power new
506 cen * ?own#0
507 reso * ?own#0
508 enable
509 force 1
510 disable
511 EOF
512         echo "Done (force)."
513         echo ""
514         sleep 10
515
516         echo "Done (player 1)."
517         echo ""
518         echo "TODO: turn 4/5 (tech/assault)..."
519
520         echo "Done (Rudimentary tests)."
521         echo ""
522
523                         ;;
524         esac
525         #
526         # END TESTSCRIPT
527         #
528
529         #
530         # START SERVERSTOP
531         #
532         case "${NIGHTLY_SKIP_STEP}"
533         in
534                 *SERVERSTOP*) ;;
535                 *)
536                         case "${NIGHTLY_SKIP_STEP}"
537                         in
538                                 *SERVERSTART*) ;;
539                                 *)
540
541         echo "Stopping server"
542         trykill "${PID}"
543         echo "Done (kill)."
544         echo ""
545                                         ;;
546                         esac
547                         ;;
548         esac
549         #
550         # END SERVERSTOP
551         #
552 done
553
554 #
555 # START CLEANUP
556 #
557 case "${NIGHTLY_SKIP_STEP}"
558 in
559         *CLEANUP*) ;;
560         *)
561
562 echo "Cleaning sandbox"
563 cd "${BOXDIR}" || err "Could not cd back to sanbox root !"
564 rm -r "${WORKDIR}" || warn "Directory ${WORKDIR} could not be cleanly removed !"
565 rm -rf "${WORKDIR}" || warn "Directory ${WORKDIR} could not be forcibly removed !"
566 [ -d "${WORKDIR}/." ] && warn "Directory ${WORKDIR} still present"
567 echo "Done (cleaning)."
568
569                 ;;
570 esac
571 #
572 # END CLEANUP
573 #
574
575 echo "Nightly build finished at `date`"
576
577 exit 0