|
1 |
| -import argparse |
2 | 1 | import os
|
3 | 2 | import platform
|
4 | 3 | import shutil
|
|
7 | 6 | import zipfile
|
8 | 7 | import stat
|
9 | 8 | import sys
|
10 |
| -import yaml |
11 |
| - |
12 | 9 |
|
13 | 10 | if platform.system().lower() != 'darwin':
|
14 | 11 | print("Not a macos system, skipping macos signing.")
|
15 | 12 | sys.exit(0)
|
16 | 13 |
|
| 14 | +if len(sys.argv) < 2: |
| 15 | + print("Must provide at least 1 archive to sign.") |
| 16 | + sys.exit(1) |
| 17 | + |
17 | 18 | supported_archs = {
|
18 | 19 | 'arm64': 'arm64',
|
19 | 20 | 'x86_64': 'amd64'
|
|
24 | 25 | print(f"Unsupported platform uname arch: {arch}, must be {supported_archs.keys()}")
|
25 | 26 | sys.exit(1)
|
26 | 27 |
|
27 |
| -expansions_file = "../expansions.yml" |
28 |
| -if not os.path.exists(expansions_file): |
29 |
| - print("Evergreen expansions file not found. Skipping macos_notary.") |
30 |
| - sys.exit(0) |
31 |
| - |
32 |
| -with open(expansions_file) as file: |
33 |
| - expansions = yaml.safe_load(file) |
34 |
| - |
35 |
| -should_sign = expansions.get("sign_macos_archive", None) |
36 |
| -if not should_sign: |
37 |
| - print("sign_macos_archive expansion not found not found or false. Skipping macos_notary.") |
38 |
| - sys.exit(0) |
39 |
| - |
40 | 28 | macnotary_name = f'darwin_{supported_archs[arch]}'
|
41 | 29 |
|
| 30 | +if os.environ['project'] == "mongodb-mongo-master-nightly": |
| 31 | + signing_type = 'notarizeAndSign' |
| 32 | +else: |
| 33 | + signing_type = 'sign' |
| 34 | + |
42 | 35 | macnotary_url = f'https://macos-notary-1628249594.s3.amazonaws.com/releases/client/latest/{macnotary_name}.zip'
|
43 | 36 | print(f'Fetching macnotary tool from: {macnotary_url}')
|
44 | 37 | local_filename, headers = urllib.request.urlretrieve(macnotary_url, f'{macnotary_name}.zip')
|
|
49 | 42 | os.chmod(f'{macnotary_name}/macnotary', st.st_mode | stat.S_IEXEC)
|
50 | 43 |
|
51 | 44 | failed = False
|
52 |
| -parser = argparse.ArgumentParser( |
53 |
| - prog="MacOS Notary", |
54 |
| - description="Sign and/or notarize a tarball containing unsigned binaries.", |
55 |
| -) |
56 |
| -parser.add_argument("--archive-name", "-a", action="store", required=True) |
57 |
| -parser.add_argument("--entitlements-file", "-e", action="store", required=True) |
58 |
| -parser.add_argument("--signing-type", "-s", action="store", required=True) |
59 |
| -args = parser.parse_args() |
60 |
| -archive_name = args.archive_name |
61 |
| -entitlements_file = args.entitlements_file |
62 |
| -signing_type = args.signing_type |
63 |
| - |
64 |
| -archive_base, archive_ext = os.path.splitext(archive_name) |
65 |
| -unsigned_archive = f'{archive_base}_unsigned{archive_ext}' |
66 |
| -shutil.move(archive_name, unsigned_archive) |
67 |
| - |
68 |
| -signing_cmd = [ |
69 |
| - f'./{macnotary_name}/macnotary', |
70 |
| - '-f', f'{unsigned_archive}', |
71 |
| - '-m', f'{signing_type}', |
72 |
| - '-u', 'https://dev.macos-notary.build.10gen.cc/api', |
73 |
| - '-k', 'server', |
74 |
| - '--entitlements', entitlements_file, |
75 |
| - '--verify', |
76 |
| - '-b', 'server.mongodb.com', |
77 |
| - '-i', f'{expansions["task_id"]}', |
78 |
| - '-c', f'{expansions["project"]}', |
79 |
| - '-o', f'{archive_name}' |
80 |
| -] |
81 |
| - |
82 |
| -signing_env = os.environ.copy() |
83 |
| -signing_env['MACOS_NOTARY_SECRET'] = expansions.get("macos_notarization_secret", "") |
84 |
| -print(' '.join(signing_cmd)) |
85 |
| -p = subprocess.Popen(signing_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=signing_env) |
86 |
| - |
87 |
| -print(f"Signing tool completed with exitcode: {p.returncode}") |
88 |
| -for line in iter(p.stdout.readline, b''): |
89 |
| - print(f'macnotary: {line.decode("utf-8").strip()}') |
90 |
| -p.wait() |
91 |
| - |
92 |
| -if p.returncode != 0: |
93 |
| - failed = True |
94 |
| - shutil.move(unsigned_archive, archive_name) |
95 |
| -else: |
96 |
| - os.unlink(unsigned_archive) |
| 45 | +archives = sys.argv[1:] |
| 46 | + |
| 47 | +for archive in archives: |
| 48 | + archive_base, archive_ext = os.path.splitext(archive) |
| 49 | + unsigned_archive = f'{archive_base}_unsigned{archive_ext}' |
| 50 | + shutil.move(archive, unsigned_archive) |
| 51 | + |
| 52 | + signing_cmd = [ |
| 53 | + f'./{macnotary_name}/macnotary', |
| 54 | + '-f', f'{unsigned_archive}', |
| 55 | + '-m', f'{signing_type}', |
| 56 | + '-u', 'https://dev.macos-notary.build.10gen.cc/api', |
| 57 | + '-k', 'server', |
| 58 | + '--entitlements', 'etc/macos_entitlements.xml', |
| 59 | + '--verify', |
| 60 | + '-b', 'server.mongodb.com', |
| 61 | + '-i', f'{os.environ["task_id"]}', |
| 62 | + '-c', f'{os.environ["project"]}', |
| 63 | + '-o', f'{archive}' |
| 64 | + ] |
| 65 | + |
| 66 | + signing_env = os.environ.copy() |
| 67 | + signing_env['MACOS_NOTARY_SECRET'] = os.environ["macos_notarization_secret"] |
| 68 | + print(' '.join(signing_cmd)) |
| 69 | + p = subprocess.Popen(signing_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=signing_env) |
| 70 | + |
| 71 | + print(f"Signing tool completed with exitcode: {p.returncode}") |
| 72 | + for line in iter(p.stdout.readline, b''): |
| 73 | + print(f'macnotary: {line.decode("utf-8").strip()}') |
| 74 | + p.wait() |
| 75 | + |
| 76 | + if p.returncode != 0: |
| 77 | + failed = True |
| 78 | + shutil.move(unsigned_archive, archive) |
| 79 | + else: |
| 80 | + os.unlink(unsigned_archive) |
97 | 81 |
|
98 | 82 | if failed:
|
99 | 83 | exit(1)
|
| 84 | + |
0 commit comments