10 OPENSSL_VERSION_PAT
= re
.compile(r
'^set\(OPENSSL_VERSION "(.*)"\)')
11 OPENSSL_SHA256_PAT
= re
.compile(r
'^set\(OPENSSL_ARCHIVE_SHA256 "(.*)"\)')
12 INFO_PATH
= 'pkgs/tools/system/osquery/info.json'
15 def download_str(url
):
16 return urllib
.request
.urlopen(url
).read().decode('utf-8')
20 latest_url
= f
'https://api.github.com/repos/{OWNER}/{REPO}/releases/latest'
21 return json
.loads(download_str(latest_url
))['tag_name']
25 with
open(INFO_PATH
, 'r') as f
:
30 with
open(INFO_PATH
, 'w') as f
:
31 json
.dump(info
, f
, indent
=4, sort_keys
=True)
35 def sha256_hex_to_sri(hex):
36 return 'sha256-' + base64
.b64encode(bytes
.fromhex(hex)).decode()
39 def openssl_info_from_cmake(cmake
):
42 for line
in cmake
.splitlines():
44 m
= OPENSSL_VERSION_PAT
.match(line
)
48 m
= OPENSSL_SHA256_PAT
.match(line
)
51 if version
is not None and sha256
is not None:
54 if version
is None or sha256
is None:
55 raise Exception('Failed to extract openssl fetch info')
58 'url': f
'https://www.openssl.org/source/openssl-{version}.tar.gz',
59 'hash': sha256_hex_to_sri(sha256
)
63 def openssl_info_for_rev(rev
):
64 url
= f
'https://raw.githubusercontent.com/{OWNER}/{REPO}/{rev}/libraries/cmake/formula/openssl/CMakeLists.txt' # noqa: E501
65 return openssl_info_from_cmake(download_str(url
))
68 force
= len(sys
.argv
) == 2 and sys
.argv
[1] == '--force'
70 latest_tag
= get_latest_tag()
71 print(f
'osquery_latest_tag: {latest_tag}')
74 old_info
= read_info()
75 if latest_tag
== old_info
['osquery']['rev']:
76 print('latest tag matches existing rev. exiting')
79 openssl_fetch_info
= openssl_info_for_rev(latest_tag
)
80 print(f
'openssl_info: {openssl_fetch_info}')
82 prefetch
= json
.loads(subprocess
.check_output([
86 f
'https://github.com/{OWNER}/{REPO}',
90 prefetch_hash
= prefetch
['hash']
96 'hash': prefetch_hash
,
97 'fetchSubmodules': True
100 print(f
'osquery_hash: {prefetch_hash}')
103 'osquery': github_fetch_info
,
104 'openssl': openssl_fetch_info
107 print(f
'osquery_info: {new_info}')