diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2020-08-26 17:04:52 -0400 |
|---|---|---|
| committer | Jordan Wiens <jordan@psifertex.com> | 2020-08-26 17:04:52 -0400 |
| commit | 50b9d45f068c38812ccf0a081836fe21ac8326c6 (patch) | |
| tree | 5dfb1c27f04c179771c9529ea59925f748a23ac0 /scripts | |
| parent | 25277f0cea0d6d8057acedd795a890fd00ed178e (diff) | |
add download script for headless install bundles for better CI automation
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/download_headless.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/download_headless.py b/scripts/download_headless.py new file mode 100755 index 00000000..a72e9ec8 --- /dev/null +++ b/scripts/download_headless.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +'''Note that this script will only function for headless licenses at this time.''' +import argparse +import json +import os +import requests +import sys +import urllib + +from pathlib import Path + +url='https://master.binary.ninja/headless-download' + +if sys.platform == "darwin": + userpath = Path.home() / 'Library' / 'Application Support' / 'Binary Ninja' +elif sys.platform.startswith("linux"): + userpath = Path.home() / '.binaryninja' +else: + userpath = Path.home() / 'AppData' / 'Roaming' / 'Binary Ninja' + +serial = '' +parser = argparse.ArgumentParser(description='Download a Binary Ninja installer with a headless license') +parser.add_argument("--serial", help="serial number") +parser.add_argument('--dev', dest='dev', default=False, action='store_true') +args = parser.parse_args() + +if args.serial: + serial = args.serial +elif userpath.is_dir(): + if (userpath / 'license.dat').is_file(): + with open(userpath / 'license.dat') as f: + licenses = json.load(f) + for license in licenses: + if 'headless' in license['product']: + serial = license['serial'] + +if serial == '': + parser.print_help() + sys.exit(-1) + +params = {'serial': serial, 'dev': str(args.dev).lower()} + +r = requests.get(url, params) +results = json.loads(r.text) +if results['ok']: + url = results['url'] + r = requests.get(url, allow_redirects=True) + filename = os.path.basename(urllib.parse.urlparse(url).path) + if len(r.content) < 2**13: + print(f'Error downloading from {url}') + else: + open(filename, 'wb').write(r.content) +else: + print('Download failed.') |
