4
4
# Distributed under the MIT software license, see the accompanying
5
5
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
6
#
7
- # Build previous releases.
7
+ # Download or build previous releases.
8
+ # Needs curl and tar to download a release, or the build dependencies when
9
+ # building a release.
8
10
9
11
import argparse
10
12
import contextlib
@@ -52,14 +54,14 @@ def download_binary(tag, args) -> int:
52
54
print ('Fetching: {sha256SumsUrl}' .format (sha256SumsUrl = sha256SumsUrl ))
53
55
54
56
header , status = subprocess .Popen (
55
- ['curl' , '-I ' , tarballUrl ], stdout = subprocess .PIPE ).communicate ()
57
+ ['curl' , '--head ' , tarballUrl ], stdout = subprocess .PIPE ).communicate ()
56
58
if re .search ("404 Not Found" , header .decode ("utf-8" )):
57
59
print ("Binary tag was not found" )
58
60
return 1
59
61
60
62
curlCmds = [
61
- ['curl' , '-O ' , tarballUrl ],
62
- ['curl' , "-o" , sha256Sums , sha256SumsUrl ],
63
+ ['curl' , '--remote-name ' , tarballUrl ],
64
+ ['curl' , '--output' , sha256Sums , sha256SumsUrl ],
63
65
]
64
66
65
67
for cmd in curlCmds :
@@ -69,23 +71,17 @@ def download_binary(tag, args) -> int:
69
71
70
72
hasher = hashlib .sha256 ()
71
73
with open (tarball , "rb" ) as afile :
72
- buf = afile .read ()
73
- hasher .update (buf )
74
- afile .close ()
74
+ hasher .update (afile .read ())
75
75
tarballHash = hasher .hexdigest ()
76
- file = open (sha256Sums , 'r' , encoding = "utf-8" )
77
- lst = list (file .readlines ())
78
- file .close ()
79
- lastline = lst [len (lst )- 1 ]
80
-
81
- for line in lst :
82
- if re .search (tarballHash , line ):
83
- print ("Checksum matched" )
84
- break
85
- elif lastline == line :
86
- print ("Checksum did not match" )
87
- Path (tarball ).unlink ()
88
- return 1
76
+ tarballHash = '{} {}\n ' .format (tarballHash , tarball )
77
+ with open (sha256Sums , 'r' , encoding = "utf-8" ) as afile :
78
+ shasums = afile .readlines ()
79
+
80
+ if tarballHash not in shasums :
81
+ print ("Checksum did not match" )
82
+ Path (tarball ).unlink ()
83
+ return 1
84
+ print ("Checksum matched" )
89
85
90
86
# Bitcoin Core Release Signing Keys v0.11.0+
91
87
signingKey = "01EA5486DE18A882D4C2684590C8019E36C2E964"
@@ -182,8 +178,7 @@ def check_host(args) -> int:
182
178
183
179
184
180
def main (args ) -> int :
185
- if not Path (args .target_dir ).is_dir ():
186
- Path (args .target_dir ).mkdir (exist_ok = True , parents = True )
181
+ Path (args .target_dir ).mkdir (exist_ok = True , parents = True )
187
182
print ("Releases directory: {}" .format (args .target_dir ))
188
183
ret = check_host (args )
189
184
if ret :
0 commit comments