forked from bmrf/standalone_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_tron.ps1
726 lines (616 loc) · 30.8 KB
/
deploy_tron.ps1
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
<#
Purpose: Deploys Tron
Requirements: 1. Expects Master Copy directory to look like this:
\resources
tron.bat
changelog-vX.Y.X-updated-yyyy-mm-dd.txt
Instructions -- YES ACTUALLY READ THEM.txt
2. Expects master copy tron.bat to have accurate "set SCRIPT_DATE=yyyy-mm-dd" and "set SCRIPT_VERSION=x.y.z" strings because these are parsed and used to name everything correctly
3. Expects seed server directory structure to look like this:
\btsync\tron
\tron
- changelog-vX.Y.Z-updated-YYYY-MM-DD.txt
- Instructions -- YES ACTUALLY READ THEM.txt
- Tron.bat
\integrity_verification
- checksums.txt
- checksums.txt.asc
- vocatus-public-key.asc
\syncthing\tron
\tron
- changelog-vX.Y.Z-updated-YYYY-MM-DD.txt
- Instructions -- YES ACTUALLY READ THEM.txt
- Tron.bat
\integrity_verification
- checksums.txt
- checksums.txt.asc
- vocatus-public-key.asc
Author: reddit.com/user/vocatus ( [email protected] ) // PGP key: 0x07d1490f82a211a2
Version: 1.3.4 + Add check for existence of hashdeep prior to running
1.3.3 + Add dev shares to list of Syncthing and BT Sync shares to wipe and upload to
1.3.2 ! Re-order FTP upload commands to remove .UPLOADING from the new binary name PRIOR to uploading new sha256sums.txt
1.3.1 / Move "Are you sure?" dialog to after sanity checks; this way when we see the dialog we know all sanity checks passed
+ Add note at beginning of script telling us which version we're replacing and with what version it's being replaced
* Minor formatting and log cleanup
1.3.0 ! Fix bug where we appended .UPLOADING to the new binary pack too soon
+ Add automatic PGP signature verification of new Tron binary pack
1.2.9 + Add additional checks to look for Tron's stage-specific sub-scripts (Tron modularization project)
1.2.8 * Add automatic PGP signature verification of Tron's internal checksums.txt
1.2.7 * Add ability to handle two seed directories (one for BT Sync and one for SyncThing)
* Add reporting of the date of the version we're replacing
1.2.6 / Disable all use of PortablePGP since we're reverting to using gpg4win
1.2.5 + Add auto-killing of PortablePGP window after checksums.txt signature file appears
1.2.4 ! Fix binary pack hash calculation by removing ".\" prefix on new binary path, which was breaking the update checker in Tron.bat
1.2.3 / Suppress 7-Zip output (redirect to log file)
1.2.2 + Add automatic launching of PortablePGP.exe to signing portion, along with associated $PortablePGP variable
1.2.1 / Update to account for changed Tron sub-folder and new integrity_verification directory
+ Add $OldVersion variable and associated code to display the version we replaced
1.2.0 + Replace built-in Windows FTP client with WinSCP and add associated $WinSCP variable and checks
1.1.0 * Add calculation of SHA256 sum of the binary pack and upload of respective sha256sums.txt to prepare for moving the Tron update checker away from using MD5 sums
1.0.0 . Initial write
Behavior/steps:
1. Deletes content from seed server
2. Calculates sha256 hashes of all files in \tron
3. PGP-signs checksums.txt
4. Creates binary pack
5. PGP-signs the binary pack
6. Background uploads the binary pack to the seed server
7. Fetches sha256sums.txt from repo and updates it with sha256sum of the new binary pack
8. Deletes current version from repo server; uploads .exe pack and sha256sums.txt to repo server; cleans up residual temp files; notifies of completion and advises to restart BT Sync
9. Builds FTP upload script
10. Uploads via FTP
11. Cleans up (deletes temp files used)
#>
#############
# VARIABLES # ---------------------- Set these to match your environment ------------------------ #
#############
# Rules for variables:
# * NO quotes! (bad: "c:\directory\path" )
# * NO trailing slashes on paths! (bad: c:\directory\ )
# * Spaces are okay (okay: c:\my folder\with spaces )
# * Network paths are okay (okay: \\server\share name )
param (
# Logging information
[string]$logpath = "$env:systemdrive\Logs",
[string]$logfile = "tron_deployment_script.log",
# Path to 7z.exe
[string]$SevenZip = "C:\Program Files\7-Zip\7z.exe",
# Path to WinSCP.com
[string]$WinSCP = "R:\applications\WinSCP\WinSCP.com",
# Path to hashdeep.exe
[string]$HashDeep = "$env:SystemRoot\system32\hashdeep.exe", # e.g. "$env:SystemRoot\system32\hashdeep.exe"
# Path to gpg.exe (for signing)
[string]$gpg = "${env:ProgramFiles(x86)}\GNU\GnuPG\pub\gpg.exe", # e.g. "$env:ProgramFiles\gpg4win\bin\gpg.exe"
# Master copy of Tron. Directory path, not tron.bat
[string]$MasterCopy = "r:\utilities\security\cleanup-repair\tron", # e.g. "r:\utilities\security\cleanup-repair\tron"
# Server holding the Tron seed directories
[string]$SeedServer = "\\thebrain", # e.g. "\\thebrain"
# Seeding subdirectories containing \tron and \integrity_verification directories. No leading or trailing slashes
# Release seeds
[string]$SeedFolderBTS = "downloads\seeders\btsync\tron", # e.g. "downloads\seeders\btsync\tron"
[string]$SeedFolderST = "downloads\seeders\syncthing\tron", # e.g. "downloads\seeders\syncthing\tron"
# Dev seeds
[string]$SeedFolderBTS_dev = "downloads\seeders\btsync\tron_dev", # e.g. "downloads\seeders\btsync\tron_dev"
[string]$SeedFolderST_dev = "downloads\seeders\syncthing\tron_dev", # e.g. "downloads\seeders\syncthing\tron_dev"
# Static pack storage location. RELATIVE path from root on the
# local deployment server. Where we stash the compiled .exe
# after uploading to the repo server.
# No leading or trailing slashes
[string]$StaticPackStorageLocation = "downloads\seeders\static_packs", # e.g. "downloads\seeders\static packs"
# Repository server where we'll fetch sha256sums.txt from
[string]$Repo_URL = "http://bmrf.org/repos/tron", # e.g. "http://bmrf.org/repos/tron"
# FTP information for where we'll upload the final sha256sums.txt and "Tron vX.Y.Z (yyyy-mm-dd).exe" file to
[string]$Repo_FTP_Host = "xxxxxxxx", # e.g. "bmrf.org"
[string]$Repo_FTP_Username = "xxx",
[string]$Repo_FTP_Password = "xxx",
[string]$Repo_FTP_DepositPath = "/public_html/repos/tron/", # e.g. "/public_html/repos/tron/"
# PGP key authentication information
[string]$gpgPassphrase = "xxx",
[string]$gpgUsername = "xxx"
)
# ----------------------------- Don't edit anything below this line ----------------------------- #
###################
# PREP AND CHECKS #
###################
$SCRIPT_VERSION = "1.3.4"
$SCRIPT_UPDATED = "2016-02-19"
$CUR_DATE=get-date -f "yyyy-MM-dd"
# Extract version number of current version from the seed server copy of tron.bat and stash it in $OldVersion
# The "split" command/method is similar to variable cutting in batch (e.g. %myVar:~3,0%)
$OldVersion = gc $SeedServer\$SeedFolderBTS\tron\tron.bat -ea SilentlyContinue | Select-String -pattern "set SCRIPT_VERSION"
$OldVersion = "$OldVersion".Split("=")[1]
# Extract release date of current version from th seed server copy of tron.bat and stash it in $OldDate
$OldDate = gc $SeedServer\$SeedFolderBTS\tron\tron.bat -ea SilentlyContinue | Select-String -pattern "set SCRIPT_DATE"
$OldDate = "$OldDate".Split("=")[1]
# Extract version number from master's tron.bat and stash it in $NewVersion, then calculate and store the full .exe name for the new binary we'll be building
# The "split" command/method is similar to variable cutting in batch (e.g. %myVar:~3,0%)
$NewVersion = gc $MasterCopy\tron\Tron.bat -ea SilentlyContinue | Select-String -pattern "set SCRIPT_VERSION"
$NewVersion = "$NewVersion".Split("=")[1]
$NewBinary = "Tron v$NewVersion ($CUR_DATE).exe"
#################
# SANITY CHECKS #
#################
# Local machine: Test for existence of 7-Zip
if (!(test-path -literalpath $SevenZip)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find 7z.exe at:"
""
write-host " $SevenZip"
""
write-host " Edit this script and change the `$SevenZip variable to"
write-host " the correct location."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Local machine: Test for existence of WinSCP.com
if (!(test-path -literalpath $WinSCP)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find WinSCP.com at:"
""
write-host " $WinSCP"
""
write-host " Edit this script and change the `$WinSCP variable to point"
write-host " to the correct location."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Local machine: Test for existence of hashdeep
if (!(test-path -literalpath $HashDeep)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find hashdeep at:"
""
write-host " $HashDeep"
""
write-host " Edit this script and change the `$HashDeep variable to point"
write-host " to the correct location."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of Tron's \resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find Tron's \resources subfolder at:"
""
write-host " $MasterCopy\resources"
""
write-host " Check your paths."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of tron.bat inside the tron subfolder
if (!(test-path -literalpath $MasterCopy\tron\tron.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find tron.bat at:"
""
write-host " $MasterCopy\tron.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of stage_0_prep.bat inside the resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources\stage_0_prep\stage_0_prep.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find stage_0_prep.bat at:"
""
write-host " $MasterCopy\resources\stage_0_prep\stage_0_prep.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of stage_1_tempclean.bat inside the resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources\stage_1_tempclean\stage_1_tempclean.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find stage_1_tempclean.bat at:"
""
write-host " $MasterCopy\resources\stage_1_tempclean\stage_1_tempclean.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of stage_2_de-bloat.bat inside the resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources\stage_2_de-bloat\stage_2_de-bloat.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find stage_2_de-bloat.bat at:"
""
write-host " $MasterCopy\resources\stage_2_de-bloat\stage_2_de-bloat.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of stage_3_disinfect.bat inside the resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources\stage_3_disinfect\stage_3_disinfect.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find stage_3_disinfect.bat at:"
""
write-host " $MasterCopy\resources\stage_3_disinfect\stage_3_disinfect.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of stage_4_repair.bat inside the resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources\stage_4_repair\stage_4_repair.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find stage_4_repair.bat at:"
""
write-host " $MasterCopy\resources\stage_4_repair\stage_4_repair.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of stage_5_patch.bat inside the resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources\stage_5_patch\stage_5_patch.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find stage_5_patch.bat at:"
""
write-host " $MasterCopy\resources\stage_5_patch\stage_5_patch.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of stage_6_optimize.bat inside the resources subfolder
if (!(test-path -literalpath $MasterCopy\tron\resources\stage_6_optimize\stage_6_optimize.bat)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find stage_6_optimize.bat at:"
""
write-host " $MasterCopy\resources\stage_6_optimize\stage_6_optimize.bat"
""
write-host " Check your paths and make sure all the required files"
write-host " exist in the appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of the changelog
if (!(test-path -literalpath $MasterCopy\tron\changelog-v$NewVersion-updated-$CUR_DATE.txt)) {
""
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the changelog at:"
""
write-host " $MasterCopy\changelog-v$NewVersion-updated-$CUR_DATE.txt"
""
write-host " Check your paths and make sure all the required files exist in the"
write-host " appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Master copy: Test for existence of the Instructions file
if (!(test-path $MasterCopy\tron\Instructions*.txt)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the Instructions file at:"
""
write-host " $MasterCopy\Instructions*.txt"
""
write-host " Check your paths and make sure all the required files exist in the"
write-host " appropriate locations."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Seed server: Test for existence of top level Tron folder (BT Sync)
if (!(test-path -literalpath $SeedServer\$SeedFolderBTS)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the Tron BT Sync seed folder at:"
""
write-host " $SeedServer\$SeedFolderBTS"
""
write-host " Check your paths and make sure the deployment server is"
write-host " accessible and that you have write-access to the Tron seed folder."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Seed server: Test for existence of top level Tron folder (SyncThing)
if (!(test-path -literalpath $SeedServer\$SeedFolderST)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the Tron SyncThing seed folder at:"
""
write-host " $SeedServer\$SeedFolderST"
""
write-host " Check your paths and make sure the deployment server is"
write-host " accessible and that you have write-access to the Tron seed folder."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Seed server: Test for existence of \tron\integrity_verification sub-folder (BT Sync)
if (!(test-path -literalpath $SeedServer\$SeedFolderBTS\integrity_verification)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the BT Sync integrity_verification folder at:"
""
write-host " $SeedServer\$SeedFolderBTS\integrity_verification\"
""
write-host " Check your paths and make sure you can reach the deployment server,"
write-host " you have write-access to the Tron seed folder, and that the"
write-host " \integrity_verification sub-folder exists. "
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Seed server: Test for existence of \tron\integrity_verification sub-folder (SyncThing)
if (!(test-path -literalpath $SeedServer\$SeedFolderST\integrity_verification)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the SyncThing integrity_verification folder at:"
""
write-host " $SeedServer\$SeedFolderST\integrity_verification\"
""
write-host " Check your paths and make sure you can reach the deployment server,"
write-host " you have write-access to the Tron seed folder, and that the"
write-host " \integrity_verification sub-folder exists. "
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Seed server: Test for existence of the public key (BT Sync)
if (!(test-path -literalpath $SeedServer\$SeedFolderBTS\integrity_verification\vocatus-public-key.asc)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the public key at:"
""
write-host " $SeedServer\$SeedFolderBTS\integrity_verification\vocatus-public-key.asc"
""
write-host " Check your paths and make sure you can reach the deployment server"
write-host " and that you have write-access to the Tron seed folder."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Seed server: Test for existence of the public key (SyncThing)
if (!(test-path -literalpath $SeedServer\$SeedFolderST\integrity_verification\vocatus-public-key.asc)) {
""
write-host -n " ["; write-host -n "ERROR" -f red; write-host -n "]";
write-host " Couldn't find the public key at:"
""
write-host " $SeedServer\$SeedFolderST\integrity_verification\vocatus-public-key.asc"
""
write-host " Check your paths and make sure you can reach the deployment server"
write-host " and that you have write-access to the Tron seed folder."
""
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
break
}
# Are you sure?
""
write-host " Build passed sanity checks." -f green
""
write-host " About to replace Tron v$OldVersion ($OldDate) with v$NewVersion ($CUR_DATE)"
""
write-host " Are you sure?" -f red
""
Write-Host -n 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
""
clear
###########
# EXECUTE #
###########
# The rest of the script is wrapped in the "main" function. This is just so we can put the logging function at the bottom of the script instead of at the top
function main() {
""
log " Tron deployment script v$SCRIPT_VERSION" blue
""
log " Replacing v$OldVersion ($OldDate) with v$NewVersion ($CUR_DATE)" green
# JOB: Clear target area
log " Clearing Release targets on local seed server..." green
remove-item $SeedServer\$SeedFolderBTS\tron\* -force -recurse -ea SilentlyContinue | out-null
remove-item $SeedServer\$SeedFolderBTS\integrity_verification\*txt* -force -recurse -ea SilentlyContinue | out-null
remove-item $SeedServer\$SeedFolderST\tron\* -force -recurse -ea SilentlyContinue | out-null
remove-item $SeedServer\$SeedFolderST\integrity_verification\*txt* -force -recurse -ea SilentlyContinue | out-null
log " Done" darkgreen
log " Clearing Dev targets on local seed server..." green
remove-item $SeedServer\$SeedFolderBTS_dev\tron\* -force -recurse -ea SilentlyContinue | out-null
remove-item $SeedServer\$SeedFolderBTS_dev\integrity_verification\*txt* -force -recurse -ea SilentlyContinue | out-null
remove-item $SeedServer\$SeedFolderST_dev\tron\* -force -recurse -ea SilentlyContinue | out-null
remove-item $SeedServer\$SeedFolderST_dev\integrity_verification\*txt* -force -recurse -ea SilentlyContinue | out-null
log " Done" darkgreen
# JOB: Calculate hashes of every single file included in the \tron directory
log " Calculating individual hashes of all included files, please wait..." green
pushd $MasterCopy
del $env:temp\checksum* -force -recurse | out-null
& $HashDeep -s -e -c sha256 -l -r .\ | Out-File $env:temp\checksums.txt -encoding ascii
mv $env:temp\checksums.txt $MasterCopy\integrity_verification\checksums.txt -force
log " Done" darkgreen
# JOB: PGP sign the resulting checksums.txt then upload master directory to seed locations
log " PGP signing checksums.txt..." green
""
remove-item $MasterCopy\integrity_verification\checksums.txt.asc -force -recurse -ea SilentlyContinue | out-null
& $gpg --batch --yes --local-user $gpgUsername --passphrase $gpgPassphrase --armor --verbose --detach-sign $MasterCopy\integrity_verification\checksums.txt
while (1 -eq 1) {
if (test-path $MasterCopy\integrity_verification\checksums.txt.asc) {
""
log " Done" darkgreen
break
}
# sleep before looking again
start-sleep -s 2
}
# JOB: Verify PGP signature before FTP upload
log " Verifying PGP signature of checksums.txt..." green
""
& $gpg --batch --yes --verbose --verify $MasterCopy\integrity_verification\checksums.txt.asc $MasterCopy\integrity_verification\checksums.txt
if ($? -eq "True") {
""
log " Done" darkgreen
} else {
log " ! There was a problem verifying the signature!" red
}
# JOB: Upload from master copy to seed server directories
log " Master copy is gold. Copying from master to local seed directories..." green
log " Loading BT Sync Release seed..." green
cp $MasterCopy\* $SeedServer\$SeedFolderBTS\ -recurse -force
log " Done" darkgreen
log " Loading BT Sync Dev seed..." green
cp $MasterCopy\* $SeedServer\$SeedFolderBTS_dev\ -recurse -force
log " Done" darkgreen
log " Loading Syncthing Release seed..." green
cp $MasterCopy\* $SeedServer\$SeedFolderST\ -recurse -force
log " Done" darkgreen
log " Loading Syncthing Dev seed..." green
cp $MasterCopy\* $SeedServer\$SeedFolderST_dev\ -recurse -force
log " Done" darkgreen
log " Done, seed server loaded." darkgreen
# Notify that we're done loading the seed server and are starting deployment to the master repo
log " Updating master repo (remote)..." green
# JOB: Pack Tron to into a binary pack (.exe archive) using 7z and stash it in the TEMP directory.
# Create the file name using the new version number extracted from tron.bat and exclude any
# files with "sync" in the title (these are BT Sync hidden files, we don't need to pack them
log " Building binary pack, please wait..." green
& "$SevenZip" a -sfx "$env:temp\$NewBinary" ".\*" -x!*sync* -x!*ini* >> $LOGPATH\$LOGFILE
log " Done" darkgreen
# JOB: Background upload the binary pack to the static pack folder on the local seed server
log " Starting background upload of $NewBinary to $SeedServer\$StaticPackStorageLocation..." green
start-job -name tron_copy_pack_to_seed_server -scriptblock {cp "$env:temp\$($args[0])" "$($args[1])\$($args[2])" -force} -ArgumentList $NewBinary, $SeedServer, $StaticPackStorageLocation
""
# JOB: Fetch sha256sums.txt from the repo for updating
log " Fetching repo copy of sha256sums.txt to update..." green
Invoke-WebRequest $Repo_URL/sha256sums.txt -outfile $env:temp\sha256sums.txt
log " Done" darkgreen
# JOB: Calculate SHA256 hash of newly-created binary pack and append it to sha256sums.txt
log " Calculating SHA256 hash for binary pack and appending it to sha256sums.txt..." green
pushd $env:temp
# First hash the file
& $HashDeep -s -e -l -c sha256 "Tron v$NewVersion ($CUR_DATE).exe" | Out-File .\sha256sums_TEMP.txt -Encoding utf8
# Strip out the annoying hashdeep header
gc .\sha256sums_TEMP.txt | Where-Object {$_ -notmatch '#'} | where-object {$_ -notmatch '%'} | sc .\sha256sums_TEMP2.txt
# Strip out blank lines and trailing spaces (not needed?)
#(gc .\sha256sums_TEMP2.txt) | ? {$_.trim() -ne "" } | sc .\sha256sums_TEMP2.txt
# Append the result to the sha256sums.txt we pulled from the repo
gc .\sha256sums_TEMP2.txt | out-file .\sha256sums.txt -encoding utf8 -append
# Sleep for a few seconds to make sure the pack has had time to finish uploading to the local seed server static pack location
start-sleep -s 10
# Rename the file to prepare it for uploading
ren "$env:temp\$NewBinary" "$env:temp\$NewBinary.UPLOADING"
popd
log " Done" darkgreen
# JOB: PGP sign sha256sums.txt
log " PGP signing sha256sums.txt..." green
""
remove-item $env:temp\sha256sums.txt.asc -force -recurse -ea SilentlyContinue | out-null
& $gpg --batch --yes --local-user $gpgUsername --passphrase $gpgPassphrase --armor --verbose --detach-sign $env:temp\sha256sums.txt
while (1 -eq 1) {
if (test-path $env:temp\sha256sums.txt.asc) {
""
log " Done" darkgreen
break
}
# sleep before looking again
start-sleep -s 2
}
# JOB: Verify PGP signature of sha256sums.txt
log " Verifying PGP signature of sha256sums.txt..." green
& $gpg --batch --yes --verbose --verify $env:temp\sha256sums.txt.asc $env:temp\sha256sums.txt
if ($? -eq "True") {
log " Done" darkgreen
} else {
log " ! There was a problem verifying the signature!" red
}
# JOB: Build FTP upload script
# Tron exe will have "UPLOADING" appended to its name until upload is complete
log " Building FTP deployment script..." green
"option batch abort" | Out-File $env:temp\deploy_tron_ftp_script.txt -encoding ascii
"option confirm off" | Out-File $env:temp\deploy_tron_ftp_script.txt -append -encoding ascii
"open ftp://$Repo_FTP_Username`:$Repo_FTP_Password@$Repo_FTP_Host" | Out-File $env:temp\deploy_tron_ftp_script.txt -append -encoding ascii
"cd $Repo_FTP_DepositPath" | Out-File $env:temp\deploy_tron_ftp_script.txt -append -encoding ascii
"rm *.exe" | Out-File $env:temp\deploy_tron_ftp_script.txt -append -encoding ascii
"rm sha256sums*" | Out-File $env:temp\deploy_tron_ftp_script.txt -append -encoding ascii
add-content -path $env:temp\deploy_tron_ftp_script.txt -value "put -transfer=binary `"$env:temp\$NewBinary.UPLOADING`""
add-content -path $env:temp\deploy_tron_ftp_script.txt -value "mv `"$NewBinary.UPLOADING`" `"$NewBinary`""
add-content -path $env:temp\deploy_tron_ftp_script.txt -value "put -transfer=binary `"$env:temp\sha256sums.txt`""
add-content -path $env:temp\deploy_tron_ftp_script.txt -value "put -transfer=ascii `"$env:temp\sha256sums.txt.asc`""
#write-output "mv "$NewBinary.UPLOADING" "$NewBinary"" | Out-File $env:temp\deploy_tron_ftp_script.txt -append -encoding ascii
"exit" | Out-File $env:temp\deploy_tron_ftp_script.txt -append -encoding ascii
log " Done" darkgreen
# JOB: Upload binary pack and hash files to FTP repo server
# Get in TEMP directory and call WinSCP to run the script we just created
log " Uploading $NewBinary to $Repo_FTP_Host..." green
""
pushd $env:temp
& $WinSCP /script=.\deploy_tron_ftp_script.txt
popd
Write-Host ""
log " Done" darkgreen
# JOB: Clean up after ourselves
log " Cleaning up..." green
remove-item $env:temp\sha256sums* -force -recurse -ea SilentlyContinue | out-null
remove-item $env:temp\$NewBinary* -force -recurse -ea SilentlyContinue | out-null
remove-item $env:temp\deploy_tron_ftp_script.txt -force -recurse -ea SilentlyContinue | out-null
# Remove our background upload job from the job list
get-job | remove-job
log " Done" darkgreen
############
# Finished #
############
log " Done " green
log " Version deployed: v$NewVersion ($CUR_DATE)"
log " Version replaced: v$OldVersion ($OldDate)"
log " Local seed server: $SeedServer"
log " Local seed directories:"
log " BT Sync (Release): $SeedFolderBTS"
log " BT Sync (Dev): $SeedFolderBTS_dev"
log " SyncThing (Release): $SeedFolderST"
log " SyncThing (Dev): $SeedFolderST_dev"
log " Local static pack storage: $StaticPackStorageLocation"
log " Remote repo host: $Repo_FTP_Host"
log " Remote repo upload path: $Repo_FTP_Host/$Repo_FTP_DepositPath"
log " Log file: $LOGPATH\$LOGFILE"
log " Notify mirror ops and post release to Reddit" blue
write-output "Press any key to continue..."; $HOST.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | out-null
# Close the main() function. End of the script
}
#############
# FUNCTIONS #
#############
function log($message, $color)
{
if ($color -eq $null) {$color = "gray"}
#console
write-host (get-date -f "yyyy-mm-dd hh:mm:ss") -n -f darkgray; write-host "$message" -f $color
#log
#(get-date -f "yyyy-mm-dd hh:mm:ss") +"$message" | out-file -Filepath "$logpath\$logfile" -append
(get-date -f "yyyy-mm-dd hh:mm:ss") +"$message" | out-file -Filepath "C:\logs\tron_deployment_script.log" -append
}
# call the main script
main