-
Notifications
You must be signed in to change notification settings - Fork 279
/
generateDataOnlyDiffBundle.sh
executable file
·702 lines (426 loc) · 13.9 KB
/
generateDataOnlyDiffBundle.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
wipeMaps=0
# two arguments means automation
if [ $# -ne 2 ]
then
echo ""
echo ""
echo "Auto wipe maps as part of process?"
echo ""
echo "Enter WIPE to wipe, or press [ENTER] to skip."
echo ""
echo -n "Wipe maps: "
read wipeMapsWord
if [ "$wipeMapsWord" = "WIPE" ]
then
echo
echo "Auto-wiping maps."
echo
wipeMaps=1
else
echo
echo "NOT Auto-wiping maps."
echo
fi
fi
# note that if we're running on cron-job automation, this might not work
# in genral, we have never done cron-job automation for midnight updates
# (because we are updating servers in batches) so it probably doesn't matter
echo ""
echo "Logging in to steamcmd to make sure credentials are cached"
echo ""
steamcmd +login "jasonrohrergames" +quit
# two arguments means automation
if [ $# -ne 2 ]
then
echo ""
echo ""
lastBuildID=`~/checkout/OneLifeWorking/scripts/getLatestSteamBuildID.sh`
echo "Seeing last Steam build ID of $lastBuildID"
echo ""
echo "Check Steamworks and verify that this is correct."
echo ""
echo -n "Hit [ENTER] when ready: "
read
fi
echo ""
echo "Updating minorGems"
echo ""
cd ~/checkout/minorGems
git pull --tags
echo ""
echo "Building diffBundle tool"
echo ""
cd game/diffBundle
./diffBundleCompile
echo ""
echo "Updating OneLifeData7Latest"
echo ""
cd ~/checkout/OneLifeData7Latest
git pull --tags
lastTaggedDataVersion=`git for-each-ref --sort=-creatordate --format '%(refname:short)' --count=1 refs/tags/OneLife_v* | sed -e 's/OneLife_v//'`
echo ""
echo "Most recent Data git version is: $lastTaggedDataVersion"
echo ""
baseDataVersion=$lastTaggedDataVersion
if [ $# -eq 1 ]
then
echo ""
echo "Overriding base data version using command line argument: $1"
echo ""
baseDataVersion=$1
fi
numNewChangsets=`git log OneLife_v$baseDataVersion..HEAD | grep commit | wc -l`
echo ""
echo "Num git revisions since base data version: $numNewChangsets"
echo ""
if [ $numNewChangsets -lt 1 ]
then
echo "No new revisions to bundle, exiting."
exit 1
fi
echo ""
echo "Updating OneLifeWorking"
echo ""
cd ~/checkout/OneLifeWorking
git pull --tags
echo ""
echo "Building headless cache generation tool"
echo ""
cd gameSource
sh ./makeRegenerateCaches
cd ~/checkout/OneLifeWorking
lastTaggedCodeVersion=`git for-each-ref --sort=-creatordate --format '%(refname:short)' --count=1 refs/tags/OneLife_v* | sed -e 's/OneLife_v//'`
echo ""
echo "Most recent Code git version is: $lastTaggedCodeVersion"
echo ""
lastTaggedVersion=$lastTaggedDataVersion
if [ $lastTaggedCodeVersion -gt $lastTaggedDataVersion ]
then
lastTaggedVersion=$lastTaggedCodeVersion
fi
echo ""
echo "Most recent Data or Code git version is: $lastTaggedVersion"
echo ""
newVersion=$((lastTaggedVersion + 1))
echo ""
echo "Using new version number: $newVersion"
echo ""
# two arguments means automation
if [ $# -ne 2 ]
then
echo ""
echo ""
echo "Most recent code version $lastTaggedCodeVersion"
echo "Most recent data version $lastTaggedDataVersion"
echo "Base data version for diff bundle $baseDataVersion"
echo ""
echo "About to post and tag data with $newVersion"
echo ""
echo -n "Hit [ENTER] when ready: "
read
fi
cd ~/checkout/OneLifeData7Latest
# remove any old, stale directories
# this is what got us into trouble with the v152 update
# (the diffWorking/dataLatest directory created manually to test Steam
# builds was in the way)
rm -rf ~/checkout/diffWorking
mkdir ~/checkout/diffWorking
echo ""
echo "Exporting latest data for diffing"
echo ""
git clone . ~/checkout/diffWorking/dataLatest
rm -rf ~/checkout/diffWorking/dataLatest/.git*
rm ~/checkout/diffWorking/dataLatest/.hg*
rm -rf ~/checkout/diffWorking/dataLatest/soundsRaw
rm -rf ~/checkout/diffWorking/dataLatest/faces
rm -rf ~/checkout/diffWorking/dataLatest/scenes
rm -r ~/checkout/diffWorking/dataLatest/*.sh ~/checkout/diffWorking/dataLatest/working ~/checkout/diffWorking/dataLatest/overlays
echo -n "$newVersion" > ~/checkout/diffWorking/dataLatest/dataVersionNumber.txt
echo ""
echo "Exporting base data for diffing"
echo ""
git checkout -q OneLife_v$baseDataVersion
git clone . ~/checkout/diffWorking/dataLast
rm -rf ~/checkout/diffWorking/dataLast/.git*
rm ~/checkout/diffWorking/dataLast/.hg*
rm -rf ~/checkout/diffWorking/dataLast/soundsRaw
rm -rf ~/checkout/diffWorking/dataLast/faces
rm -rf ~/checkout/diffWorking/dataLast/scenes
rm -r ~/checkout/diffWorking/dataLast/*.sh ~/checkout/diffWorking/dataLast/working ~/checkout/diffWorking/dataLast/overlays
# restore repository to latest, to avoid confusion later
git checkout -q master
echo ""
echo "Copying last bundle's reverb cache to save work"
echo ""
cp -r ~/checkout/reverbCacheLastBundle ~/checkout/diffWorking/dataLast/reverbCache
cp -r ~/checkout/reverbCacheLastBundle ~/checkout/diffWorking/dataLatest/reverbCache
echo ""
echo "Generating caches"
echo ""
cd ~/checkout/diffWorking/dataLast
cp ~/checkout/OneLifeWorking/gameSource/reverbImpulseResponse.aiff .
~/checkout/OneLifeWorking/gameSource/regenerateCaches
rm reverbImpulseResponse.aiff
# don't include bin_cache files in downloads, because they change
# with each update, and are too big
# cache.fcz files are full of compressed text files, so they're much smaller
# and fine to included when they change
rm */bin_*cache.fcz
cd ~/checkout/diffWorking/dataLatest
cp ~/checkout/OneLifeWorking/gameSource/reverbImpulseResponse.aiff .
~/checkout/OneLifeWorking/gameSource/regenerateCaches
rm reverbImpulseResponse.aiff
rm */bin_*cache.fcz
echo ""
echo "Saving latest reverb cache for next time"
echo ""
rm -r ~/checkout/reverbCacheLastBundle
cp -r ~/checkout/diffWorking/dataLatest/reverbCache ~/checkout/reverbCacheLastBundle
echo ""
echo "Generating diff bundle"
echo ""
cd ~/checkout/diffWorking
dbzFileName=${newVersion}_inc_all.dbz
~/checkout/minorGems/game/diffBundle/diffBundle dataLast dataLatest $dbzFileName
cp $dbzFileName ~/diffBundles/
mv $dbzFileName ~/www/updateBundles/
# start with an empty URL list
echo -n "" > ~/diffBundles/${newVersion}_inc_all_urls.txt
# feed file through grep to add newlines at the end of each line
# otherwise, read skips the last line if it doesn't end with newline
# send this new .dbz to all the download servers
while read user server
do
echo ""
echo "Sending $dbzFileName to $server"
scp ~/diffBundles/$dbzFileName $user@$server:downloads/
echo "Adding url for $server to mirror list for this .dbz"
echo "http://$server/downloads/$dbzFileName" >> ~/diffBundles/${newVersion}_inc_all_urls.txt
done < <( grep "" ~/diffBundles/remoteServerList.ini )
# DO NOT add the main server to the mirror list
# farm this out to conserve bandwidth on the main server
# echo -n "http://onehouronelife.com/updateBundles/$dbzFileName" > ~/diffBundles/${newVersion}_inc_all_urls.txt
# don't post new version requirement to reflector just yet
# need to shutdown all servers first
# do NOT remove diffWorking dir just yet
# need it to build steam depot below
echo ""
echo "Updating live server data"
echo ""
cd ~/checkout/OneLifeData7
git pull
rm */cache.fcz
rm */bin_cache.fcz
newTag=OneLife_v$newVersion
echo ""
echo "Updating live server data dataVersionNumber.txt to $newVersion"
echo ""
echo -n "$newVersion" > dataVersionNumber.txt
git add dataVersionNumber.txt
git commit -m "Updatated dataVersionNumber to $newVersion"
echo ""
echo "Tagging live server data with new git tag $newTag"
echo ""
git tag -a $newTag -m "Tag automatically generated by data-only diffBundle script."
echo ""
echo "Pushing tag change to central git server"
echo ""
git push
git push origin $newTag
echo ""
echo "Tagging live server code with OneLife_liveServer"
echo ""
cd ~/checkout/OneLifeWorking
git tag -fa OneLife_liveServer -m "Tag automatically generated by data-only diffBundle script."
echo ""
echo "Pushing tag change to central git server"
echo ""
git push
git push origin -f --tags
echo ""
echo "Tagging live minorGems code with OneLife_liveServer"
echo ""
cd ~/checkout/minorGems
git tag -fa OneLife_liveServer -m "Tag automatically generated by data-only diffBundle script."
echo ""
echo "Pushing tag change to central git server"
echo ""
git push
git push origin -f --tags
echo ""
echo "Re-compiling non-running local server code base as a sanity check"
echo ""
cd ~/checkout/OneLife/server
git pull
./configure 1
make
echo ""
echo "Posting to website Update log."
echo ""
~/checkout/OneLifeWorking/scripts/generateUpdatePosts.sh
echo ""
echo "Generating object report for website."
echo ""
~/checkout/OneLifeWorking/scripts/generateObjectReport.sh
echo ""
echo "Shutting down EVEN remote servers, setting server shutdownMode flags."
echo ""
# feed file through grep to add newlines at the end of each line
# otherwise, read skips the last line if it doesn't end with newline
i=1
while read user server port
do
if [ $((i % 2)) -eq 0 ];
then
echo " Shutting down $server"
ssh -n $user@$server '~/checkout/OneLife/scripts/remoteServerShutdown.sh'
fi
i=$((i + 1))
done < <( grep "" ~/www/reflector/remoteServerList.ini )
echo ""
echo "Triggering EVEN remote server updates."
echo ""
# this will wait for even servers to finish shutting down
i=1
while read user server port
do
if [ $((i % 2)) -eq 0 ];
then
echo " Starting update on $server"
ssh -n $user@$server '~/checkout/OneLife/scripts/remoteServerUpdate.sh'
fi
i=$((i + 1))
done < <( grep "" ~/www/reflector/remoteServerList.ini )
# Decision about when to build depot and make it live is tough
# This depot build process could take a bit of time.
# At this moment, Even servers are down, but ready to go
# and Odd servers are still running the old version and accepting new players
#
# There's no way to do this without the possibility of someone slipping through
# the cracks and connecting to a mis-matched-version server.
#
# Client should catch this and display an error message when it happens.
#
# So, all we can do is minimize the amount of time during which this can happen.
#
# Since the depot build can take a while, we do it here, while Odd servers are
# still running, so everyone can keep playing during the build.
#
# The shutdown operation of Odd servers should be quick, and the startup
# operation of Even servers should be quick as well.
#
# During that moment, some Steam users, who already have the new version,
# will see a SERVERS UPDATING message, because they will connect to outdated
# Odd servers that are still running.
#
# The worst thing that can ever happen to Non-Steam users is that they find
# all servers shutdown (in the moment between Odd shutdown and Even startup).
#
echo ""
echo "Building Steam Depot and making it public/live"
echo ""
oldBuildID=`~/checkout/OneLifeWorking/scripts/getLatestSteamBuildID.sh`
steamcmd +login "jasonrohrergames" +run_app_build -desc OneLifeContent_v$newVersion ~/checkout/OneLifeWorking/build/steam/app_build_content_595690.vdf +quit | tee /tmp/steamBuildLog.txt
newBuildID=`grep BuildID /tmp/steamBuildLog.txt | sed "s/.*(BuildID //" | sed "s/).*//"`
echo ""
echo "Old Steam build ID: $oldBuildID"
echo "New Steam build ID: $newBuildID"
echo ""
if [[ $newBuildID = "" || $newBuildID -le $oldBuildID ]]
then
echo ""
echo "Steam build failed, trying remote build as backup"
echo ""
echo
echo "Remote Steam build starting"
echo
# two arguments means automation
if [ $# -ne 2 ]
then
# run ssh interactively so we can pause at error
ssh build.onehouronelife.com 'cd ~/checkout/OneLifeWorking; git pull; ~/checkout/OneLifeWorking/scripts/generateSteamContentDepot.sh'
else
# automation, don't run ssh interactively
ssh -n build.onehouronelife.com 'cd ~/checkout/OneLifeWorking; git pull; ~/checkout/OneLifeWorking/scripts/generateSteamContentDepot.sh'
fi
echo
echo "Remote Steam build done"
echo
fi
echo ""
echo "Deleting temporary diffWorking directory"
echo ""
rm -r ~/checkout/diffWorking
echo ""
echo "Shutting down ODD remote servers, setting server shutdownMode flags."
echo ""
# feed file through grep to add newlines at the end of each line
# otherwise, read skips the last line if it doesn't end with newline
i=1
while read user server port
do
if [ $((i % 2)) -eq 1 ];
then
echo " Shutting down $server"
ssh -n $user@$server '~/checkout/OneLife/scripts/remoteServerShutdown.sh'
fi
i=$((i + 1))
done < <( grep "" ~/www/reflector/remoteServerList.ini )
echo ""
echo "Setting required version number to $newVersion for all future connections."
echo ""
# now that servers are no longer accepting new connections, tell reflector
# and update server that an upgrade is available
echo -n "$newVersion" > ~/diffBundles/latest.txt
echo -n "<?php \$version=$newVersion; ?>" > ~/www/reflector/requiredVersion.php
echo ""
echo "Triggering EVEN remote server startups."
echo ""
withMapWipeNote=""
serverStartupCommand="~/checkout/OneLife/scripts/remoteServerStartup.sh"
if [ $wipeMaps -eq 1 ]
then
withMapWipeNote=" (with map wipe)"
serverStartupCommand="~/checkout/OneLife/scripts/remoteServerWipeMap.sh"
fi
i=1
while read user server port
do
if [ $((i % 2)) -eq 0 ];
then
echo " Triggering server startup$withMapWipeNote on $server"
ssh -n $user@$server "$serverStartupCommand"
fi
i=$((i + 1))
done < <( grep "" ~/www/reflector/remoteServerList.ini )
echo ""
echo "Triggering ODD remote server updates."
echo ""
# this will wait for ODD servers to finish shutting down
i=1
while read user server port
do
if [ $((i % 2)) -eq 1 ];
then
echo " Starting update on $server"
ssh -n $user@$server '~/checkout/OneLife/scripts/remoteServerUpdate.sh'
fi
i=$((i + 1))
done < <( grep "" ~/www/reflector/remoteServerList.ini )
echo ""
echo "Triggering ODD remote server startups."
echo ""
i=1
while read user server port
do
if [ $((i % 2)) -eq 1 ];
then
echo " Triggering server startup$withMapWipeNote on $server"
ssh -n $user@$server "$serverStartupCommand"
fi
i=$((i + 1))
done < <( grep "" ~/www/reflector/remoteServerList.ini )
echo ""
echo "Entire update process is done."
echo ""