From a83b21ec016e4302fb1e767e338527865beefba3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:21:39 +0100 Subject: Fixing offline deployment a bit --- archinstall.py | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/archinstall.py b/archinstall.py index 268787ec..2a51a35e 100644 --- a/archinstall.py +++ b/archinstall.py @@ -696,29 +696,37 @@ def get_application_instructions(target): return instructions +def get_local_instructions(target): + instructions = oDict() + local_path = './deployments' if os.path.isfile('./archinstall.py') else './archinstall/deployments' # Dangerous assumption + if os.path.isfile(f'{local_path}/{target}.json'): + with open(f'{local_path}/{target}.json', 'r') as fh: + instructions = fh.read() + + print('[N] Found local instructions called: {}'.format(target)) + else: + print('[N] No instructions found called: {}'.format(target)) + return instructions + def get_instructions(target, *positionals, **kwargs): instructions = oDict() - try: - instructions = grab_url_data('{}/{}.json'.format(args['profiles-path'], target)).decode('UTF-8') - print('[N] Found net-deploy instructions called: {}'.format(target)) - except urllib.error.HTTPError: - print('[N] Could not find remote instructions. Trying local instructions under ./deployments') - local_path = './deployments' if os.path.isfile('./archinstall.py') else './archinstall/deployments' # Dangerous assumption - if os.path.isfile(f'{local_path}/{target}.json'): - with open(f'{local_path}/{target}.json', 'r') as fh: - instructions = fh.read() + if get_default_gateway_linux(): + try: + instructions = grab_url_data('{}/{}.json'.format(args['profiles-path'], target)).decode('UTF-8') + print('[N] Found net-deploy instructions called: {}'.format(target)) + except urllib.error.HTTPError: + print('[N] Could not find remote instructions. Trying local instructions under ./deployments') + isntructions = get_local_instructions(target, *positionals) + else: + isntructions = get_local_instructions(target, *positionals) - print('[N] Found local instructions called: {}'.format(target)) - else: - print('[N] No instructions found called: {}'.format(target)) - return instructions - - try: - instructions = json.loads(instructions, object_pairs_hook=oDict) - except: - print('[E] JSON syntax error in {}'.format('{}/{}.json'.format(args['profiles-path'], target))) - traceback.print_exc() - exit(1) + if type(instructions) in (dict, oDict): + try: + instructions = json.loads(instructions, object_pairs_hook=oDict) + except: + print('[E] JSON syntax error in {}'.format('{}/{}.json'.format(args['profiles-path'], target))) + traceback.print_exc() + exit(1) return instructions -- cgit v1.2.3-54-g00ecf