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