mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
contrib: Clean up previous_releases.py
* Replace curl single char options with their verbose counterpart * Stricter check for tarballHash
This commit is contained in:
parent
ea595d39f7
commit
facdf530c7
1 changed files with 16 additions and 21 deletions
|
@ -4,7 +4,9 @@
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
#
|
#
|
||||||
# Build previous releases.
|
# Download or build previous releases.
|
||||||
|
# Needs curl and tar to download a release, or the build dependencies when
|
||||||
|
# building a release.
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import contextlib
|
import contextlib
|
||||||
|
@ -52,14 +54,14 @@ def download_binary(tag, args) -> int:
|
||||||
print('Fetching: {sha256SumsUrl}'.format(sha256SumsUrl=sha256SumsUrl))
|
print('Fetching: {sha256SumsUrl}'.format(sha256SumsUrl=sha256SumsUrl))
|
||||||
|
|
||||||
header, status = subprocess.Popen(
|
header, status = subprocess.Popen(
|
||||||
['curl', '-I', tarballUrl], stdout=subprocess.PIPE).communicate()
|
['curl', '--head', tarballUrl], stdout=subprocess.PIPE).communicate()
|
||||||
if re.search("404 Not Found", header.decode("utf-8")):
|
if re.search("404 Not Found", header.decode("utf-8")):
|
||||||
print("Binary tag was not found")
|
print("Binary tag was not found")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
curlCmds = [
|
curlCmds = [
|
||||||
['curl', '-O', tarballUrl],
|
['curl', '--remote-name', tarballUrl],
|
||||||
['curl', "-o", sha256Sums, sha256SumsUrl],
|
['curl', '--output', sha256Sums, sha256SumsUrl],
|
||||||
]
|
]
|
||||||
|
|
||||||
for cmd in curlCmds:
|
for cmd in curlCmds:
|
||||||
|
@ -69,23 +71,17 @@ def download_binary(tag, args) -> int:
|
||||||
|
|
||||||
hasher = hashlib.sha256()
|
hasher = hashlib.sha256()
|
||||||
with open(tarball, "rb") as afile:
|
with open(tarball, "rb") as afile:
|
||||||
buf = afile.read()
|
hasher.update(afile.read())
|
||||||
hasher.update(buf)
|
|
||||||
afile.close()
|
|
||||||
tarballHash = hasher.hexdigest()
|
tarballHash = hasher.hexdigest()
|
||||||
file = open(sha256Sums, 'r', encoding="utf-8")
|
tarballHash = '{} {}\n'.format(tarballHash, tarball)
|
||||||
lst = list(file.readlines())
|
with open(sha256Sums, 'r', encoding="utf-8") as afile:
|
||||||
file.close()
|
shasums = afile.readlines()
|
||||||
lastline = lst[len(lst)-1]
|
|
||||||
|
|
||||||
for line in lst:
|
if tarballHash not in shasums:
|
||||||
if re.search(tarballHash, line):
|
print("Checksum did not match")
|
||||||
print("Checksum matched")
|
Path(tarball).unlink()
|
||||||
break
|
return 1
|
||||||
elif lastline == line:
|
print("Checksum matched")
|
||||||
print("Checksum did not match")
|
|
||||||
Path(tarball).unlink()
|
|
||||||
return 1
|
|
||||||
|
|
||||||
# Bitcoin Core Release Signing Keys v0.11.0+
|
# Bitcoin Core Release Signing Keys v0.11.0+
|
||||||
signingKey = "01EA5486DE18A882D4C2684590C8019E36C2E964"
|
signingKey = "01EA5486DE18A882D4C2684590C8019E36C2E964"
|
||||||
|
@ -182,8 +178,7 @@ def check_host(args) -> int:
|
||||||
|
|
||||||
|
|
||||||
def main(args) -> int:
|
def main(args) -> int:
|
||||||
if not Path(args.target_dir).is_dir():
|
Path(args.target_dir).mkdir(exist_ok=True, parents=True)
|
||||||
Path(args.target_dir).mkdir(exist_ok=True, parents=True)
|
|
||||||
print("Releases directory: {}".format(args.target_dir))
|
print("Releases directory: {}".format(args.target_dir))
|
||||||
ret = check_host(args)
|
ret = check_host(args)
|
||||||
if ret:
|
if ret:
|
||||||
|
|
Loading…
Reference in a new issue