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