From e9484e4adb24f846cd930e12a4acc4e4b0f58df5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 13:37:58 +0100 Subject: Update 00:11:22:33:44:55.json --- deployments/00:11:22:33:44:55.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deployments/00:11:22:33:44:55.json b/deployments/00:11:22:33:44:55.json index e96fc01b..909b4256 100644 --- a/deployments/00:11:22:33:44:55.json +++ b/deployments/00:11:22:33:44:55.json @@ -6,14 +6,14 @@ "post" : "don't reboot" }, "post" : { + "Setup user" : { + "useradd -m -G wheel -s /bin/bash anton" : null, + "sh -c \"echo {user}:{password} | chpasswd\"" : {"pass-args" : true} + }, "Setup a basic virtual environment": { "mkdir -p /home/{user}/virts" : {"pass-args" : true}, "qemu-img create -f qcow2 /home/{user}/virts/test_deploy.qcow2 4G" : {"pass-args" : true}, "chown -R {user}.{user} /home/{user}/virts" : {"pass-args" : true} - }, - "Setup user" : { - "useradd -m -G wheel -s /bin/bash anton" : null, - "sh -c \"echo {user}:{password} | chpasswd\"" : {"pass-args" : true} } } } -- cgit v1.2.3-54-g00ecf From 30752a49c6b7a394508aee381fcc293bad584aae Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:04:36 +0000 Subject: Added refreshing of partitions into a function --- archinstall.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index df63a08f..6b26059c 100644 --- a/archinstall.py +++ b/archinstall.py @@ -778,6 +778,9 @@ def cache_diskpw_on_disk(): with open(args['pwfile'], 'w') as pw: pw.write(args['password']) +def refresh_partition_list(drive): + args['paritions'] = get_partitions(drive) + if __name__ == '__main__': update_git() # Breaks and restarts the script if an update was found. update_drive_list() @@ -836,7 +839,7 @@ if __name__ == '__main__': close_disks() format_disk(args['drive'], start=args['start'], end=args['size']) - args['paritions'] = get_partitions(args['drive']) + refresh_partition_list(args['drive']) print(f'Partitions: (Boot: {list(args["paritions"].keys())[0]})') if len(args['paritions']) <= 0: -- cgit v1.2.3-54-g00ecf From da36b4f4e108369c91d8eb8ec1a7d26468c20010 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:09:18 +0000 Subject: Started adding failure responses on commands for error checks. --- archinstall.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/archinstall.py b/archinstall.py index 6b26059c..d9d5556f 100644 --- a/archinstall.py +++ b/archinstall.py @@ -593,16 +593,25 @@ def format_disk(drive=None, start='512MiB', end='100%', emulate=False, *args, ** print(f'[N] Setting up {drive}.') # dd if=/dev/random of=args['drive'] bs=4096 status=progress # https://github.com/dcantrell/pyparted would be nice, but isn't officially in the repo's #SadPanda - o = b''.join(sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate)) - o = b''.join(sys_command(f'/usr/bin/parted -s {drive} mkpart primary FAT32 1MiB {start}', emulate=emulate)) - o = b''.join(sys_command(f'/usr/bin/parted -s {drive} name 1 "EFI"', emulate=emulate)) - o = b''.join(sys_command(f'/usr/bin/parted -s {drive} set 1 esp on', emulate=emulate)) - o = b''.join(sys_command(f'/usr/bin/parted -s {drive} set 1 boot on', emulate=emulate)) - o = b''.join(sys_command(f'/usr/bin/parted -s {drive} mkpart primary {start} {end}', emulate=emulate)) + if sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate).exit_code != 0: + return None + if sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate).exit_code != 0: + return None + if sys_command(f'/usr/bin/parted -s {drive} mkpart primary FAT32 1MiB {start}', emulate=emulate).exit_code != 0: + return None + if sys_command(f'/usr/bin/parted -s {drive} name 1 "EFI"', emulate=emulate).exit_code != 0: + return None + if sys_command(f'/usr/bin/parted -s {drive} set 1 esp on', emulate=emulate).exit_code != 0: + return None + if sys_command(f'/usr/bin/parted -s {drive} set 1 boot on', emulate=emulate).exit_code != 0: + return None + if sys_command(f'/usr/bin/parted -s {drive} mkpart primary {start} {end}', emulate=emulate).exit_code != 0: + return None # TODO: grab paritions after each parted/partition step instead of guessing which partiton is which later on. # Create one, grab partitions - dub that to "boot" or something. do the next partition, grab that and dub it "system".. or something.. # This "assumption" has bit me in the ass so many times now I've stoped counting.. Jerker is right.. Don't do it like this :P + def multisplit(s, splitters): s = [s,] for key in splitters: -- cgit v1.2.3-54-g00ecf From c2a2e1e5d07e4c2582c3063a57cd52e46a61edd7 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:09:57 +0000 Subject: Added success return on format of disks --- archinstall.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archinstall.py b/archinstall.py index d9d5556f..bddf8de4 100644 --- a/archinstall.py +++ b/archinstall.py @@ -607,10 +607,12 @@ def format_disk(drive=None, start='512MiB', end='100%', emulate=False, *args, ** return None if sys_command(f'/usr/bin/parted -s {drive} mkpart primary {start} {end}', emulate=emulate).exit_code != 0: return None + # TODO: grab paritions after each parted/partition step instead of guessing which partiton is which later on. # Create one, grab partitions - dub that to "boot" or something. do the next partition, grab that and dub it "system".. or something.. # This "assumption" has bit me in the ass so many times now I've stoped counting.. Jerker is right.. Don't do it like this :P + return True def multisplit(s, splitters): s = [s,] -- cgit v1.2.3-54-g00ecf From 1ae1c764ba194279c19428f64c50b9a8af0980aa Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:10:38 +0000 Subject: Added args/kwargs to function --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index bddf8de4..61a51e36 100644 --- a/archinstall.py +++ b/archinstall.py @@ -789,7 +789,7 @@ def cache_diskpw_on_disk(): with open(args['pwfile'], 'w') as pw: pw.write(args['password']) -def refresh_partition_list(drive): +def refresh_partition_list(drive, *args, **kwargs): args['paritions'] = get_partitions(drive) if __name__ == '__main__': -- cgit v1.2.3-54-g00ecf From 8c03f60765c1a9490d40b50181f599115ec7b70e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:13:20 +0000 Subject: Stupid of me to call the sys.argv for args. Now I have to rename all *args expansions to *positionals or something --- archinstall.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index 61a51e36..c03fd78e 100644 --- a/archinstall.py +++ b/archinstall.py @@ -156,7 +156,7 @@ signal.signal(signal.SIGINT, sig_handler) def gen_uid(entropy_length=256): return sha512(os.urandom(entropy_length)).hexdigest() -def get_default_gateway_linux(*args, **kwargs): +def get_default_gateway_linux(*positionals, **kwargs): """Read the default gateway directly from /proc.""" with open("/proc/net/route") as fh: for line in fh: @@ -556,7 +556,7 @@ def merge_in_includes(instructions, *positionals, **kwargs): return instructions -def update_drive_list(*args, **kwargs): +def update_drive_list(*positionals, **kwargs): # https://github.com/karelzak/util-linux/blob/f920f73d83f8fd52e7a14ec0385f61fab448b491/disk-utils/fdisk-list.c#L52 for path in glob('/sys/block/*/device'): name = re.sub('.*/(.*?)/device', '\g<1>', path) @@ -753,9 +753,9 @@ def setup_args_defaults(args, interactive=True): args['drive'] = drive return args -def load_automatic_instructions(*args, **kwargs): +def load_automatic_instructions(*positionals, **kwargs): instructions = oDict() - if get_default_gateway_linux(*args, **kwargs): + if get_default_gateway_linux(*positionals, **kwargs): locmac = get_local_MACs() if not len(locmac): print('[N] No network interfaces - No net deploy.') @@ -789,7 +789,7 @@ def cache_diskpw_on_disk(): with open(args['pwfile'], 'w') as pw: pw.write(args['password']) -def refresh_partition_list(drive, *args, **kwargs): +def refresh_partition_list(drive, *positionals, **kwargs): args['paritions'] = get_partitions(drive) if __name__ == '__main__': -- cgit v1.2.3-54-g00ecf From f5f1f210fe852dfdca3f42200e444d2a61d329c3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:14:56 +0000 Subject: Added more *q, **k to functions --- archinstall.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index c03fd78e..b2716284 100644 --- a/archinstall.py +++ b/archinstall.py @@ -394,11 +394,11 @@ def get_drive_from_uuid(uuid): return None -def get_drive_from_part_uuid(partuuid): +def get_drive_from_part_uuid(partuuid, *positionals, **kwargs): if len(harddrives) <= 0: raise ValueError("No hard drives to iterate in order to find: {}".format(uuid)) for drive in harddrives: - for partition in get_partitions(f'/dev/{drive}'): + for partition in get_partitions(f'/dev/{drive}', *positionals, **kwargs): o = simple_command(f'blkid -s PARTUUID -o value /dev/{drive}') if len(o) and o == partuuid: return drive @@ -463,7 +463,7 @@ def device_state(name, *positionals, **kwargs): return return True -def get_partitions(dev): +def get_partitions(dev, *positionals, **kwargs): drive_name = os.path.basename(dev) parts = oDict() #o = b''.join(sys_command('/usr/bin/lsblk -o name -J -b {dev}'.format(dev=dev))) @@ -790,7 +790,8 @@ def cache_diskpw_on_disk(): pw.write(args['password']) def refresh_partition_list(drive, *positionals, **kwargs): - args['paritions'] = get_partitions(drive) + args['paritions'] = get_partitions(drive, *positionals, **kwargs) + return True if __name__ == '__main__': update_git() # Breaks and restarts the script if an update was found. -- cgit v1.2.3-54-g00ecf From 737c2b648d08816da78e3c5b818f1884d211fda9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:46:20 +0000 Subject: Cleaned up the entire format process into functions. --- archinstall.py | 72 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/archinstall.py b/archinstall.py index b2716284..2749458d 100644 --- a/archinstall.py +++ b/archinstall.py @@ -793,6 +793,52 @@ def refresh_partition_list(drive, *positionals, **kwargs): args['paritions'] = get_partitions(drive, *positionals, **kwargs) return True +def mkfs_fat32(drive, partition, *positionals, **kwargs): + o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {drive}{partition}')) + if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: + return None + return True + +def is_luksdev_mounted(*positionals, **kwargs): + o = b''.join(sys_command('/usr/bin/file /dev/mapper/luksdev')) # /dev/dm-0 + if b'cannot open' in o: + return False + return True + +def mount_luktsdev(drive, partition, keyfile, *positionals, **kwargs): + if not is_luksdev_mounted(): + o = b''.join(sys_command(f'/usr/bin/cryptsetup open {drive}{partition} luksdev --key-file {keyfile} --type luks2'.format(**args))) + return is_luksdev_mounted() + +def encrypt_partition(drive, partition, keyfile='/tmp/diskpw', *positionals, **kwargs): + o = b''.join(sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash sha512 --key-size 512 --iter-time 10000 --key-file {keyfile} --use-urandom luksFormat {drive}{partition}')) + if not b'Command successful.' in o: + return False + return True + +def mkfs_btrfs(drive='/dev/mapper/luksdev', *positionals, **kwargs): + o = b''.join(sys_command('/usr/bin/mkfs.btrfs -f /dev/mapper/luksdev')) + if not b'UUID' in o: + return False + return True + +def mount_luksdev(where='/dev/mapper/luksdev', to='/mnt', *positionals, **kwargs): + o = simple_command('/usr/bin/mount | /usr/bin/grep /mnt') # /dev/dm-0 + if len(o) <= 0: + o = b''.join(sys_command('/usr/bin/mount /dev/mapper/luksdev /mnt')) + return True + +def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs) + os.makedirs('/mnt/boot', exist_ok=True) + o = simple_command('/usr/bin/mount | /usr/bin/grep /mnt/boot') # /dev/dm-0 + if len(o) <= 0: + o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}')) + return True + +def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot'): + mount_luksdev() + mount_boot(drive, bootpartition, mountpoint='/mnt/boot') + if __name__ == '__main__': update_git() # Breaks and restarts the script if an update was found. update_drive_list() @@ -863,42 +909,28 @@ if __name__ == '__main__': print(json.dumps(args['paritions'][part_name], indent=4)) if not args['rerun'] or args['ignore-rerun']: - o = b''.join(sys_command('/usr/bin/mkfs.vfat -F32 {drive}{partition_1}'.format(**args))) - if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: - print('[E] Could not setup {drive}{partition_1}'.format(**args), o) + if not mkfs_fat32(args['drive'], args['partition_1'], *positionals, **kwargs): + print('[E] Could not setup {drive}{partition_1}'.format(**args)) exit(1) # "--cipher sha512" breaks the shit. # TODO: --use-random instead of --use-urandom print('[N] Adding encryption to {drive}{partition_2}.'.format(**args)) - o = b''.join(sys_command('/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash sha512 --key-size 512 --iter-time 10000 --key-file {pwfile} --use-urandom luksFormat {drive}{partition_2}'.format(**args))) - if not b'Command successful.' in o: + if not encrypt_partition(args['drive'], args['partition_2'], args['pwfile']): print('[E] Failed to setup disk encryption.', o) exit(1) - o = b''.join(sys_command('/usr/bin/file /dev/mapper/luksdev')) # /dev/dm-0 - if b'cannot open' in o: - o = b''.join(sys_command('/usr/bin/cryptsetup open {drive}{partition_2} luksdev --key-file {pwfile} --type luks2'.format(**args))) - o = b''.join(sys_command('/usr/bin/file /dev/mapper/luksdev')) # /dev/dm-0 - if b'cannot open' in o: + if not mount_luktsdev(args['drive'], args['partition_2'], args['pwfile']): print('[E] Could not open encrypted device.', o) exit(1) if not args['rerun'] or args['ignore-rerun']: print('[N] Creating btrfs filesystem inside {drive}{partition_2}'.format(**args)) - o = b''.join(sys_command('/usr/bin/mkfs.btrfs -f /dev/mapper/luksdev')) - if not b'UUID' in o: + if not mkfs_btrfs(): print('[E] Could not setup btrfs filesystem.', o) exit(1) - o = simple_command('/usr/bin/mount | /usr/bin/grep /mnt') # /dev/dm-0 - if len(o) <= 0: - o = b''.join(sys_command('/usr/bin/mount /dev/mapper/luksdev /mnt')) - - os.makedirs('/mnt/boot', exist_ok=True) - o = simple_command('/usr/bin/mount | /usr/bin/grep /mnt/boot') # /dev/dm-0 - if len(o) <= 0: - o = b''.join(sys_command('/usr/bin/mount {drive}{partition_1} /mnt/boot'.format(**args))) + mount_mountpoints(args['drive'], args['partition_1']) if 'mirrors' in args and args['mirrors'] and 'country' in args and get_default_gateway_linux(): print('[N] Reordering mirrors.') -- cgit v1.2.3-54-g00ecf From 5a4e1ec0925528003d49c8ba97d214987e750674 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 20:46:46 +0000 Subject: Cleaned up the entire format process into functions. --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 2749458d..452f62f2 100644 --- a/archinstall.py +++ b/archinstall.py @@ -828,7 +828,7 @@ def mount_luksdev(where='/dev/mapper/luksdev', to='/mnt', *positionals, **kwargs o = b''.join(sys_command('/usr/bin/mount /dev/mapper/luksdev /mnt')) return True -def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs) +def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs): os.makedirs('/mnt/boot', exist_ok=True) o = simple_command('/usr/bin/mount | /usr/bin/grep /mnt/boot') # /dev/dm-0 if len(o) <= 0: -- cgit v1.2.3-54-g00ecf From f2e3d8ecf28e0e2d3398948d8b283974d7484ec2 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 21:17:16 +0000 Subject: Converted to a new mode. Each parameter to the functions, are given as strings and later mapped to the args[] structure. This so that you can supply keys in advanced without them being there. In order to chain functions together where functions some where along the chain supplies one of those values --- archinstall.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/archinstall.py b/archinstall.py index 452f62f2..415abc8e 100644 --- a/archinstall.py +++ b/archinstall.py @@ -587,7 +587,10 @@ def close_disks(): o = simple_command('/usr/bin/umount -R /mnt') o = simple_command('/usr/bin/cryptsetup close /dev/mapper/luksdev') -def format_disk(drive=None, start='512MiB', end='100%', emulate=False, *args, **kwargs): +def format_disk(drive='drive', start='start', end='size', emulate=False, *args, **kwargs): + drive = args[drive] + start = args[start] + end = args[end] if not drive: raise ValueError('Need to supply a drive path, for instance: /dev/sdx') print(f'[N] Setting up {drive}.') @@ -790,10 +793,13 @@ def cache_diskpw_on_disk(): pw.write(args['password']) def refresh_partition_list(drive, *positionals, **kwargs): + drive = args[drive] args['paritions'] = get_partitions(drive, *positionals, **kwargs) return True def mkfs_fat32(drive, partition, *positionals, **kwargs): + drive = args[drive] + partition = args[partition] o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {drive}{partition}')) if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: return None @@ -806,11 +812,17 @@ def is_luksdev_mounted(*positionals, **kwargs): return True def mount_luktsdev(drive, partition, keyfile, *positionals, **kwargs): + drive = args[drive] + partition = args[partition] + keyfile = args[keyfile] if not is_luksdev_mounted(): o = b''.join(sys_command(f'/usr/bin/cryptsetup open {drive}{partition} luksdev --key-file {keyfile} --type luks2'.format(**args))) return is_luksdev_mounted() def encrypt_partition(drive, partition, keyfile='/tmp/diskpw', *positionals, **kwargs): + drive = args[drive] + partition = args[partition] + keyfile = args[keyfile] o = b''.join(sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash sha512 --key-size 512 --iter-time 10000 --key-file {keyfile} --use-urandom luksFormat {drive}{partition}')) if not b'Command successful.' in o: return False @@ -836,6 +848,8 @@ def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs) return True def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot'): + drive = args[drive] + bootpartition = args[bootpartition] mount_luksdev() mount_boot(drive, bootpartition, mountpoint='/mnt/boot') @@ -895,9 +909,9 @@ if __name__ == '__main__': time.sleep(1) close_disks() - format_disk(args['drive'], start=args['start'], end=args['size']) + format_disk('drive', start='start', end='size') - refresh_partition_list(args['drive']) + refresh_partition_list('drive') print(f'Partitions: (Boot: {list(args["paritions"].keys())[0]})') if len(args['paritions']) <= 0: @@ -909,18 +923,18 @@ if __name__ == '__main__': print(json.dumps(args['paritions'][part_name], indent=4)) if not args['rerun'] or args['ignore-rerun']: - if not mkfs_fat32(args['drive'], args['partition_1'], *positionals, **kwargs): + if not mkfs_fat32('drive', 'partition_1', *positionals, **kwargs): print('[E] Could not setup {drive}{partition_1}'.format(**args)) exit(1) # "--cipher sha512" breaks the shit. # TODO: --use-random instead of --use-urandom print('[N] Adding encryption to {drive}{partition_2}.'.format(**args)) - if not encrypt_partition(args['drive'], args['partition_2'], args['pwfile']): + if not encrypt_partition('drive', 'partition_2', 'pwfile'): print('[E] Failed to setup disk encryption.', o) exit(1) - if not mount_luktsdev(args['drive'], args['partition_2'], args['pwfile']): + if not mount_luktsdev('drive', 'partition_2', 'pwfile'): print('[E] Could not open encrypted device.', o) exit(1) @@ -930,7 +944,7 @@ if __name__ == '__main__': print('[E] Could not setup btrfs filesystem.', o) exit(1) - mount_mountpoints(args['drive'], args['partition_1']) + mount_mountpoints('drive', 'partition_1') if 'mirrors' in args and args['mirrors'] and 'country' in args and get_default_gateway_linux(): print('[N] Reordering mirrors.') -- cgit v1.2.3-54-g00ecf From 3bcfd23b30509336ac5bdbd72cc7163d091edc3c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 21:19:33 +0000 Subject: Positions, not args --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 415abc8e..59af0fee 100644 --- a/archinstall.py +++ b/archinstall.py @@ -587,7 +587,7 @@ def close_disks(): o = simple_command('/usr/bin/umount -R /mnt') o = simple_command('/usr/bin/cryptsetup close /dev/mapper/luksdev') -def format_disk(drive='drive', start='start', end='size', emulate=False, *args, **kwargs): +def format_disk(drive='drive', start='start', end='size', emulate=False, *positionals, **kwargs): drive = args[drive] start = args[start] end = args[end] -- cgit v1.2.3-54-g00ecf From 9e322c0205f2d1de75cc6336011dcb4ddd72238b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 21:36:12 +0000 Subject: Fetching partitions from the partition tree in the dictionary. --- archinstall.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index 59af0fee..0380bb22 100644 --- a/archinstall.py +++ b/archinstall.py @@ -799,7 +799,7 @@ def refresh_partition_list(drive, *positionals, **kwargs): def mkfs_fat32(drive, partition, *positionals, **kwargs): drive = args[drive] - partition = args[partition] + partition = args['paritions'][partition] o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {drive}{partition}')) if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: return None @@ -813,7 +813,7 @@ def is_luksdev_mounted(*positionals, **kwargs): def mount_luktsdev(drive, partition, keyfile, *positionals, **kwargs): drive = args[drive] - partition = args[partition] + partition = args['paritions'][partition] keyfile = args[keyfile] if not is_luksdev_mounted(): o = b''.join(sys_command(f'/usr/bin/cryptsetup open {drive}{partition} luksdev --key-file {keyfile} --type luks2'.format(**args))) @@ -821,7 +821,7 @@ def mount_luktsdev(drive, partition, keyfile, *positionals, **kwargs): def encrypt_partition(drive, partition, keyfile='/tmp/diskpw', *positionals, **kwargs): drive = args[drive] - partition = args[partition] + partition = args['paritions'][partition] keyfile = args[keyfile] o = b''.join(sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash sha512 --key-size 512 --iter-time 10000 --key-file {keyfile} --use-urandom luksFormat {drive}{partition}')) if not b'Command successful.' in o: -- cgit v1.2.3-54-g00ecf From 4cd31af1b0e4409d96f3d9c4107d58d68b9924a9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 21:37:34 +0000 Subject: Debugging --- archinstall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall.py b/archinstall.py index 0380bb22..a9295f22 100644 --- a/archinstall.py +++ b/archinstall.py @@ -795,6 +795,7 @@ def cache_diskpw_on_disk(): def refresh_partition_list(drive, *positionals, **kwargs): drive = args[drive] args['paritions'] = get_partitions(drive, *positionals, **kwargs) + print(json.dumps(args['paritions'], indent=4)) return True def mkfs_fat32(drive, partition, *positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 0afa90f815c78d2c45bdd3fecfc5e4f801269eed Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 21:46:07 +0000 Subject: Refresh partitions function enhanced. Previously it just returned a unsorted mess, now the args['partitions'] structure is finalized in that function --- archinstall.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/archinstall.py b/archinstall.py index a9295f22..a0f69c07 100644 --- a/archinstall.py +++ b/archinstall.py @@ -399,7 +399,7 @@ def get_drive_from_part_uuid(partuuid, *positionals, **kwargs): for drive in harddrives: for partition in get_partitions(f'/dev/{drive}', *positionals, **kwargs): - o = simple_command(f'blkid -s PARTUUID -o value /dev/{drive}') + o = simple_command(f'blkid -s PARTUUID -o value /dev/{drive}{partition}') if len(o) and o == partuuid: return drive @@ -794,8 +794,9 @@ def cache_diskpw_on_disk(): def refresh_partition_list(drive, *positionals, **kwargs): drive = args[drive] - args['paritions'] = get_partitions(drive, *positionals, **kwargs) - print(json.dumps(args['paritions'], indent=4)) + partitions = oDict() + for index, part_name in enumerate(sorted(get_partitions(drive, *positionals, **kwargs).keys())): + args['partitions'][index+1] = part_name return True def mkfs_fat32(drive, partition, *positionals, **kwargs): @@ -918,34 +919,30 @@ if __name__ == '__main__': if len(args['paritions']) <= 0: print('[E] No paritions were created on {drive}'.format(**args), o) exit(1) - for index, part_name in enumerate(sorted(args['paritions'].keys())): - args['partition_{}'.format(index+1)] = part_name - print(f'Partition info: {part_name}') - print(json.dumps(args['paritions'][part_name], indent=4)) if not args['rerun'] or args['ignore-rerun']: - if not mkfs_fat32('drive', 'partition_1', *positionals, **kwargs): - print('[E] Could not setup {drive}{partition_1}'.format(**args)) + if not mkfs_fat32('drive', '1', *positionals, **kwargs): + print(f'[E] Could not setup {args["drive"]}{args["paritions"]["1"]}') exit(1) # "--cipher sha512" breaks the shit. # TODO: --use-random instead of --use-urandom - print('[N] Adding encryption to {drive}{partition_2}.'.format(**args)) - if not encrypt_partition('drive', 'partition_2', 'pwfile'): + print(f'[N] Adding encryption to {drive}{partitions["2"]}.') + if not encrypt_partition('drive', '2', 'pwfile'): print('[E] Failed to setup disk encryption.', o) exit(1) - if not mount_luktsdev('drive', 'partition_2', 'pwfile'): + if not mount_luktsdev('drive', '2', 'pwfile'): print('[E] Could not open encrypted device.', o) exit(1) if not args['rerun'] or args['ignore-rerun']: - print('[N] Creating btrfs filesystem inside {drive}{partition_2}'.format(**args)) + print(f'[N] Creating btrfs filesystem inside {args["drive"]}{args["partitions"]["2"]}') if not mkfs_btrfs(): print('[E] Could not setup btrfs filesystem.', o) exit(1) - mount_mountpoints('drive', 'partition_1') + mount_mountpoints('drive', '1') if 'mirrors' in args and args['mirrors'] and 'country' in args and get_default_gateway_linux(): print('[N] Reordering mirrors.') @@ -1042,7 +1039,7 @@ if __name__ == '__main__': ## For some reason, blkid and /dev/disk/by-uuid are not getting along well. ## And blkid is wrong in terms of LUKS. #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip() - UUID = simple_command("ls -l /dev/disk/by-uuid/ | grep {basename}{partition_2} | awk '{{print $9}}'".format(basename=os.path.basename(args['drive']), **args)).decode('UTF-8').strip() + UUID = simple_command(f"ls -l /dev/disk/by-uuid/ | grep {os.path.basename(args['drive'])}{args['partitions']['2']} | awk '{{print $9}}'").decode('UTF-8').strip() with open('/mnt/boot/loader/entries/arch.conf', 'w') as entry: entry.write('title Arch Linux\n') entry.write('linux /vmlinuz-linux\n') -- cgit v1.2.3-54-g00ecf From 3c2a88bd7a8f0face88628f09b90bad61c185ed9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 21:47:49 +0000 Subject: Refresh partitions function enhanced. Previously it just returned a unsorted mess, now the args['partitions'] structure is finalized in that function --- archinstall.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/archinstall.py b/archinstall.py index a0f69c07..297eb12a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -611,7 +611,7 @@ def format_disk(drive='drive', start='start', end='size', emulate=False, *positi if sys_command(f'/usr/bin/parted -s {drive} mkpart primary {start} {end}', emulate=emulate).exit_code != 0: return None - # TODO: grab paritions after each parted/partition step instead of guessing which partiton is which later on. + # TODO: grab partitions after each parted/partition step instead of guessing which partiton is which later on. # Create one, grab partitions - dub that to "boot" or something. do the next partition, grab that and dub it "system".. or something.. # This "assumption" has bit me in the ass so many times now I've stoped counting.. Jerker is right.. Don't do it like this :P @@ -794,14 +794,15 @@ def cache_diskpw_on_disk(): def refresh_partition_list(drive, *positionals, **kwargs): drive = args[drive] - partitions = oDict() + if not 'partitions' in args: + args['partitions'] = oDict() for index, part_name in enumerate(sorted(get_partitions(drive, *positionals, **kwargs).keys())): args['partitions'][index+1] = part_name return True def mkfs_fat32(drive, partition, *positionals, **kwargs): drive = args[drive] - partition = args['paritions'][partition] + partition = args['partitions'][partition] o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {drive}{partition}')) if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: return None @@ -815,7 +816,7 @@ def is_luksdev_mounted(*positionals, **kwargs): def mount_luktsdev(drive, partition, keyfile, *positionals, **kwargs): drive = args[drive] - partition = args['paritions'][partition] + partition = args['partitions'][partition] keyfile = args[keyfile] if not is_luksdev_mounted(): o = b''.join(sys_command(f'/usr/bin/cryptsetup open {drive}{partition} luksdev --key-file {keyfile} --type luks2'.format(**args))) @@ -823,7 +824,7 @@ def mount_luktsdev(drive, partition, keyfile, *positionals, **kwargs): def encrypt_partition(drive, partition, keyfile='/tmp/diskpw', *positionals, **kwargs): drive = args[drive] - partition = args['paritions'][partition] + partition = args['partitions'][partition] keyfile = args[keyfile] o = b''.join(sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash sha512 --key-size 512 --iter-time 10000 --key-file {keyfile} --use-urandom luksFormat {drive}{partition}')) if not b'Command successful.' in o: @@ -914,15 +915,15 @@ if __name__ == '__main__': format_disk('drive', start='start', end='size') refresh_partition_list('drive') - print(f'Partitions: (Boot: {list(args["paritions"].keys())[0]})') + print(f'Partitions: (Boot: {list(args["partitions"].keys())[0]})') - if len(args['paritions']) <= 0: - print('[E] No paritions were created on {drive}'.format(**args), o) + if len(args['partitions']) <= 0: + print('[E] No partitions were created on {drive}'.format(**args), o) exit(1) if not args['rerun'] or args['ignore-rerun']: if not mkfs_fat32('drive', '1', *positionals, **kwargs): - print(f'[E] Could not setup {args["drive"]}{args["paritions"]["1"]}') + print(f'[E] Could not setup {args["drive"]}{args["partitions"]["1"]}') exit(1) # "--cipher sha512" breaks the shit. -- cgit v1.2.3-54-g00ecf From 3657cc5c6e2315f62273272c297f769e472a6fd5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 21:50:56 +0000 Subject: Debugging --- archinstall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall.py b/archinstall.py index 297eb12a..525387f9 100644 --- a/archinstall.py +++ b/archinstall.py @@ -801,6 +801,7 @@ def refresh_partition_list(drive, *positionals, **kwargs): return True def mkfs_fat32(drive, partition, *positionals, **kwargs): + print(json.dumps(args, indent=4)) drive = args[drive] partition = args['partitions'][partition] o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {drive}{partition}')) -- cgit v1.2.3-54-g00ecf From 1129dae13d0f5cb9c33acd8b46b3173cb1a2e86a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 22:02:45 +0000 Subject: Debugging --- archinstall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall.py b/archinstall.py index 525387f9..0a82ace7 100644 --- a/archinstall.py +++ b/archinstall.py @@ -803,6 +803,7 @@ def refresh_partition_list(drive, *positionals, **kwargs): def mkfs_fat32(drive, partition, *positionals, **kwargs): print(json.dumps(args, indent=4)) drive = args[drive] + print(partition, type(partition), args['partitions'], type(args['partitions'])) partition = args['partitions'][partition] o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {drive}{partition}')) if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: -- cgit v1.2.3-54-g00ecf From 29b091e0370bdde3a6955b8b646174436fad18b8 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 22:03:49 +0000 Subject: String convertion on part numbers, maybe a stupid idea? --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 0a82ace7..f2ed3a7a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -797,7 +797,7 @@ def refresh_partition_list(drive, *positionals, **kwargs): if not 'partitions' in args: args['partitions'] = oDict() for index, part_name in enumerate(sorted(get_partitions(drive, *positionals, **kwargs).keys())): - args['partitions'][index+1] = part_name + args['partitions'][str(index+1)] = part_name return True def mkfs_fat32(drive, partition, *positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 755efe5706590dd096be551847855293c641df89 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 22:05:17 +0000 Subject: Positions and kwargs not added to functions --- archinstall.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index f2ed3a7a..00744044 100644 --- a/archinstall.py +++ b/archinstall.py @@ -801,9 +801,7 @@ def refresh_partition_list(drive, *positionals, **kwargs): return True def mkfs_fat32(drive, partition, *positionals, **kwargs): - print(json.dumps(args, indent=4)) drive = args[drive] - print(partition, type(partition), args['partitions'], type(args['partitions'])) partition = args['partitions'][partition] o = b''.join(sys_command(f'/usr/bin/mkfs.vfat -F32 {drive}{partition}')) if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: @@ -852,11 +850,11 @@ def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs) o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}')) return True -def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot'): +def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs): drive = args[drive] bootpartition = args[bootpartition] - mount_luksdev() - mount_boot(drive, bootpartition, mountpoint='/mnt/boot') + mount_luksdev(*positionals, **kwargs) + mount_boot(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs) if __name__ == '__main__': update_git() # Breaks and restarts the script if an update was found. -- cgit v1.2.3-54-g00ecf From ceb73c5523d5ff8fb32e8a95d16d0d81914fbcfc Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 22:09:24 +0000 Subject: Correction on args fetching --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 00744044..76afbddc 100644 --- a/archinstall.py +++ b/archinstall.py @@ -852,7 +852,7 @@ def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs) def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs): drive = args[drive] - bootpartition = args[bootpartition] + bootpartition = args['partitions'][bootpartition] mount_luksdev(*positionals, **kwargs) mount_boot(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs) -- cgit v1.2.3-54-g00ecf From fda94e5b9579298478c79d53c08e9f80ea4424ed Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 22:14:54 +0000 Subject: Forgot return value --- archinstall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall.py b/archinstall.py index 76afbddc..7067d5ec 100644 --- a/archinstall.py +++ b/archinstall.py @@ -855,6 +855,7 @@ def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals bootpartition = args['partitions'][bootpartition] mount_luksdev(*positionals, **kwargs) mount_boot(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs) + return True if __name__ == '__main__': update_git() # Breaks and restarts the script if an update was found. -- cgit v1.2.3-54-g00ecf From cf865c98b59562f6cf8e1761b0a925aa1c01ab1f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 23:12:36 +0000 Subject: Finished moving almost all steps into functions. --- archinstall.py | 337 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 184 insertions(+), 153 deletions(-) diff --git a/archinstall.py b/archinstall.py index 7067d5ec..d0bd23b8 100644 --- a/archinstall.py +++ b/archinstall.py @@ -502,7 +502,7 @@ def disk_info(drive, *positionals, **kwargs): lkwargs = {**kwargs} lkwargs['emulate'] = False # This is a emulate-safe function. Does not alter filesystem. - info = json.loads(b''.join(sys_command(f'lsblk -J -o "NAME,SIZE,FSTYPE,LABEL" {drive}', *positionals, **lkwargs)).decode('UTF_8'))['blockdevices'][0] + info = json.loads(b''.join(sys_command(f'lsblk -J -o "NAME,SIZE,FSTYPE,LABEL" {drive}', *positionals, **lkwargs, hide_from_log=True)).decode('UTF_8'))['blockdevices'][0] fileformats = [] labels = [] if 'children' in info: ## Might not be partitioned yet @@ -809,7 +809,7 @@ def mkfs_fat32(drive, partition, *positionals, **kwargs): return True def is_luksdev_mounted(*positionals, **kwargs): - o = b''.join(sys_command('/usr/bin/file /dev/mapper/luksdev')) # /dev/dm-0 + o = b''.join(sys_command('/usr/bin/file /dev/mapper/luksdev', hide_from_log=True)) # /dev/dm-0 if b'cannot open' in o: return False return True @@ -857,6 +857,182 @@ def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals mount_boot(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs) return True +def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): + ## TODO: replace wget with urllib.request (no point in calling syscommand) + country_list = [] + for country in countries.split(','): + country_list.append(f'country={country}') + o = simple_command(f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(country_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist") + o = simple_command("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist") + o = simple_command('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist') + return True + +def strap_in_base(*positionals, **kwargs): + if args['aur-support']: + args['packages'] += ' git' + if sys_command('/usr/bin/pacman -Syy').exit_code == 0: + if sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args)).exit_code == 0: + return True + return False + +def configure_base_system(*positionals, **kwargs): + ## TODO: Replace a lot of these syscalls with just python native operations. + o = b''.join(sys_command('/usr/bin/genfstab -pU /mnt >> /mnt/etc/fstab')) + with open('/mnt/etc/fstab', 'a') as fstab: + fstab.write('\ntmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0\n') # Redundant \n at the start? who knoes? + + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt rm -f /etc/localtime')) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt ln -s /usr/share/zoneinfo/{localtime} /etc/localtime'.format(**args))) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt hwclock --hctosys --localtime')) + #o = sys_command('arch-chroot /mnt echo "{hostname}" > /etc/hostname'.format(**args)) + #o = sys_command("arch-chroot /mnt sed -i 's/#\(en_US\.UTF-8\)/\1/' /etc/locale.gen") + o = b''.join(sys_command("/usr/bin/arch-chroot /mnt sh -c \"echo '{hostname}' > /etc/hostname\"".format(**args))) + o = b''.join(sys_command("/usr/bin/arch-chroot /mnt sh -c \"echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen\"")) + o = b''.join(sys_command("/usr/bin/arch-chroot /mnt sh -c \"echo 'LANG=en_US.UTF-8' > /etc/locale.conf\"")) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt locale-gen')) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt chmod 700 /root')) + + with open('/mnt/etc/mkinitcpio.conf', 'w') as mkinit: + ## TODO: Don't replace it, in case some update in the future actually adds something. + mkinit.write('MODULES=(btrfs)\n') + mkinit.write('BINARIES=(/usr/bin/btrfs)\n') + mkinit.write('FILES=()\n') + mkinit.write('HOOKS=(base udev autodetect modconf block encrypt filesystems keyboard fsck)\n') + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt mkinitcpio -p linux')) + + return True + +def setup_bootloader(*positionals, **kwargs): + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt bootctl --no-variables --path=/boot install')) + + with open('/mnt/boot/loader/loader.conf', 'w') as loader: + loader.write('default arch\n') + loader.write('timeout 5\n') + + ## For some reason, blkid and /dev/disk/by-uuid are not getting along well. + ## And blkid is wrong in terms of LUKS. + #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip() + UUID = simple_command(f"ls -l /dev/disk/by-uuid/ | grep {os.path.basename(args['drive'])}{args['partitions']['2']} | awk '{{print $9}}'").decode('UTF-8').strip() + with open('/mnt/boot/loader/entries/arch.conf', 'w') as entry: + entry.write('title Arch Linux\n') + entry.write('linux /vmlinuz-linux\n') + entry.write('initrd /initramfs-linux.img\n') + entry.write('options cryptdevice=UUID={UUID}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n'.format(UUID=UUID)) + + return True + +def add_AUR_support(*positionals, **kwargs): + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "useradd -m -G wheel aibuilder"')) + o = b''.join(sys_command("/usr/bin/sed -i 's/# %wheel ALL=(ALL) NO/%wheel ALL=(ALL) NO/' /mnt/etc/sudoers")) + + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "su - aibuilder -c \\"(cd /home/aibuilder; git clone https://aur.archlinux.org/yay.git)\\""')) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "chown -R aibuilder.aibuilder /home/aibuilder/yay"')) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "su - aibuilder -c \\"(cd /home/aibuilder/yay; makepkg -si --noconfirm)\\" >/dev/null"')) + ## Do not remove aibuilder just yet, can be used later for aur packages. + #o = b''.join(sys_command('/usr/bin/sed -i \'s/%wheel ALL=(ALL) NO/# %wheel ALL=(ALL) NO/\' /mnt/etc/sudoers')) + #o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "userdel aibuilder"')) + #o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "rm -rf /home/aibuilder"')) + return True + +def run_post_install_steps(*positionals, **kwargs): + conf = {} + if 'post' in instructions: + conf = instructions['post'] + elif not 'args' in instructions and len(instructions): + conf = instructions + + if 'git-branch' in conf: + update_git(conf['git-branch']) + del(conf['git-branch']) + + for title in conf: + if args['rerun'] and args['rerun'] != title and not rerun: + continue + else: + rerun = True + + print('[N] Network Deploy: {}'.format(title)) + if type(conf[title]) == str: + print('[N] Loading {} configuration'.format(conf[title])) + conf[title] = get_application_instructions(conf[title]) + + for command in conf[title]: + raw_command = command + opts = conf[title][command] if type(conf[title][command]) in (dict, oDict) else {} + if len(opts): + if 'pass-args' in opts or 'format' in opts: + command = command.format(**args) + ## FIXME: Instead of deleting the two options + ## in order to mute command output further down, + ## check for a 'debug' flag per command and delete these two + if 'pass-args' in opts: + del(opts['pass-args']) + elif 'format' in opts: + del(opts['format']) + elif ('debug' in opts and opts['debug']) or ('debug' in conf and conf['debug']): + print('[-] Options: {}'.format(opts)) + if 'pass-args' in opts and opts['pass-args']: + command = command.format(**args) + + if 'runas' in opts and f'su - {opts["runas"]} -c' not in command: + command = command.replace('"', '\\"') + command = f'su - {opts["runas"]} -c "{command}"' + + #print('[N] Command: {} ({})'.format(command, opts)) + + ## https://superuser.com/questions/1242978/start-systemd-nspawn-and-execute-commands-inside + ## !IMPORTANT + ## + ## arch-chroot mounts /run into the chroot environment, this breaks name resolves for some reason. + ## Either skipping mounting /run and using traditional chroot is an option, but using + ## `systemd-nspawn -D /mnt --machine temporary` might be a more flexible solution in case of file structure changes. + if 'no-chroot' in opts and opts['no-chroot']: + o = simple_command(command, opts) + elif 'chroot' in opts and opts['chroot']: + ## Run in a manually set up version of arch-chroot (arch-chroot will break namespaces). + ## This is a bit risky in case the file systems changes over the years, but we'll probably be safe adding this as an option. + ## **> Prefer if possible to use 'no-chroot' instead which "live boots" the OS and runs the command. + o = simple_command("mount /dev/mapper/luksdev /mnt") + o = simple_command("cd /mnt; cp /etc/resolv.conf etc") + o = simple_command("cd /mnt; mount -t proc /proc proc") + o = simple_command("cd /mnt; mount --make-rslave --rbind /sys sys") + o = simple_command("cd /mnt; mount --make-rslave --rbind /dev dev") + o = simple_command('chroot /mnt /bin/bash -c "{c}"'.format(c=command), opts=opts) + o = simple_command("cd /mnt; umount -R dev") + o = simple_command("cd /mnt; umount -R sys") + o = simple_command("cd /mnt; umount -R proc") + else: + if 'boot' in opts and opts['boot']: + ## So, if we're going to boot this maddafakker up, we'll need to + ## be able to login. The quickest way is to just add automatic login.. so lessgo! + + ## Turns out.. that didn't work exactly as planned.. + ## + # if not os.path.isdir('/mnt/etc/systemd/system/console-getty.service.d/'): + # os.makedirs('/mnt/etc/systemd/system/console-getty.service.d/') + # with open('/mnt/etc/systemd/system/console-getty.service.d/override.conf', 'w') as fh: + # fh.write('[Service]\n') + # fh.write('ExecStart=\n') + # fh.write('ExecStart=-/usr/bin/agetty --autologin root -s %I 115200,38400,9600 vt102\n') + + ## So we'll add a bunch of triggers instead and let the sys_command manually react to them. + ## " login" followed by "Passwodd" in case it's been set in a previous step.. usually this shouldn't be nessecary + ## since we set the password as the last step. And then the command itself which will be executed by looking for: + ## [root@ ~]# + o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', opts={'triggers' : { + bytes(f'login:', 'UTF-8') : b'root\n', + #b'Password:' : bytes(args['password']+'\n', 'UTF-8'), + bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), + }, **opts})) + + ## Not needed anymore: And cleanup after out selves.. Don't want to leave any residue.. + # os.remove('/mnt/etc/systemd/system/console-getty.service.d/override.conf') + else: + o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt --machine temporary {c}'.format(c=command), opts=opts)) + if type(conf[title][raw_command]) == bytes and len(conf[title][raw_command]) and not conf[title][raw_command] in o: + print('[W] Post install command failed: {}'.format(o.decode('UTF-8'))) + #print(o) + if __name__ == '__main__': update_git() # Breaks and restarts the script if an update was found. update_drive_list() @@ -948,9 +1124,7 @@ if __name__ == '__main__': if 'mirrors' in args and args['mirrors'] and 'country' in args and get_default_gateway_linux(): print('[N] Reordering mirrors.') - o = simple_command("/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?country={country}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist".format(**args)) - o = simple_command("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist") - o = simple_command('/usr/bin/rankmirrors -n 6 /root/mirrorlist > /etc/pacman.d/mirrorlist') + filter_mirrors_by_country(args['country']) pre_conf = {} if 'pre' in instructions: @@ -999,166 +1173,23 @@ if __name__ == '__main__': if not args['rerun'] or rerun: print('[N] Straping in packages.') - if args['aur-support']: - args['packages'] += ' git' - o = b''.join(sys_command('/usr/bin/pacman -Syy')) - o = b''.join(sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args))) + strap_in_base() # TODO: check return here? we return based off pacstrap exit code.. Never tired it tho. if not os.path.isdir('/mnt/etc'): # TODO: This might not be the most long term stable thing to rely on... print('[E] Failed to strap in packages', o) exit(1) if not args['rerun'] or rerun: - o = b''.join(sys_command('/usr/bin/genfstab -pU /mnt >> /mnt/etc/fstab')) - with open('/mnt/etc/fstab', 'a') as fstab: - fstab.write('\ntmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0\n') # Redundant \n at the start? who knoes? - - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt rm -f /etc/localtime')) - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt ln -s /usr/share/zoneinfo/{localtime} /etc/localtime'.format(**args))) - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt hwclock --hctosys --localtime')) - #o = sys_command('arch-chroot /mnt echo "{hostname}" > /etc/hostname'.format(**args)) - #o = sys_command("arch-chroot /mnt sed -i 's/#\(en_US\.UTF-8\)/\1/' /etc/locale.gen") - o = b''.join(sys_command("/usr/bin/arch-chroot /mnt sh -c \"echo '{hostname}' > /etc/hostname\"".format(**args))) - o = b''.join(sys_command("/usr/bin/arch-chroot /mnt sh -c \"echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen\"")) - o = b''.join(sys_command("/usr/bin/arch-chroot /mnt sh -c \"echo 'LANG=en_US.UTF-8' > /etc/locale.conf\"")) - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt locale-gen')) - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt chmod 700 /root')) - - with open('/mnt/etc/mkinitcpio.conf', 'w') as mkinit: - ## TODO: Don't replace it, in case some update in the future actually adds something. - mkinit.write('MODULES=(btrfs)\n') - mkinit.write('BINARIES=(/usr/bin/btrfs)\n') - mkinit.write('FILES=()\n') - mkinit.write('HOOKS=(base udev autodetect modconf block encrypt filesystems keyboard fsck)\n') - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt mkinitcpio -p linux')) + configure_base_system() ## WORKAROUND: https://github.com/systemd/systemd/issues/13603#issuecomment-552246188 - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt bootctl --no-variables --path=/boot install')) - - with open('/mnt/boot/loader/loader.conf', 'w') as loader: - loader.write('default arch\n') - loader.write('timeout 5\n') - - ## For some reason, blkid and /dev/disk/by-uuid are not getting along well. - ## And blkid is wrong in terms of LUKS. - #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip() - UUID = simple_command(f"ls -l /dev/disk/by-uuid/ | grep {os.path.basename(args['drive'])}{args['partitions']['2']} | awk '{{print $9}}'").decode('UTF-8').strip() - with open('/mnt/boot/loader/entries/arch.conf', 'w') as entry: - entry.write('title Arch Linux\n') - entry.write('linux /vmlinuz-linux\n') - entry.write('initrd /initramfs-linux.img\n') - entry.write('options cryptdevice=UUID={UUID}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n'.format(UUID=UUID)) + setup_bootloader() if args['aur-support']: print('[N] AUR support demanded, building "yay" before running POST steps.') - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "useradd -m -G wheel aibuilder"')) - o = b''.join(sys_command("/usr/bin/sed -i 's/# %wheel ALL=(ALL) NO/%wheel ALL=(ALL) NO/' /mnt/etc/sudoers")) - - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "su - aibuilder -c \\"(cd /home/aibuilder; git clone https://aur.archlinux.org/yay.git)\\""')) - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "chown -R aibuilder.aibuilder /home/aibuilder/yay"')) - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "su - aibuilder -c \\"(cd /home/aibuilder/yay; makepkg -si --noconfirm)\\" >/dev/null"')) - ## Do not remove aibuilder just yet, can be used later for aur packages. - #o = b''.join(sys_command('/usr/bin/sed -i \'s/%wheel ALL=(ALL) NO/# %wheel ALL=(ALL) NO/\' /mnt/etc/sudoers')) - #o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "userdel aibuilder"')) - #o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "rm -rf /home/aibuilder"')) + add_AUR_support() print('[N] AUR support added. use "yay -Syy --noconfirm " to deploy in POST.') - conf = {} - if 'post' in instructions: - conf = instructions['post'] - elif not 'args' in instructions and len(instructions): - conf = instructions - - if 'git-branch' in conf: - update_git(conf['git-branch']) - del(conf['git-branch']) - - for title in conf: - if args['rerun'] and args['rerun'] != title and not rerun: - continue - else: - rerun = True - - print('[N] Network Deploy: {}'.format(title)) - if type(conf[title]) == str: - print('[N] Loading {} configuration'.format(conf[title])) - conf[title] = get_application_instructions(conf[title]) - - for command in conf[title]: - raw_command = command - opts = conf[title][command] if type(conf[title][command]) in (dict, oDict) else {} - if len(opts): - if 'pass-args' in opts or 'format' in opts: - command = command.format(**args) - ## FIXME: Instead of deleting the two options - ## in order to mute command output further down, - ## check for a 'debug' flag per command and delete these two - if 'pass-args' in opts: - del(opts['pass-args']) - elif 'format' in opts: - del(opts['format']) - elif ('debug' in opts and opts['debug']) or ('debug' in conf and conf['debug']): - print('[-] Options: {}'.format(opts)) - if 'pass-args' in opts and opts['pass-args']: - command = command.format(**args) - - if 'runas' in opts and f'su - {opts["runas"]} -c' not in command: - command = command.replace('"', '\\"') - command = f'su - {opts["runas"]} -c "{command}"' - - #print('[N] Command: {} ({})'.format(command, opts)) - - ## https://superuser.com/questions/1242978/start-systemd-nspawn-and-execute-commands-inside - ## !IMPORTANT - ## - ## arch-chroot mounts /run into the chroot environment, this breaks name resolves for some reason. - ## Either skipping mounting /run and using traditional chroot is an option, but using - ## `systemd-nspawn -D /mnt --machine temporary` might be a more flexible solution in case of file structure changes. - if 'no-chroot' in opts and opts['no-chroot']: - o = simple_command(command, opts) - elif 'chroot' in opts and opts['chroot']: - ## Run in a manually set up version of arch-chroot (arch-chroot will break namespaces). - ## This is a bit risky in case the file systems changes over the years, but we'll probably be safe adding this as an option. - ## **> Prefer if possible to use 'no-chroot' instead which "live boots" the OS and runs the command. - o = simple_command("mount /dev/mapper/luksdev /mnt") - o = simple_command("cd /mnt; cp /etc/resolv.conf etc") - o = simple_command("cd /mnt; mount -t proc /proc proc") - o = simple_command("cd /mnt; mount --make-rslave --rbind /sys sys") - o = simple_command("cd /mnt; mount --make-rslave --rbind /dev dev") - o = simple_command('chroot /mnt /bin/bash -c "{c}"'.format(c=command), opts=opts) - o = simple_command("cd /mnt; umount -R dev") - o = simple_command("cd /mnt; umount -R sys") - o = simple_command("cd /mnt; umount -R proc") - else: - if 'boot' in opts and opts['boot']: - ## So, if we're going to boot this maddafakker up, we'll need to - ## be able to login. The quickest way is to just add automatic login.. so lessgo! - - ## Turns out.. that didn't work exactly as planned.. - ## - # if not os.path.isdir('/mnt/etc/systemd/system/console-getty.service.d/'): - # os.makedirs('/mnt/etc/systemd/system/console-getty.service.d/') - # with open('/mnt/etc/systemd/system/console-getty.service.d/override.conf', 'w') as fh: - # fh.write('[Service]\n') - # fh.write('ExecStart=\n') - # fh.write('ExecStart=-/usr/bin/agetty --autologin root -s %I 115200,38400,9600 vt102\n') - - ## So we'll add a bunch of triggers instead and let the sys_command manually react to them. - ## " login" followed by "Passwodd" in case it's been set in a previous step.. usually this shouldn't be nessecary - ## since we set the password as the last step. And then the command itself which will be executed by looking for: - ## [root@ ~]# - o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', opts={'triggers' : { - bytes(f'login:', 'UTF-8') : b'root\n', - #b'Password:' : bytes(args['password']+'\n', 'UTF-8'), - bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), - }, **opts})) - - ## Not needed anymore: And cleanup after out selves.. Don't want to leave any residue.. - # os.remove('/mnt/etc/systemd/system/console-getty.service.d/override.conf') - else: - o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt --machine temporary {c}'.format(c=command), opts=opts)) - if type(conf[title][raw_command]) == bytes and len(conf[title][raw_command]) and not conf[title][raw_command] in o: - print('[W] Post install command failed: {}'.format(o.decode('UTF-8'))) - #print(o) + run_post_install_steps() if args['aur-support']: o = b''.join(sys_command('/usr/bin/sed -i \'s/%wheel ALL=(ALL) NO/# %wheel ALL=(ALL) NO/\' /mnt/etc/sudoers')) -- cgit v1.2.3-54-g00ecf From 03ceef69f17897b0f725bb29ce1ac3206d7e4c8e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 23:35:09 +0000 Subject: Debugging --- archinstall.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index d0bd23b8..41e67c3a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -870,8 +870,8 @@ def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): def strap_in_base(*positionals, **kwargs): if args['aur-support']: args['packages'] += ' git' - if sys_command('/usr/bin/pacman -Syy').exit_code == 0: - if sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args)).exit_code == 0: + if sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs).exit_code == 0: + if sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args), *positionals, **kwargs).exit_code == 0: return True return False -- cgit v1.2.3-54-g00ecf From 4f394d40ceddb5d9c9de7a11b2dc1efeaf2ad19f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 23:42:04 +0000 Subject: mismatch between archinstall and archinstall_gui in the worker class --- archinstall.py | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/archinstall.py b/archinstall.py index 41e67c3a..9cf7246a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -370,17 +370,38 @@ class sys_command():#Thread): worker_history[self.worker_id] = self.dump() - if 'dependency' in self.kwargs and self.exit_code == 0: - ## If this had a dependency waiting, - ## Start it since there's no hook for this yet, the worker has to spawn it's waiting workers. - module = self.kwargs['dependency']['module'] - print(self.cmd[0],'fullfills a dependency:', module) - dependency_id = self.kwargs['dependency']['id'] - dependencies[module][dependency_id]['fullfilled'] = True - dependencies[module][dependency_id]['spawn'](*dependencies[module][dependency_id]['args'], **dependencies[module][dependency_id]['kwargs'], start_callback=_worker_started_notification) + if 'dependency' in self.kwargs: + pass # TODO: Not yet supported (steal it from archinstall_gui) + """ + dependency = self.kwargs['dependency'] + if type(dependency) == str: + # Dependency is a progress-string. Wait for it to show up. + while main and main.isAlive() and dependency not in progress or progress[dependency] is None: + time.sleep(0.25) + dependency = progress[dependency] + + if type(dependency) == str: + log(f"{self.func} waited for progress {dependency} which never showed up. Aborting.", level=2, origin='worker', function='run') + self.ended = time.time() + self.status = 'aborted' + return None + + while main and main.isAlive() and dependency.ended is None: + time.sleep(0.25) + + print(' *** Dependency released for:', self.func) + + if dependency.data is None or not main or not main.isAlive(): + log('Dependency:', dependency.func, 'did not exit clearly. There for,', self.func, 'can not execute.', level=2, origin='worker', function='run') + self.ended = time.time() + self.status = 'aborted' + return None + """ if self.callback: - self.callback(self, *self.args, **self.kwargs) + pass # TODO: Not yet supported (steal it from archinstall_gui) + + #self.callback(self, *self.args, **self.kwargs) def get_drive_from_uuid(uuid): if len(harddrives) <= 0: raise ValueError("No hard drives to iterate in order to find: {}".format(uuid)) -- cgit v1.2.3-54-g00ecf From d80d74b82090a9097bc483f81ae5d84643007ca3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 18 Nov 2019 23:44:50 +0000 Subject: Debugging --- archinstall.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 9cf7246a..2e1a9b7a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -257,7 +257,7 @@ class sys_command():#Thread): yield line def __repr__(self, *positionals, **kwargs): - return self.trace_log.decode('UTF-8') + return f"{self.cmd, self.trace_log}" def decode(self, fmt='UTF-8'): return self.trace_log.decode(fmt) @@ -891,7 +891,10 @@ def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): def strap_in_base(*positionals, **kwargs): if args['aur-support']: args['packages'] += ' git' - if sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs).exit_code == 0: + x = sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs) + print(x) + print(x.exit_code) + if x.exit_code == 0: if sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args), *positionals, **kwargs).exit_code == 0: return True return False -- cgit v1.2.3-54-g00ecf From e7e7390c7e0325cc0b214e04126d853ca4f770f3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:07:33 +0000 Subject: Debug --- archinstall.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 2e1a9b7a..67a64cd7 100644 --- a/archinstall.py +++ b/archinstall.py @@ -892,8 +892,8 @@ def strap_in_base(*positionals, **kwargs): if args['aur-support']: args['packages'] += ' git' x = sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs) - print(x) - print(x.exit_code) + print('Handle:', x) + print('Exit code:', x.exit_code) if x.exit_code == 0: if sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args), *positionals, **kwargs).exit_code == 0: return True -- cgit v1.2.3-54-g00ecf From 22698ad65cbd5c24870f0e03eb8b5986ea3f7b88 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:09:25 +0000 Subject: debugging --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 67a64cd7..d62949ba 100644 --- a/archinstall.py +++ b/archinstall.py @@ -893,7 +893,7 @@ def strap_in_base(*positionals, **kwargs): args['packages'] += ' git' x = sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs) print('Handle:', x) - print('Exit code:', x.exit_code) + print('Exit code:', x.exit_code, x.exit_code == 0) if x.exit_code == 0: if sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args), *positionals, **kwargs).exit_code == 0: return True -- cgit v1.2.3-54-g00ecf From 42676d57877bcccb8e5f2869891a790e94d450a0 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:11:43 +0000 Subject: debugging --- archinstall.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index d62949ba..26091ea8 100644 --- a/archinstall.py +++ b/archinstall.py @@ -891,11 +891,11 @@ def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): def strap_in_base(*positionals, **kwargs): if args['aur-support']: args['packages'] += ' git' - x = sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs) - print('Handle:', x) - print('Exit code:', x.exit_code, x.exit_code == 0) - if x.exit_code == 0: - if sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args), *positionals, **kwargs).exit_code == 0: + if sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs).exit_code == 0: + x = sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args), *positionals, **kwargs) + print(x) + print(x.exit_code) + if x.exit_code == 0: return True return False -- cgit v1.2.3-54-g00ecf From a543c2033c1e27ffa57b9762c63f792d6c2b451f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:17:31 +0000 Subject: Enhanced spawn logic a bit --- archinstall.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 26091ea8..ec371dee 100644 --- a/archinstall.py +++ b/archinstall.py @@ -292,7 +292,14 @@ class sys_command():#Thread): if not self.pid: # Child process # Replace child process with our main process if not self.kwargs['emulate']: - os.execv(self.cmd[0], self.cmd) + try: + os.execv(self.cmd[0], self.cmd) + except FileNotFoundError: + self.status = 'done' + log(f"{self.cmd[0]} does not exist.", origin='spawn', level=2) + self.exit_code = 1 + return False + os.chdir(old_dir) poller = epoll() -- cgit v1.2.3-54-g00ecf From fcdafd22e1ca2a51f3f9583f68fd02f2786f13e2 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:26:00 +0000 Subject: debug --- archinstall.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index ec371dee..26603be8 100644 --- a/archinstall.py +++ b/archinstall.py @@ -885,6 +885,9 @@ def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals mount_boot(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs) return True +def re_rank_mirrors(top=10, *positionals, **kwargs) + o = simple_command('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist') + def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): ## TODO: replace wget with urllib.request (no point in calling syscommand) country_list = [] @@ -892,7 +895,7 @@ def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): country_list.append(f'country={country}') o = simple_command(f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(country_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist") o = simple_command("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist") - o = simple_command('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist') + re_rank_mirrors(top, *positionals, **kwargs) return True def strap_in_base(*positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 76731be748e0a45203d038430588faad3f62bd87 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:26:34 +0000 Subject: debugging --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 26603be8..be7f8d55 100644 --- a/archinstall.py +++ b/archinstall.py @@ -885,7 +885,7 @@ def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals mount_boot(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs) return True -def re_rank_mirrors(top=10, *positionals, **kwargs) +def re_rank_mirrors(top=10, *positionals, **kwargs): o = simple_command('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist') def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 673e607d4b3d8fab76f93e58bbcada6e9c9e7d50 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:30:01 +0000 Subject: debugging --- archinstall.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index be7f8d55..c9453bae 100644 --- a/archinstall.py +++ b/archinstall.py @@ -866,14 +866,14 @@ def mkfs_btrfs(drive='/dev/mapper/luksdev', *positionals, **kwargs): return True def mount_luksdev(where='/dev/mapper/luksdev', to='/mnt', *positionals, **kwargs): - o = simple_command('/usr/bin/mount | /usr/bin/grep /mnt') # /dev/dm-0 + o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt')) # /dev/dm-0 if len(o) <= 0: o = b''.join(sys_command('/usr/bin/mount /dev/mapper/luksdev /mnt')) return True def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs): os.makedirs('/mnt/boot', exist_ok=True) - o = simple_command('/usr/bin/mount | /usr/bin/grep /mnt/boot') # /dev/dm-0 + o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot')) # /dev/dm-0 if len(o) <= 0: o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}')) return True @@ -886,15 +886,15 @@ def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals return True def re_rank_mirrors(top=10, *positionals, **kwargs): - o = simple_command('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist') + o = b''.join(sys_command(('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist'))) def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): ## TODO: replace wget with urllib.request (no point in calling syscommand) country_list = [] for country in countries.split(','): country_list.append(f'country={country}') - o = simple_command(f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(country_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist") - o = simple_command("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist") + o = b''.join(sys_command((f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(country_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist"))) + o = b''.join(sys_command(("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist"))) re_rank_mirrors(top, *positionals, **kwargs) return True -- cgit v1.2.3-54-g00ecf From 7bdb2cfb923fdf13cd199ed0508fd3413976ce50 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:35:27 +0000 Subject: More error handling --- archinstall.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index c9453bae..d94932a4 100644 --- a/archinstall.py +++ b/archinstall.py @@ -886,7 +886,9 @@ def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals return True def re_rank_mirrors(top=10, *positionals, **kwargs): - o = b''.join(sys_command(('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist'))) + if sys_command(('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist')).exit_code == 0: + return True + return False def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): ## TODO: replace wget with urllib.request (no point in calling syscommand) @@ -895,7 +897,9 @@ def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): country_list.append(f'country={country}') o = b''.join(sys_command((f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(country_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist"))) o = b''.join(sys_command(("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist"))) - re_rank_mirrors(top, *positionals, **kwargs) + + if not re_rank_mirrors(top, *positionals, **kwargs) or not os.path.isfile('/etc/pacman.d/mirrorlist'): + o = b''.join(sys_command(("/usr/bin/mv /root/mirrorlist /etc/pacman.d/"))) return True def strap_in_base(*positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 161f35d9bd0fde0917341d67c7f0f362d595309f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:41:49 +0000 Subject: debugging --- archinstall.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index d94932a4..fa184dd4 100644 --- a/archinstall.py +++ b/archinstall.py @@ -873,9 +873,11 @@ def mount_luksdev(where='/dev/mapper/luksdev', to='/mnt', *positionals, **kwargs def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs): os.makedirs('/mnt/boot', exist_ok=True) - o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot')) # /dev/dm-0 + o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs)) # /dev/dm-0 + print('MOUNT STUFF:', o) if len(o) <= 0: - o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}')) + o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}', *positionals, **kwargs)) + print('MOUNT STUFF2:', o) return True def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 1c7077029b2cdce1d0e331c0d464a32ceb15533b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:46:27 +0000 Subject: debugging --- archinstall.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index fa184dd4..68d59ecb 100644 --- a/archinstall.py +++ b/archinstall.py @@ -873,11 +873,15 @@ def mount_luksdev(where='/dev/mapper/luksdev', to='/mnt', *positionals, **kwargs def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs): os.makedirs('/mnt/boot', exist_ok=True) - o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs)) # /dev/dm-0 - print('MOUNT STUFF:', o) - if len(o) <= 0: - o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}', *positionals, **kwargs)) - print('MOUNT STUFF2:', o) + #o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs)) # /dev/dm-0 + + check_mount = simple_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs).decode('UTF-8').strip() + if len(check_mount): + return False + + o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}', *positionals, **kwargs)) + print('MOUNT STUFF2:', o) + return True def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 2fbf1beeef6db67ae9c7e3f302362dd5a43943dc Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:47:45 +0000 Subject: debugging --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 68d59ecb..6d67faea 100644 --- a/archinstall.py +++ b/archinstall.py @@ -193,7 +193,7 @@ def simple_command(cmd, opts=None, *positionals, **kwargs): if not opts: opts = {} if 'debug' in opts: print('[!] {}'.format(cmd)) - handle = Popen(cmd, shell='True', stdout=PIPE, stderr=STDOUT, stdin=PIPE, **kwargs) + handle = Popen(cmd, shell='True', stdout=PIPE, stderr=STDOUT, stdin=PIPE) output = b'' while handle.poll() is None: data = handle.stdout.read() -- cgit v1.2.3-54-g00ecf From 4a1a98b2ed2692e2b95eff649ea40c4415fd05cf Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:52:10 +0000 Subject: debugging --- archinstall.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/archinstall.py b/archinstall.py index 6d67faea..c8a45ea2 100644 --- a/archinstall.py +++ b/archinstall.py @@ -866,22 +866,22 @@ def mkfs_btrfs(drive='/dev/mapper/luksdev', *positionals, **kwargs): return True def mount_luksdev(where='/dev/mapper/luksdev', to='/mnt', *positionals, **kwargs): - o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt')) # /dev/dm-0 - if len(o) <= 0: - o = b''.join(sys_command('/usr/bin/mount /dev/mapper/luksdev /mnt')) + check_mounted = simple_command('/usr/bin/mount | /usr/bin/grep /mnt', *positionals, **kwargs).decode('UTF-8').strip()# /dev/dm-0 + if len(check_mounted): + return False + + o = b''.join(sys_command('/usr/bin/mount /dev/mapper/luksdev /mnt', *positionals, **kwargs)) return True def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs): os.makedirs('/mnt/boot', exist_ok=True) #o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs)) # /dev/dm-0 - check_mount = simple_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs).decode('UTF-8').strip() - if len(check_mount): + check_mounted = simple_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs).decode('UTF-8').strip() + if len(check_mounted): return False o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}', *positionals, **kwargs)) - print('MOUNT STUFF2:', o) - return True def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From 8a5266d08751a0e1269ad0d812111bc3678c8959 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 00:54:42 +0000 Subject: debugging --- archinstall.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/archinstall.py b/archinstall.py index c8a45ea2..59e5cc81 100644 --- a/archinstall.py +++ b/archinstall.py @@ -624,19 +624,19 @@ def format_disk(drive='drive', start='start', end='size', emulate=False, *positi print(f'[N] Setting up {drive}.') # dd if=/dev/random of=args['drive'] bs=4096 status=progress # https://github.com/dcantrell/pyparted would be nice, but isn't officially in the repo's #SadPanda - if sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate).exit_code != 0: + if sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate, *positionals, **kwargs).exit_code != 0: return None - if sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate).exit_code != 0: + if sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate, *positionals, **kwargs).exit_code != 0: return None - if sys_command(f'/usr/bin/parted -s {drive} mkpart primary FAT32 1MiB {start}', emulate=emulate).exit_code != 0: + if sys_command(f'/usr/bin/parted -s {drive} mkpart primary FAT32 1MiB {start}', emulate=emulate, *positionals, **kwargs).exit_code != 0: return None - if sys_command(f'/usr/bin/parted -s {drive} name 1 "EFI"', emulate=emulate).exit_code != 0: + if sys_command(f'/usr/bin/parted -s {drive} name 1 "EFI"', emulate=emulate, *positionals, **kwargs).exit_code != 0: return None - if sys_command(f'/usr/bin/parted -s {drive} set 1 esp on', emulate=emulate).exit_code != 0: + if sys_command(f'/usr/bin/parted -s {drive} set 1 esp on', emulate=emulate, *positionals, **kwargs).exit_code != 0: return None - if sys_command(f'/usr/bin/parted -s {drive} set 1 boot on', emulate=emulate).exit_code != 0: + if sys_command(f'/usr/bin/parted -s {drive} set 1 boot on', emulate=emulate, *positionals, **kwargs).exit_code != 0: return None - if sys_command(f'/usr/bin/parted -s {drive} mkpart primary {start} {end}', emulate=emulate).exit_code != 0: + if sys_command(f'/usr/bin/parted -s {drive} mkpart primary {start} {end}', emulate=emulate, *positionals, **kwargs).exit_code != 0: return None # TODO: grab partitions after each parted/partition step instead of guessing which partiton is which later on. -- cgit v1.2.3-54-g00ecf From 86847d6dc17d83549be19b0cf54bda4711ceccec Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 01:05:04 +0000 Subject: Added extra error handling in case filesystem wasn't mounted porperly --- archinstall.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall.py b/archinstall.py index 59e5cc81..4f2dc19a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -612,6 +612,7 @@ def human_disk_info(drive): } def close_disks(): + o = simple_command('/usr/bin/umount -R /mnt/boot') o = simple_command('/usr/bin/umount -R /mnt') o = simple_command('/usr/bin/cryptsetup close /dev/mapper/luksdev') -- cgit v1.2.3-54-g00ecf From 6b570b62c2556932451f404f62cd31068dd1a3b0 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 01:06:23 +0000 Subject: Removed some debugging --- archinstall.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index 4f2dc19a..83193aa7 100644 --- a/archinstall.py +++ b/archinstall.py @@ -622,7 +622,6 @@ def format_disk(drive='drive', start='start', end='size', emulate=False, *positi end = args[end] if not drive: raise ValueError('Need to supply a drive path, for instance: /dev/sdx') - print(f'[N] Setting up {drive}.') # dd if=/dev/random of=args['drive'] bs=4096 status=progress # https://github.com/dcantrell/pyparted would be nice, but isn't officially in the repo's #SadPanda if sys_command(f'/usr/bin/parted -s {drive} mklabel gpt', emulate=emulate, *positionals, **kwargs).exit_code != 0: @@ -914,8 +913,6 @@ def strap_in_base(*positionals, **kwargs): args['packages'] += ' git' if sys_command('/usr/bin/pacman -Syy', *positionals, **kwargs).exit_code == 0: x = sys_command('/usr/bin/pacstrap /mnt base base-devel linux linux-firmware btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args), *positionals, **kwargs) - print(x) - print(x.exit_code) if x.exit_code == 0: return True return False @@ -1134,6 +1131,7 @@ if __name__ == '__main__': time.sleep(1) close_disks() + print(f'[N] Setting up {drive}.') format_disk('drive', start='start', end='size') refresh_partition_list('drive') -- cgit v1.2.3-54-g00ecf From b3e9505fab33af0e2420c98cea9b0b5dc9949677 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 19 Nov 2019 01:14:08 +0000 Subject: Cleaned up function calls a bit --- archinstall.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index 83193aa7..2b3cc302 100644 --- a/archinstall.py +++ b/archinstall.py @@ -892,20 +892,22 @@ def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals return True def re_rank_mirrors(top=10, *positionals, **kwargs): - if sys_command(('/usr/bin/rankmirrors -n {top} /root/mirrorlist > /etc/pacman.d/mirrorlist')).exit_code == 0: + if sys_command(('/usr/bin/rankmirrors -n {top} /etc/pacman.d/mirrorlist > /etc/pacman.d/mirrorlist')).exit_code == 0: return True return False -def filter_mirrors_by_country(countries, top=10, *positionals, **kwargs): +def filter_mirrors_by_country_list(countries, top=None, *positionals, **kwargs): ## TODO: replace wget with urllib.request (no point in calling syscommand) country_list = [] for country in countries.split(','): country_list.append(f'country={country}') o = b''.join(sys_command((f"/usr/bin/wget 'https://www.archlinux.org/mirrorlist/?{'&'.join(country_list)}&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' -O /root/mirrorlist"))) o = b''.join(sys_command(("/usr/bin/sed -i 's/#Server/Server/' /root/mirrorlist"))) + o = b''.join(sys_command(("/usr/bin/mv /root/mirrorlist /etc/pacman.d/"))) - if not re_rank_mirrors(top, *positionals, **kwargs) or not os.path.isfile('/etc/pacman.d/mirrorlist'): - o = b''.join(sys_command(("/usr/bin/mv /root/mirrorlist /etc/pacman.d/"))) + if top: + re_rank_mirrors(top, *positionals, **kwargs) or not os.path.isfile('/etc/pacman.d/mirrorlist') + return True def strap_in_base(*positionals, **kwargs): @@ -1167,7 +1169,7 @@ if __name__ == '__main__': if 'mirrors' in args and args['mirrors'] and 'country' in args and get_default_gateway_linux(): print('[N] Reordering mirrors.') - filter_mirrors_by_country(args['country']) + filter_mirrors_by_country_list([args['country']]) pre_conf = {} if 'pre' in instructions: -- cgit v1.2.3-54-g00ecf From 273c7d3402663c78f40ee361fe1de2eefa0bed98 Mon Sep 17 00:00:00 2001 From: jaybent <55739788+jaybent@users.noreply.github.com> Date: Fri, 22 Nov 2019 14:55:53 +0100 Subject: Create vmhost.json basic template for a barebone vmhost with i3 --- vmhost.json | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 vmhost.json diff --git a/vmhost.json b/vmhost.json new file mode 100644 index 00000000..0b2dabec --- /dev/null +++ b/vmhost.json @@ -0,0 +1,26 @@ +{ + "args" : { + "password" : "", + "_keyboard_layout" : "us", + "_editor" : "vim", + "_window_manager" : "i3", + "_window_manager_dependencies" : "xorg-server xorg-xrandr xorg-xinit xterm", + "_window_manager_utilities" : "slock xscreensaver terminus-font-otb gnu-free-fonts ttf-liberation xsel", + "_virtulization" : "qemu ovmf", + "_utils" : "git htop dhclient curl", + "post" : "don't reboot" + }, + "post" : { + "Install workstation packages": { + "pacman -Syy --noconfirm {_editor} {_utils} {_window_manager} {_window_manager_dependencies} {_window_manager_utilities} {_virtulization}" : {"pass-args" : true} + }, + "Setup virtulization" : { + "sh -c \"Description=\\\"Bridge for virtual machines\\\"\nInterface=br0\nConnection=bridge\nBindsToInterfaces=(eno1)\nIP=no\nExecUpPost=\\\"ip link set dev br0 address $(cat /sys/class/net/eno1/address); IP=dhcp; ip_set\\\"\nExecDownPre=\\\"IP=dhcp\\\"\n\n## Ignore (R)STP and immediately activate the bridge\nSkipForwardingDelay=yes\"" : null + }, + "Setup localization" : { + "sh -c \"echo 'setxkbmap us' >> /etc/X11/xinit/xinitrc\"" : null, + "sh -c \"echo 'KEYMAP={_keyboard_layout}\nFONT=lat9w-16' >> /etc/vconsole.conf\"" : {"pass-args" : true} + }, + "Configure desktop environment" : "i3" + } +} -- cgit v1.2.3-54-g00ecf From d1f1c9294f6c6ee52b70255cf41698d8107850a7 Mon Sep 17 00:00:00 2001 From: jaybent <55739788+jaybent@users.noreply.github.com> Date: Fri, 22 Nov 2019 15:15:56 +0100 Subject: Rename vmhost.json to deployments/vmhost.json --- deployments/vmhost.json | 26 ++++++++++++++++++++++++++ vmhost.json | 26 -------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 deployments/vmhost.json delete mode 100644 vmhost.json diff --git a/deployments/vmhost.json b/deployments/vmhost.json new file mode 100644 index 00000000..0b2dabec --- /dev/null +++ b/deployments/vmhost.json @@ -0,0 +1,26 @@ +{ + "args" : { + "password" : "", + "_keyboard_layout" : "us", + "_editor" : "vim", + "_window_manager" : "i3", + "_window_manager_dependencies" : "xorg-server xorg-xrandr xorg-xinit xterm", + "_window_manager_utilities" : "slock xscreensaver terminus-font-otb gnu-free-fonts ttf-liberation xsel", + "_virtulization" : "qemu ovmf", + "_utils" : "git htop dhclient curl", + "post" : "don't reboot" + }, + "post" : { + "Install workstation packages": { + "pacman -Syy --noconfirm {_editor} {_utils} {_window_manager} {_window_manager_dependencies} {_window_manager_utilities} {_virtulization}" : {"pass-args" : true} + }, + "Setup virtulization" : { + "sh -c \"Description=\\\"Bridge for virtual machines\\\"\nInterface=br0\nConnection=bridge\nBindsToInterfaces=(eno1)\nIP=no\nExecUpPost=\\\"ip link set dev br0 address $(cat /sys/class/net/eno1/address); IP=dhcp; ip_set\\\"\nExecDownPre=\\\"IP=dhcp\\\"\n\n## Ignore (R)STP and immediately activate the bridge\nSkipForwardingDelay=yes\"" : null + }, + "Setup localization" : { + "sh -c \"echo 'setxkbmap us' >> /etc/X11/xinit/xinitrc\"" : null, + "sh -c \"echo 'KEYMAP={_keyboard_layout}\nFONT=lat9w-16' >> /etc/vconsole.conf\"" : {"pass-args" : true} + }, + "Configure desktop environment" : "i3" + } +} diff --git a/vmhost.json b/vmhost.json deleted file mode 100644 index 0b2dabec..00000000 --- a/vmhost.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "args" : { - "password" : "", - "_keyboard_layout" : "us", - "_editor" : "vim", - "_window_manager" : "i3", - "_window_manager_dependencies" : "xorg-server xorg-xrandr xorg-xinit xterm", - "_window_manager_utilities" : "slock xscreensaver terminus-font-otb gnu-free-fonts ttf-liberation xsel", - "_virtulization" : "qemu ovmf", - "_utils" : "git htop dhclient curl", - "post" : "don't reboot" - }, - "post" : { - "Install workstation packages": { - "pacman -Syy --noconfirm {_editor} {_utils} {_window_manager} {_window_manager_dependencies} {_window_manager_utilities} {_virtulization}" : {"pass-args" : true} - }, - "Setup virtulization" : { - "sh -c \"Description=\\\"Bridge for virtual machines\\\"\nInterface=br0\nConnection=bridge\nBindsToInterfaces=(eno1)\nIP=no\nExecUpPost=\\\"ip link set dev br0 address $(cat /sys/class/net/eno1/address); IP=dhcp; ip_set\\\"\nExecDownPre=\\\"IP=dhcp\\\"\n\n## Ignore (R)STP and immediately activate the bridge\nSkipForwardingDelay=yes\"" : null - }, - "Setup localization" : { - "sh -c \"echo 'setxkbmap us' >> /etc/X11/xinit/xinitrc\"" : null, - "sh -c \"echo 'KEYMAP={_keyboard_layout}\nFONT=lat9w-16' >> /etc/vconsole.conf\"" : {"pass-args" : true} - }, - "Configure desktop environment" : "i3" - } -} -- cgit v1.2.3-54-g00ecf From 53a57300cc3e322d9e10ce30ad03a8b00d7a0009 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 23 Nov 2019 21:31:29 +0000 Subject: Fixed which statement. It's a builtin and not a /usr/bin command --- archinstall.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index 2b3cc302..783db347 100644 --- a/archinstall.py +++ b/archinstall.py @@ -7,7 +7,7 @@ from glob import glob from select import epoll, EPOLLIN, EPOLLHUP from socket import socket, inet_ntoa, AF_INET, AF_INET6, AF_PACKET from collections import OrderedDict as oDict -from subprocess import Popen, STDOUT, PIPE +from subprocess import Popen, STDOUT, PIPE, check_output from random import choice from string import ascii_uppercase, ascii_lowercase, digits from hashlib import sha512 @@ -235,9 +235,10 @@ class sys_command():#Thread): if not self.cmd[0][0] == '/': log('Worker command is not executed with absolute path, trying to find: {}'.format(self.cmd[0]), origin='spawn', level=5) - o = sys_command('/usr/bin/which {}'.format(self.cmd[0]), emulate=False, hide_from_log=True) + o = check_output(['which', self.cmd[0]]) + ##o = sys_command('sh which {}'.format(self.cmd[0]), emulate=False, hide_from_log=True) log('This is the binary {} for {}'.format(o.decode('UTF-8'), self.cmd[0]), origin='spawn', level=5) - self.cmd[0] = o.decode('UTF-8') + self.cmd[0] = o.decode('UTF-8').strip() if not os.path.isdir(self.exec_dir): os.makedirs(self.exec_dir) -- cgit v1.2.3-54-g00ecf From 5c306c3bccf80a74756d13c06da7baa2e91f5256 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 23 Nov 2019 21:36:07 +0000 Subject: Fixed which statement. It's a builtin and not a /usr/bin command --- archinstall.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 783db347..fa700ffe 100644 --- a/archinstall.py +++ b/archinstall.py @@ -235,8 +235,10 @@ class sys_command():#Thread): if not self.cmd[0][0] == '/': log('Worker command is not executed with absolute path, trying to find: {}'.format(self.cmd[0]), origin='spawn', level=5) - o = check_output(['which', self.cmd[0]]) - ##o = sys_command('sh which {}'.format(self.cmd[0]), emulate=False, hide_from_log=True) + x = Popen(f'/usr/bin/sh -c "which {self.cmd[0]}"', shell=True, stdout=PIPE) + while x.poll() is None: + pass + o = x.stdout.read() log('This is the binary {} for {}'.format(o.decode('UTF-8'), self.cmd[0]), origin='spawn', level=5) self.cmd[0] = o.decode('UTF-8').strip() -- cgit v1.2.3-54-g00ecf From 5e99895803accce102faeaac5544f76ed54a904d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 23 Nov 2019 21:38:30 +0000 Subject: Fixed which statement. It's a builtin and not a /usr/bin command --- archinstall.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index fa700ffe..c7b54d12 100644 --- a/archinstall.py +++ b/archinstall.py @@ -235,10 +235,7 @@ class sys_command():#Thread): if not self.cmd[0][0] == '/': log('Worker command is not executed with absolute path, trying to find: {}'.format(self.cmd[0]), origin='spawn', level=5) - x = Popen(f'/usr/bin/sh -c "which {self.cmd[0]}"', shell=True, stdout=PIPE) - while x.poll() is None: - pass - o = x.stdout.read() + o = check_output(['which', self.cmd[0]]) log('This is the binary {} for {}'.format(o.decode('UTF-8'), self.cmd[0]), origin='spawn', level=5) self.cmd[0] = o.decode('UTF-8').strip() -- cgit v1.2.3-54-g00ecf From bbb62bc8798bb874835dcbde711d09311b44ae3f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 23 Nov 2019 21:38:53 +0000 Subject: Fixed which statement. It's a builtin and not a /usr/bin command --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index c7b54d12..80ea9f07 100644 --- a/archinstall.py +++ b/archinstall.py @@ -235,7 +235,7 @@ class sys_command():#Thread): if not self.cmd[0][0] == '/': log('Worker command is not executed with absolute path, trying to find: {}'.format(self.cmd[0]), origin='spawn', level=5) - o = check_output(['which', self.cmd[0]]) + o = check_output(['/usr/bin/which', self.cmd[0]]) log('This is the binary {} for {}'.format(o.decode('UTF-8'), self.cmd[0]), origin='spawn', level=5) self.cmd[0] = o.decode('UTF-8').strip() -- cgit v1.2.3-54-g00ecf From 8ea7e831cbc1f8c2eb769d7d58f1e61b7c3c658e Mon Sep 17 00:00:00 2001 From: jaybent <55739788+jaybent@users.noreply.github.com> Date: Wed, 27 Nov 2019 15:26:32 +0100 Subject: Create gittea --- deployments/gittea | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 deployments/gittea diff --git a/deployments/gittea b/deployments/gittea new file mode 100644 index 00000000..28071bd8 --- /dev/null +++ b/deployments/gittea @@ -0,0 +1,13 @@ +{ + "args" : { + "password" : "", + "_editor" : "nano", + "_utils" : "openssh git curl dhclient", + "post" : "don't reboot" + }, + "post" : { + "Install workstation packages": { + "pacman -Syy --noconfirm {{_utils} {_editor}" : {"pass-args" : true} + } + } +} -- cgit v1.2.3-54-g00ecf From 96c63c9bc0be8a1f5fc003935af19923a4bc1e19 Mon Sep 17 00:00:00 2001 From: jaybent <55739788+jaybent@users.noreply.github.com> Date: Wed, 27 Nov 2019 15:28:48 +0100 Subject: Rename gittea to gitea --- deployments/gitea | 13 +++++++++++++ deployments/gittea | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 deployments/gitea delete mode 100644 deployments/gittea diff --git a/deployments/gitea b/deployments/gitea new file mode 100644 index 00000000..28071bd8 --- /dev/null +++ b/deployments/gitea @@ -0,0 +1,13 @@ +{ + "args" : { + "password" : "", + "_editor" : "nano", + "_utils" : "openssh git curl dhclient", + "post" : "don't reboot" + }, + "post" : { + "Install workstation packages": { + "pacman -Syy --noconfirm {{_utils} {_editor}" : {"pass-args" : true} + } + } +} diff --git a/deployments/gittea b/deployments/gittea deleted file mode 100644 index 28071bd8..00000000 --- a/deployments/gittea +++ /dev/null @@ -1,13 +0,0 @@ -{ - "args" : { - "password" : "", - "_editor" : "nano", - "_utils" : "openssh git curl dhclient", - "post" : "don't reboot" - }, - "post" : { - "Install workstation packages": { - "pacman -Syy --noconfirm {{_utils} {_editor}" : {"pass-args" : true} - } - } -} -- cgit v1.2.3-54-g00ecf From 97f8f642f7c33eee4f4f9260085f6f95790988d7 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 19:06:12 +0000 Subject: Fixes for transition --- archinstall.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index 80ea9f07..2b27f8be 100644 --- a/archinstall.py +++ b/archinstall.py @@ -410,7 +410,7 @@ class sys_command():#Thread): #self.callback(self, *self.args, **self.kwargs) -def get_drive_from_uuid(uuid): +def get_drive_from_uuid(drive): if len(harddrives) <= 0: raise ValueError("No hard drives to iterate in order to find: {}".format(uuid)) for drive in harddrives: @@ -1133,14 +1133,14 @@ if __name__ == '__main__': time.sleep(1) close_disks() - print(f'[N] Setting up {drive}.') + print(f'[N] Setting up {args["drive"]}.') format_disk('drive', start='start', end='size') refresh_partition_list('drive') print(f'Partitions: (Boot: {list(args["partitions"].keys())[0]})') if len(args['partitions']) <= 0: - print('[E] No partitions were created on {drive}'.format(**args), o) + print(f'[E] No partitions were created on {args["drive"]}', o) exit(1) if not args['rerun'] or args['ignore-rerun']: @@ -1150,7 +1150,7 @@ if __name__ == '__main__': # "--cipher sha512" breaks the shit. # TODO: --use-random instead of --use-urandom - print(f'[N] Adding encryption to {drive}{partitions["2"]}.') + print(f'[N] Adding encryption to {args["drive"]}{partitions["2"]}.') if not encrypt_partition('drive', '2', 'pwfile'): print('[E] Failed to setup disk encryption.', o) exit(1) -- cgit v1.2.3-54-g00ecf From 2f30f907f400a5a439bf61da1c435f3f31a95d43 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 19:07:18 +0000 Subject: Fixes for transition --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 2b27f8be..a4b73c56 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1144,7 +1144,7 @@ if __name__ == '__main__': exit(1) if not args['rerun'] or args['ignore-rerun']: - if not mkfs_fat32('drive', '1', *positionals, **kwargs): + if not mkfs_fat32('drive', '1'): print(f'[E] Could not setup {args["drive"]}{args["partitions"]["1"]}') exit(1) -- cgit v1.2.3-54-g00ecf From 20fdb8afeedd53e07f8f5ba18aee526486294f0d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 19:09:13 +0000 Subject: Fixes for transition --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index a4b73c56..e86d0763 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1150,7 +1150,7 @@ if __name__ == '__main__': # "--cipher sha512" breaks the shit. # TODO: --use-random instead of --use-urandom - print(f'[N] Adding encryption to {args["drive"]}{partitions["2"]}.') + print(f'[N] Adding encryption to {args["drive"]}{args["partitions"]["2"]}.') if not encrypt_partition('drive', '2', 'pwfile'): print('[E] Failed to setup disk encryption.', o) exit(1) -- cgit v1.2.3-54-g00ecf From f5c3bda6036d1d123a57b104011f725f644eab94 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 19:32:49 +0000 Subject: New feature: phone-home (post status POST request, optional.. Useful for debugging / verifying installs) --- archinstall.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index e86d0763..c6f6fea7 100644 --- a/archinstall.py +++ b/archinstall.py @@ -755,6 +755,7 @@ def setup_args_defaults(args, interactive=True): if not 'aur-support' in args: args['aur-support'] = True # Support adds yay (https://github.com/Jguer/yay) in installation steps. if not 'ignore-rerun' in args: args['ignore-rerun'] = False if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now + if not 'phone-home' in args: args['phone-home'] = False if not 'drive' in args: if interactive and len(harddrives): drives = sorted(list(harddrives.keys())) @@ -1218,7 +1219,9 @@ if __name__ == '__main__': if not args['rerun'] or rerun: print('[N] Straping in packages.') - strap_in_base() # TODO: check return here? we return based off pacstrap exit code.. Never tired it tho. + base_return_code = strap_in_base() # TODO: check return here? we return based off pacstrap exit code.. Never tired it tho. + else: + base_return_code = None if not os.path.isdir('/mnt/etc'): # TODO: This might not be the most long term stable thing to rely on... print('[E] Failed to strap in packages', o) @@ -1254,3 +1257,15 @@ if __name__ == '__main__': o = simple_command('/usr/bin/reboot now') else: print('Done. "umount -R /mnt; reboot" when you\'re done tinkering.') + + if args['phone-home']: + payload = json.dumps({"hostname": args['hostname'], + "done" : time(), + "profile": args['profile'], + "drive": args['drive'], + "base_status": base_return_code + }).encode('utf8') + request = urllib.request.Request(args['phone-home'], + data=payload, + headers={'content-type': 'application/json'}) + response = urllib.request.urlopen(request) \ No newline at end of file -- cgit v1.2.3-54-g00ecf From d7e5da5467268fa154d2b04beb0f1a8cf6f42079 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 20:38:03 +0000 Subject: Fixes for transition --- archinstall.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index c6f6fea7..79e4faf8 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1268,4 +1268,6 @@ if __name__ == '__main__': request = urllib.request.Request(args['phone-home'], data=payload, headers={'content-type': 'application/json'}) - response = urllib.request.urlopen(request) \ No newline at end of file + response = urllib.request.urlopen(request) + print(response) + time.sleep(2) \ No newline at end of file -- cgit v1.2.3-54-g00ecf From db24153dd7d610d86909b21c13698ca1675c823a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 21:02:53 +0000 Subject: Fixes for transition --- archinstall.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/archinstall.py b/archinstall.py index 79e4faf8..d4d55021 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1244,6 +1244,20 @@ if __name__ == '__main__': o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "userdel aibuilder"')) o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "rm -rf /home/aibuilder"')) + if args['phone-home']: + payload = json.dumps({"hostname": args['hostname'], + "done" : time.time(), + "profile": args['profile'], + "drive": args['drive'], + "base_status": base_return_code + }).encode('utf8') + request = urllib.request.Request(args['phone-home'], + data=payload, + headers={'content-type': 'application/json'}) + response = urllib.request.urlopen(request) + print(response) + time.sleep(2) + ## == Passwords # o = sys_command('arch-chroot /mnt usermod --password {} root'.format(args['password'])) # o = sys_command("arch-chroot /mnt sh -c 'echo {pin} | passwd --stdin root'".format(pin='"{pin}"'.format(**args, pin=args['password'])), echo=True) @@ -1257,17 +1271,3 @@ if __name__ == '__main__': o = simple_command('/usr/bin/reboot now') else: print('Done. "umount -R /mnt; reboot" when you\'re done tinkering.') - - if args['phone-home']: - payload = json.dumps({"hostname": args['hostname'], - "done" : time(), - "profile": args['profile'], - "drive": args['drive'], - "base_status": base_return_code - }).encode('utf8') - request = urllib.request.Request(args['phone-home'], - data=payload, - headers={'content-type': 'application/json'}) - response = urllib.request.urlopen(request) - print(response) - time.sleep(2) \ No newline at end of file -- cgit v1.2.3-54-g00ecf From bc154eacbe983231282d83e7ee5ae40c6128f026 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 21:22:16 +0000 Subject: Fixes for transition --- archinstall.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/archinstall.py b/archinstall.py index d4d55021..38856973 100644 --- a/archinstall.py +++ b/archinstall.py @@ -739,6 +739,15 @@ def merge_dicts(d1, d2, before=True, overwrite=False): def random_string(l): return ''.join(choice(ascii_uppercase + ascii_lowercase + digits) for i in range(l)) +def phone_home(url): + payload = json.dumps({"hostname": args['hostname'], + "done" : time.time(), + "profile": args['profile'], + "drive": args['drive'], + "base_status": base_return_code}).encode('utf8') + request = urllib.request.Request(url, data=payload, headers={'content-type': 'application/json'}) + response = urllib.request.urlopen(request) + def setup_args_defaults(args, interactive=True): if not 'size' in args: args['size'] = '100%' if not 'start' in args: args['start'] = '513MiB' @@ -752,6 +761,7 @@ def setup_args_defaults(args, interactive=True): if not 'profile' in args: args['profile'] = None if not 'profiles-path' in args: args['profiles-path'] = profiles_path if not 'rerun' in args: args['rerun'] = None + if not 'aur-keep' in args: args['aur-keep'] = False if not 'aur-support' in args: args['aur-support'] = True # Support adds yay (https://github.com/Jguer/yay) in installation steps. if not 'ignore-rerun' in args: args['ignore-rerun'] = False if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now @@ -1228,36 +1238,29 @@ if __name__ == '__main__': exit(1) if not args['rerun'] or rerun: + print('[N] Configuring base system.') configure_base_system() ## WORKAROUND: https://github.com/systemd/systemd/issues/13603#issuecomment-552246188 + print('[N] Setting up bootloader.') setup_bootloader() if args['aur-support']: print('[N] AUR support demanded, building "yay" before running POST steps.') add_AUR_support() print('[N] AUR support added. use "yay -Syy --noconfirm " to deploy in POST.') - + + print('[N] Running post installation steps.') run_post_install_steps() + time.sleep(2) - if args['aur-support']: + if args['aur-support'] and not args['aur-keep']: o = b''.join(sys_command('/usr/bin/sed -i \'s/%wheel ALL=(ALL) NO/# %wheel ALL=(ALL) NO/\' /mnt/etc/sudoers')) o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "userdel aibuilder"')) o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "rm -rf /home/aibuilder"')) if args['phone-home']: - payload = json.dumps({"hostname": args['hostname'], - "done" : time.time(), - "profile": args['profile'], - "drive": args['drive'], - "base_status": base_return_code - }).encode('utf8') - request = urllib.request.Request(args['phone-home'], - data=payload, - headers={'content-type': 'application/json'}) - response = urllib.request.urlopen(request) - print(response) - time.sleep(2) - + phone_home(args['phone-home']) + ## == Passwords # o = sys_command('arch-chroot /mnt usermod --password {} root'.format(args['password'])) # o = sys_command("arch-chroot /mnt sh -c 'echo {pin} | passwd --stdin root'".format(pin='"{pin}"'.format(**args, pin=args['password'])), echo=True) -- cgit v1.2.3-54-g00ecf From 198ba06c2749bae8f1e35a6e69a6ddf50708a17d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 22:16:06 +0000 Subject: Adding functions for issue #27 --- archinstall.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 38856973..e2d8f945 100644 --- a/archinstall.py +++ b/archinstall.py @@ -748,12 +748,32 @@ def phone_home(url): request = urllib.request.Request(url, data=payload, headers={'content-type': 'application/json'}) response = urllib.request.urlopen(request) +def get_external_ip(*positionals, **kwargs): + result = urllib.request.urlopen("https://hvornum.se/ip/?f=json").read().decode('UTF-8') + return json.loads(result)['ip'] + +def guess_country(*positionals, **kwargs): + # python-pygeoip + # geoip-database + result = None + GEOIP_DB = '/usr/share/GeoIP/GeoIP.dat' + if os.path.isfile(GEOIP_DB): + try: + import pygeoip + except: + return result + + gi = pygeoip.GeoIP(GEOIP_DB) + result = gi.country_name_by_addr(ip) + else: + log(f'Missing GeoIP database: {GEOIP_DB}', origin='guess_country', level=LOG_LEVELS.ERROR) + return result + def setup_args_defaults(args, interactive=True): if not 'size' in args: args['size'] = '100%' if not 'start' in args: args['start'] = '513MiB' if not 'pwfile' in args: args['pwfile'] = '/tmp/diskpw' if not 'hostname' in args: args['hostname'] = 'Archinstall' - if not 'country' in args: args['country'] = 'SE' # 'all' if we don't want country specific mirrors. if not 'packages' in args: args['packages'] = '' # extra packages other than default if not 'post' in args: args['post'] = 'reboot' if not 'password' in args: args['password'] = '0000' # Default disk passord, can be or a fixed string @@ -764,7 +784,6 @@ def setup_args_defaults(args, interactive=True): if not 'aur-keep' in args: args['aur-keep'] = False if not 'aur-support' in args: args['aur-support'] = True # Support adds yay (https://github.com/Jguer/yay) in installation steps. if not 'ignore-rerun' in args: args['ignore-rerun'] = False - if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now if not 'phone-home' in args: args['phone-home'] = False if not 'drive' in args: if interactive and len(harddrives): @@ -793,6 +812,15 @@ def setup_args_defaults(args, interactive=True): exit(1) args['drive'] = drive + + # Setup locales if we didn't get one. + if not 'country' in args: + country = None + if get_default_gateway_linux(): + country = guess_country(get_external_ip()) + args['country'] = 'all' if not country else country + if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now + return args def load_automatic_instructions(*positionals, **kwargs): -- cgit v1.2.3-54-g00ecf From d4c2fd61aad5010349767729eb913a75996de74c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 22:17:34 +0000 Subject: Adding debug --- archinstall.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index e2d8f945..548f9355 100644 --- a/archinstall.py +++ b/archinstall.py @@ -817,7 +817,10 @@ def setup_args_defaults(args, interactive=True): if not 'country' in args: country = None if get_default_gateway_linux(): - country = guess_country(get_external_ip()) + ip = get_external_ip() + print('IP:', ip) + country = guess_country(ip) + print('Country:', country) args['country'] = 'all' if not country else country if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now -- cgit v1.2.3-54-g00ecf From 9d984957feb3810461312f5cdeaf4b235c180ea9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 22:25:59 +0000 Subject: Missing parameter in guess_country() --- archinstall.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index 548f9355..33c39827 100644 --- a/archinstall.py +++ b/archinstall.py @@ -752,7 +752,7 @@ def get_external_ip(*positionals, **kwargs): result = urllib.request.urlopen("https://hvornum.se/ip/?f=json").read().decode('UTF-8') return json.loads(result)['ip'] -def guess_country(*positionals, **kwargs): +def guess_country(ip, *positionals, **kwargs): # python-pygeoip # geoip-database result = None @@ -761,6 +761,7 @@ def guess_country(*positionals, **kwargs): try: import pygeoip except: + ## TODO: Do a best-effort-guess based off the hostname given off the IP instead, if GoeIP doesn't exist. return result gi = pygeoip.GeoIP(GEOIP_DB) @@ -818,9 +819,7 @@ def setup_args_defaults(args, interactive=True): country = None if get_default_gateway_linux(): ip = get_external_ip() - print('IP:', ip) country = guess_country(ip) - print('Country:', country) args['country'] = 'all' if not country else country if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now -- cgit v1.2.3-54-g00ecf From bbcfd7a73da772dfeed3dd0d7a1265f4d6e5ac1d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 22:27:12 +0000 Subject: Country code instead of name --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 33c39827..50e59d04 100644 --- a/archinstall.py +++ b/archinstall.py @@ -765,7 +765,7 @@ def guess_country(ip, *positionals, **kwargs): return result gi = pygeoip.GeoIP(GEOIP_DB) - result = gi.country_name_by_addr(ip) + result = gi.country_code_by_addr(ip) else: log(f'Missing GeoIP database: {GEOIP_DB}', origin='guess_country', level=LOG_LEVELS.ERROR) return result -- cgit v1.2.3-54-g00ecf From c5d9be669dc6241f94c458bfd8b565b293549695 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 23:22:01 +0000 Subject: Update: mirrors are now re-ordered by default if a gateway and country is found --- archinstall.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 50e59d04..8def7adb 100644 --- a/archinstall.py +++ b/archinstall.py @@ -772,6 +772,7 @@ def guess_country(ip, *positionals, **kwargs): def setup_args_defaults(args, interactive=True): if not 'size' in args: args['size'] = '100%' + if not 'mirrors' in args: args['mirrors'] = True if not 'start' in args: args['start'] = '513MiB' if not 'pwfile' in args: args['pwfile'] = '/tmp/diskpw' if not 'hostname' in args: args['hostname'] = 'Archinstall' @@ -1178,7 +1179,7 @@ if __name__ == '__main__': format_disk('drive', start='start', end='size') refresh_partition_list('drive') - print(f'Partitions: (Boot: {list(args["partitions"].keys())[0]})') + print(f'[N] Partitions: {len(args["partitions"])} (Boot: {list(args["partitions"].keys())[0]})') if len(args['partitions']) <= 0: print(f'[E] No partitions were created on {args["drive"]}', o) -- cgit v1.2.3-54-g00ecf From 59994c1ffdcc916f782d50e248316790fec70974 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 27 Nov 2019 23:28:25 +0000 Subject: Fixes issue on line 944. list has no attribute 'split' --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 8def7adb..725d05ee 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1211,7 +1211,7 @@ if __name__ == '__main__': if 'mirrors' in args and args['mirrors'] and 'country' in args and get_default_gateway_linux(): print('[N] Reordering mirrors.') - filter_mirrors_by_country_list([args['country']]) + filter_mirrors_by_country_list(args['country']) pre_conf = {} if 'pre' in instructions: -- cgit v1.2.3-54-g00ecf From 93fb7f3ee51c8bcaee6dac9a2d31e0e7cf6b3c77 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 28 Nov 2019 00:10:54 +0000 Subject: Feature: #28 being worked on --- archinstall.py | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/archinstall.py b/archinstall.py index 725d05ee..06e51300 100644 --- a/archinstall.py +++ b/archinstall.py @@ -781,6 +781,7 @@ def setup_args_defaults(args, interactive=True): if not 'password' in args: args['password'] = '0000' # Default disk passord, can be or a fixed string if not 'default' in args: args['default'] = False if not 'profile' in args: args['profile'] = None + if not 'skip-encrypt' in args: args['skip-encrypt'] = False if not 'profiles-path' in args: args['profiles-path'] = profiles_path if not 'rerun' in args: args['rerun'] = None if not 'aur-keep' in args: args['aur-keep'] = False @@ -902,7 +903,7 @@ def encrypt_partition(drive, partition, keyfile='/tmp/diskpw', *positionals, **k return True def mkfs_btrfs(drive='/dev/mapper/luksdev', *positionals, **kwargs): - o = b''.join(sys_command('/usr/bin/mkfs.btrfs -f /dev/mapper/luksdev')) + o = b''.join(sys_command(f'/usr/bin/mkfs.btrfs -f {drive}')) if not b'UUID' in o: return False return True @@ -915,6 +916,17 @@ def mount_luksdev(where='/dev/mapper/luksdev', to='/mnt', *positionals, **kwargs o = b''.join(sys_command('/usr/bin/mount /dev/mapper/luksdev /mnt', *positionals, **kwargs)) return True +def mount_part(drive, partition, mountpoint='/mnt', *positionals, **kwargs): + os.makedirs(mountpoint, exist_ok=True) + #o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs)) # /dev/dm-0 + + check_mounted = simple_command(f'/usr/bin/mount | /usr/bin/grep {mountpoint}', *positionals, **kwargs).decode('UTF-8').strip() + if len(check_mounted): + return False + + o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}', *positionals, **kwargs)) + return True + def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs): os.makedirs('/mnt/boot', exist_ok=True) #o = b''.join(sys_command('/usr/bin/mount | /usr/bin/grep /mnt/boot', *positionals, **kwargs)) # /dev/dm-0 @@ -926,11 +938,13 @@ def mount_boot(drive, partition, mountpoint='/mnt/boot', *positionals, **kwargs) o = b''.join(sys_command(f'/usr/bin/mount {drive}{partition} {mountpoint}', *positionals, **kwargs)) return True -def mount_mountpoints(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs): +def mount_mountpoints(drive, bootpartition, mountpoint='/mnt', *positionals, **kwargs): drive = args[drive] - bootpartition = args['partitions'][bootpartition] - mount_luksdev(*positionals, **kwargs) - mount_boot(drive, bootpartition, mountpoint='/mnt/boot', *positionals, **kwargs) + if args['skip-encrypt']: + mount_part(drive, args['partitions']["2"], mountpoint, *positionals, **kwargs) + else: + mount_luksdev(*positionals, **kwargs) + mount_boot(drive, args['partitions'][bootpartition], mountpoint=f'{mountpoint}/boot', *positionals, **kwargs) return True def re_rank_mirrors(top=10, *positionals, **kwargs): @@ -1190,20 +1204,26 @@ if __name__ == '__main__': print(f'[E] Could not setup {args["drive"]}{args["partitions"]["1"]}') exit(1) - # "--cipher sha512" breaks the shit. - # TODO: --use-random instead of --use-urandom - print(f'[N] Adding encryption to {args["drive"]}{args["partitions"]["2"]}.') - if not encrypt_partition('drive', '2', 'pwfile'): - print('[E] Failed to setup disk encryption.', o) - exit(1) + if not args['skip-encrypt']: + # "--cipher sha512" breaks the shit. + # TODO: --use-random instead of --use-urandom + print(f'[N] Adding encryption to {args["drive"]}{args["partitions"]["2"]}.') + if not encrypt_partition('drive', '2', 'pwfile'): + print('[E] Failed to setup disk encryption.', o) + exit(1) - if not mount_luktsdev('drive', '2', 'pwfile'): - print('[E] Could not open encrypted device.', o) - exit(1) + if not args['skip-encrypt']: + if not mount_luktsdev('drive', '2', 'pwfile'): + print('[E] Could not open encrypted device.', o) + exit(1) if not args['rerun'] or args['ignore-rerun']: print(f'[N] Creating btrfs filesystem inside {args["drive"]}{args["partitions"]["2"]}') - if not mkfs_btrfs(): + + on_part = '/dev/mapper/luksdev' + if args['skip-encrypt']: + on_part = f'{args["drive"]}/{args["partitions"]["2"]}' + if not mkfs_btrfs(on_part): print('[E] Could not setup btrfs filesystem.', o) exit(1) -- cgit v1.2.3-54-g00ecf From 375976b7ce75c6309ddb06c5bd29d781dbb54fd6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 28 Nov 2019 00:14:53 +0000 Subject: Debugging --- archinstall.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index 06e51300..c4b21b9d 100644 --- a/archinstall.py +++ b/archinstall.py @@ -903,7 +903,9 @@ def encrypt_partition(drive, partition, keyfile='/tmp/diskpw', *positionals, **k return True def mkfs_btrfs(drive='/dev/mapper/luksdev', *positionals, **kwargs): + print('On drive:', drive) o = b''.join(sys_command(f'/usr/bin/mkfs.btrfs -f {drive}')) + print(o) if not b'UUID' in o: return False return True @@ -1179,9 +1181,10 @@ if __name__ == '__main__': # with open(args['pwfile'], 'r') as pw: # PIN = pw.read().strip() - print() - print('[!] Disk PASSWORD is: {}'.format(args['password'])) - print() + if not args['skip-encrypt']: + print() + print('[!] Disk PASSWORD is: {}'.format(args['password'])) + print() if not args['rerun'] or args['ignore-rerun']: for i in range(5, 0, -1): @@ -1224,7 +1227,7 @@ if __name__ == '__main__': if args['skip-encrypt']: on_part = f'{args["drive"]}/{args["partitions"]["2"]}' if not mkfs_btrfs(on_part): - print('[E] Could not setup btrfs filesystem.', o) + print('[E] Could not setup btrfs filesystem.') exit(1) mount_mountpoints('drive', '1') -- cgit v1.2.3-54-g00ecf From 0dbd44e253756b4604bf20ab8c87b1b251b938c4 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 28 Nov 2019 00:15:31 +0000 Subject: Debugging --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index c4b21b9d..a2e65312 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1225,7 +1225,7 @@ if __name__ == '__main__': on_part = '/dev/mapper/luksdev' if args['skip-encrypt']: - on_part = f'{args["drive"]}/{args["partitions"]["2"]}' + on_part = f'{args["drive"]}{args["partitions"]["2"]}' if not mkfs_btrfs(on_part): print('[E] Could not setup btrfs filesystem.') exit(1) -- cgit v1.2.3-54-g00ecf From 8cc90ad8741bef833858470d4388544489f98d9e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 28 Nov 2019 00:16:05 +0000 Subject: Feature: #28 - Testing phase --- archinstall.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index a2e65312..899566c8 100644 --- a/archinstall.py +++ b/archinstall.py @@ -903,9 +903,7 @@ def encrypt_partition(drive, partition, keyfile='/tmp/diskpw', *positionals, **k return True def mkfs_btrfs(drive='/dev/mapper/luksdev', *positionals, **kwargs): - print('On drive:', drive) o = b''.join(sys_command(f'/usr/bin/mkfs.btrfs -f {drive}')) - print(o) if not b'UUID' in o: return False return True -- cgit v1.2.3-54-g00ecf From 1aec07f82944978ff473336a9919e8b72b1da94d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 28 Nov 2019 00:23:55 +0000 Subject: Feature: #28 - Fixing the booatloader config when disk ain't encrypted --- archinstall.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 899566c8..1cc42255 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1017,7 +1017,10 @@ def setup_bootloader(*positionals, **kwargs): entry.write('title Arch Linux\n') entry.write('linux /vmlinuz-linux\n') entry.write('initrd /initramfs-linux.img\n') - entry.write('options cryptdevice=UUID={UUID}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n'.format(UUID=UUID)) + if args['skip-encrypt']: + entry.write('options root=PARTUUID={UUID} rw intel_pstate=no_hwp\n'.format(UUID=UUID)) + else: + entry.write('options cryptdevice=UUID={UUID}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n'.format(UUID=UUID)) return True -- cgit v1.2.3-54-g00ecf From 70c811e2bcc5a5492b230021c8de41b0c2368956 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 28 Nov 2019 00:50:05 +0000 Subject: Feature: #28 - Fixing the booatloader config when disk ain't encrypted --- archinstall.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 1cc42255..e0c42a04 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1012,14 +1012,16 @@ def setup_bootloader(*positionals, **kwargs): ## For some reason, blkid and /dev/disk/by-uuid are not getting along well. ## And blkid is wrong in terms of LUKS. #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip() - UUID = simple_command(f"ls -l /dev/disk/by-uuid/ | grep {os.path.basename(args['drive'])}{args['partitions']['2']} | awk '{{print $9}}'").decode('UTF-8').strip() with open('/mnt/boot/loader/entries/arch.conf', 'w') as entry: entry.write('title Arch Linux\n') entry.write('linux /vmlinuz-linux\n') entry.write('initrd /initramfs-linux.img\n') if args['skip-encrypt']: + ## NOTE: We could use /dev/disk/by-partuuid but blkid does the same and a lot cleaner + UUID = simple_command(f"blkid -s PARTUUID -o value /dev/{os.path.basename(args['drive'])}{args['partitions']['2']}").decode('UTF-8').strip() entry.write('options root=PARTUUID={UUID} rw intel_pstate=no_hwp\n'.format(UUID=UUID)) else: + UUID = simple_command(f"ls -l /dev/disk/by-uuid/ | grep {os.path.basename(args['drive'])}{args['partitions']['2']} | awk '{{print $9}}'").decode('UTF-8').strip() entry.write('options cryptdevice=UUID={UUID}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n'.format(UUID=UUID)) return True -- cgit v1.2.3-54-g00ecf From 72e6eb4567d0287b233ab758b30607d54f29a80a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 28 Nov 2019 00:56:17 +0000 Subject: Feature: #28 - Tested and works --- archinstall.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index e0c42a04..a7d46211 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1184,10 +1184,12 @@ if __name__ == '__main__': # with open(args['pwfile'], 'r') as pw: # PIN = pw.read().strip() + print() if not args['skip-encrypt']: - print() - print('[!] Disk PASSWORD is: {}'.format(args['password'])) - print() + print('[!] Disk & root PASSWORD is: {}'.format(args['password'])) + else: + print('[!] root PASSWORD is: {}'.format(args['password'])) + print() if not args['rerun'] or args['ignore-rerun']: for i in range(5, 0, -1): -- cgit v1.2.3-54-g00ecf From 4652a3eee483fa4e565a48c2b6ed531b8c46ffc4 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 12:47:17 +0100 Subject: Fixing #24 and #12 --- archinstall.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/archinstall.py b/archinstall.py index a7d46211..5dd57667 100644 --- a/archinstall.py +++ b/archinstall.py @@ -365,6 +365,9 @@ class sys_command():#Thread): else: self.exit_code = 0 + if 'ignore_error' in self.kwargs: + self.exit_code = 0 + if self.exit_code != 0: log(f"{self.cmd[0]} did not exit gracefully, exit code {self.exit_code}.", origin='spawn', level=3) log(self.trace_log.decode('UTF-8'), origin='spawn', level=3) @@ -1102,7 +1105,7 @@ def run_post_install_steps(*positionals, **kwargs): o = simple_command("cd /mnt; mount -t proc /proc proc") o = simple_command("cd /mnt; mount --make-rslave --rbind /sys sys") o = simple_command("cd /mnt; mount --make-rslave --rbind /dev dev") - o = simple_command('chroot /mnt /bin/bash -c "{c}"'.format(c=command), opts=opts) + o = simple_command('chroot /mnt /bin/bash -c "{c}"'.format(c=command), events=opts) o = simple_command("cd /mnt; umount -R dev") o = simple_command("cd /mnt; umount -R sys") o = simple_command("cd /mnt; umount -R proc") @@ -1124,16 +1127,16 @@ def run_post_install_steps(*positionals, **kwargs): ## " login" followed by "Passwodd" in case it's been set in a previous step.. usually this shouldn't be nessecary ## since we set the password as the last step. And then the command itself which will be executed by looking for: ## [root@ ~]# - o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', opts={'triggers' : { - bytes(f'login:', 'UTF-8') : b'root\n', - #b'Password:' : bytes(args['password']+'\n', 'UTF-8'), - bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), - }, **opts})) + o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', events={ + bytes(f'login:', 'UTF-8') : b'root\n', + #b'Password:' : bytes(args['password']+'\n', 'UTF-8'), + bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), + }, **opts)) ## Not needed anymore: And cleanup after out selves.. Don't want to leave any residue.. # os.remove('/mnt/etc/systemd/system/console-getty.service.d/override.conf') else: - o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt --machine temporary {c}'.format(c=command), opts=opts)) + o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt --machine temporary {c}'.format(c=command), **opts)) if type(conf[title][raw_command]) == bytes and len(conf[title][raw_command]) and not conf[title][raw_command] in o: print('[W] Post install command failed: {}'.format(o.decode('UTF-8'))) #print(o) -- cgit v1.2.3-54-g00ecf From c8f31bd344187d2d1b6c4249c6ce6b9ef28c9b63 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 12:55:38 +0100 Subject: Fixing #18 and #12 --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 5dd57667..268787ec 100644 --- a/archinstall.py +++ b/archinstall.py @@ -365,7 +365,7 @@ class sys_command():#Thread): else: self.exit_code = 0 - if 'ignore_error' in self.kwargs: + if 'ignore_errors' in self.kwargs: self.exit_code = 0 if self.exit_code != 0: -- cgit v1.2.3-54-g00ecf From d89bacdf9f187c1737439ccdef53254fc84749c5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 12:58:58 +0100 Subject: Adding tests to default, will change this to a test template later --- deployments/default.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/deployments/default.json b/deployments/default.json index 5deded3e..95870c6c 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -2,5 +2,14 @@ "args" : { "password" : "", "post" : "reboot" + }, + "post" : { + "test exit codes" : { + "exit 1" : {"ignore_errors" : true}, + "echo 'test1'; read moo; echo 'test2'; read mooo" : {"events" : { + "test1" : "something", + "test2" : "something" + }, "boot" : true} + } } } -- cgit v1.2.3-54-g00ecf 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 From 62ecb7ccfa43150d756961c1e5ac45a9dd805cfe Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:26:35 +0100 Subject: Fixed instruction loading --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 2a51a35e..9d96d439 100644 --- a/archinstall.py +++ b/archinstall.py @@ -720,7 +720,7 @@ def get_instructions(target, *positionals, **kwargs): else: isntructions = get_local_instructions(target, *positionals) - if type(instructions) in (dict, oDict): + if type(instructions) not in (dict, oDict,): try: instructions = json.loads(instructions, object_pairs_hook=oDict) except: -- cgit v1.2.3-54-g00ecf From d84f4e2bf9bbba01cbab0e9c569af4e054b2d73a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:32:48 +0100 Subject: Fixed an issue where --profile didn't override the network deploy. --- archinstall.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/archinstall.py b/archinstall.py index 9d96d439..ce76ccba 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1158,26 +1158,27 @@ if __name__ == '__main__': args = setup_args_defaults(args) ## == If we got networking, - # Try fetching instructions for this box and execute them. - instructions = load_automatic_instructions() + # Try fetching instructions for this box unless a specific profile was given, and execute them. + if args['profile'] is None: + instructions = load_automatic_instructions() - if args['profile'] and not args['default']: + elif args['profile'] and not args['default']: instructions = get_instructions(args['profile']) if len(instructions) <= 0: print('[E] No instructions by the name of {} was found.'.format(args['profile'])) print(' Installation won\'t continue until a valid profile is given.') print(' (this is because --profile was given and a --default is not given)') exit(1) - else: - first = True - while not args['default'] and not args['profile'] and len(instructions) <= 0: - profile = input('What template do you want to install: ') - instructions = get_instructions(profile) - if first and len(instructions) <= 0: - print('[E] No instructions by the name of {} was found.'.format(profile)) - print(' Installation won\'t continue until a valid profile is given.') - print(' (this is because --default is not instructed and no --profile given)') - first = False + + first = True + while not args['default'] and not args['profile'] and len(instructions) <= 0: + profile = input('What template do you want to install: ') + instructions = get_instructions(profile) + if first and len(instructions) <= 0: + print('[E] No instructions by the name of {} was found.'.format(profile)) + print(' Installation won\'t continue until a valid profile is given.') + print(' (this is because --default is not instructed and no --profile given)') + first = False # TODO: Might not need to return anything here, passed by reference? instructions = merge_in_includes(instructions) -- cgit v1.2.3-54-g00ecf From 670afabf9f3d2a3fce43ceb4d134af89b42442ba Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:39:29 +0100 Subject: Moved disk selection to after profile fetching. Should not need to select a disk if it's specified in the template --- archinstall.py | 56 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/archinstall.py b/archinstall.py index ce76ccba..06c6aa63 100644 --- a/archinstall.py +++ b/archinstall.py @@ -799,33 +799,6 @@ def setup_args_defaults(args, interactive=True): if not 'aur-support' in args: args['aur-support'] = True # Support adds yay (https://github.com/Jguer/yay) in installation steps. if not 'ignore-rerun' in args: args['ignore-rerun'] = False if not 'phone-home' in args: args['phone-home'] = False - if not 'drive' in args: - if interactive and len(harddrives): - drives = sorted(list(harddrives.keys())) - if len(drives) > 1 and 'force' not in args and ('default' in args and 'first-drive' not in args): - for index, drive in enumerate(drives): - print(f"{index}: {drive} ({harddrives[drive]['size'], harddrives[drive]['fstype'], harddrives[drive]['label']})") - drive = input('Select one of the above disks (by number): ') - if not drive.isdigit(): - raise KeyError("Multiple disks found, --drive=/dev/X not specified (or --force/--first-drive)") - drives = [drives[int(drive)]] # Make sure only the selected drive is in the list of options - args['drive'] = drives[0] # First drive found - else: - args['drive'] = None - rerun = args['ignore-rerun'] - - if args['drive'] and args['drive'][0] != '/': - ## Remap the selected UUID to the device to be formatted. - drive = get_drive_from_uuid(args['drive']) - if not drive: - print(f'[N] Could not map UUID "{args["drive"]}" to a device. Trying to match via PARTUUID instead!') - - drive = get_drive_from_part_uuid(args['drive']) - if not drive: - print(f'[E] Could not map UUID "{args["drive"]}" to a device. Aborting!') - exit(1) - - args['drive'] = drive # Setup locales if we didn't get one. if not 'country' in args: @@ -1061,6 +1034,7 @@ def run_post_install_steps(*positionals, **kwargs): update_git(conf['git-branch']) del(conf['git-branch']) + rerun = args['ignore-rerun'] for title in conf: if args['rerun'] and args['rerun'] != title and not rerun: continue @@ -1184,6 +1158,34 @@ if __name__ == '__main__': instructions = merge_in_includes(instructions) cleanup_args() + ## If no drive was found in args, select one. + if not 'drive' in args: + if interactive and len(harddrives): + drives = sorted(list(harddrives.keys())) + if len(drives) > 1 and 'force' not in args and ('default' in args and 'first-drive' not in args): + for index, drive in enumerate(drives): + print(f"{index}: {drive} ({harddrives[drive]['size'], harddrives[drive]['fstype'], harddrives[drive]['label']})") + drive = input('Select one of the above disks (by number): ') + if not drive.isdigit(): + raise KeyError("Multiple disks found, --drive=/dev/X not specified (or --force/--first-drive)") + drives = [drives[int(drive)]] # Make sure only the selected drive is in the list of options + args['drive'] = drives[0] # First drive found + else: + args['drive'] = None + + if args['drive'] and args['drive'][0] != '/': + ## Remap the selected UUID to the device to be formatted. + drive = get_drive_from_uuid(args['drive']) + if not drive: + print(f'[N] Could not map UUID "{args["drive"]}" to a device. Trying to match via PARTUUID instead!') + + drive = get_drive_from_part_uuid(args['drive']) + if not drive: + print(f'[E] Could not map UUID "{args["drive"]}" to a device. Aborting!') + exit(1) + + args['drive'] = drive + print(json.dumps(args, indent=4)) if args['default'] and not 'force' in args: if(input('Are these settings OK? (No return beyond this point) N/y: ').lower() != 'y'): -- cgit v1.2.3-54-g00ecf From 53669d63c9e01c2ed6e47d718b6983442e57fb6d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:40:47 +0100 Subject: Removing interactive since it's redundant --- archinstall.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 06c6aa63..c0018858 100644 --- a/archinstall.py +++ b/archinstall.py @@ -781,7 +781,7 @@ def guess_country(ip, *positionals, **kwargs): log(f'Missing GeoIP database: {GEOIP_DB}', origin='guess_country', level=LOG_LEVELS.ERROR) return result -def setup_args_defaults(args, interactive=True): +def setup_args_defaults(args, *positionals, **kwargs): if not 'size' in args: args['size'] = '100%' if not 'mirrors' in args: args['mirrors'] = True if not 'start' in args: args['start'] = '513MiB' @@ -1160,7 +1160,7 @@ if __name__ == '__main__': ## If no drive was found in args, select one. if not 'drive' in args: - if interactive and len(harddrives): + if len(harddrives): drives = sorted(list(harddrives.keys())) if len(drives) > 1 and 'force' not in args and ('default' in args and 'first-drive' not in args): for index, drive in enumerate(drives): -- cgit v1.2.3-54-g00ecf From ef117744cbebc98ba6aed31e4b47de0e73ae1349 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:48:51 +0100 Subject: Fixing #29. --default is now renamed to --minimal. --unattended has been added to skip steps (equal to --force). Will add a --default shortcut which will point towards the profile 'default.json' --- archinstall.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/archinstall.py b/archinstall.py index c0018858..d514b283 100644 --- a/archinstall.py +++ b/archinstall.py @@ -553,7 +553,11 @@ def disk_info(drive, *positionals, **kwargs): def cleanup_args(): for key in args: - if args[key] == '': args[key] = input(f'Enter a value for {key}: ') + if args[key] == '': + if not args['unattended']: + args[key] = input(f'Enter a value for {key}: ') + else: + args[key] = random_string(32) elif args[key] == '': args[key] = random_string(32) elif args[key] == '': args[key] = gen_yubikey_password() @@ -790,7 +794,8 @@ def setup_args_defaults(args, *positionals, **kwargs): if not 'packages' in args: args['packages'] = '' # extra packages other than default if not 'post' in args: args['post'] = 'reboot' if not 'password' in args: args['password'] = '0000' # Default disk passord, can be or a fixed string - if not 'default' in args: args['default'] = False + if not 'minimal' in args: args['minimal'] = False + if not 'unattended' in args: args['unattended'] = False if not 'profile' in args: args['profile'] = None if not 'skip-encrypt' in args: args['skip-encrypt'] = False if not 'profiles-path' in args: args['profiles-path'] = profiles_path @@ -1136,7 +1141,7 @@ if __name__ == '__main__': if args['profile'] is None: instructions = load_automatic_instructions() - elif args['profile'] and not args['default']: + elif args['profile'] and not args['minimal']: instructions = get_instructions(args['profile']) if len(instructions) <= 0: print('[E] No instructions by the name of {} was found.'.format(args['profile'])) @@ -1145,7 +1150,7 @@ if __name__ == '__main__': exit(1) first = True - while not args['default'] and not args['profile'] and len(instructions) <= 0: + while not args['minimal'] and not args['profile'] and len(instructions) <= 0: profile = input('What template do you want to install: ') instructions = get_instructions(profile) if first and len(instructions) <= 0: @@ -1162,7 +1167,7 @@ if __name__ == '__main__': if not 'drive' in args: if len(harddrives): drives = sorted(list(harddrives.keys())) - if len(drives) > 1 and 'force' not in args and ('default' in args and 'first-drive' not in args): + if len(drives) > 1 and 'force' not in args and not 'unattended' in args and ('minimal' in args and 'first-drive' not in args): for index, drive in enumerate(drives): print(f"{index}: {drive} ({harddrives[drive]['size'], harddrives[drive]['fstype'], harddrives[drive]['label']})") drive = input('Select one of the above disks (by number): ') @@ -1187,7 +1192,7 @@ if __name__ == '__main__': args['drive'] = drive print(json.dumps(args, indent=4)) - if args['default'] and not 'force' in args: + if args['minimal'] and not 'force' in args and not 'unattended' in args: if(input('Are these settings OK? (No return beyond this point) N/y: ').lower() != 'y'): exit(1) -- cgit v1.2.3-54-g00ecf From 30e45d57a1829196fdbf1ba8eaaafa16f8e9996a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:54:17 +0100 Subject: Added --minimal to skip profile lookups completely. #29 --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index d514b283..8437575c 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1138,7 +1138,7 @@ if __name__ == '__main__': ## == If we got networking, # Try fetching instructions for this box unless a specific profile was given, and execute them. - if args['profile'] is None: + if args['profile'] is None and not args['minimal']: instructions = load_automatic_instructions() elif args['profile'] and not args['minimal']: -- cgit v1.2.3-54-g00ecf From a66c2436ee67532e7625d88e5e7f293364e39fe0 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 13:56:42 +0100 Subject: Added debug --- archinstall.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archinstall.py b/archinstall.py index 8437575c..ec16e7ce 100644 --- a/archinstall.py +++ b/archinstall.py @@ -811,6 +811,8 @@ def setup_args_defaults(args, *positionals, **kwargs): if get_default_gateway_linux(): ip = get_external_ip() country = guess_country(ip) + print(ip) + print(country) args['country'] = 'all' if not country else country if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now -- cgit v1.2.3-54-g00ecf From 405117565054db73dde6ffd519873060a8564eaa Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 14:55:13 +0100 Subject: Updated README to reflect parameter changes. --- README.md | 9 +++++++-- archinstall.py | 2 -- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2682979e..39a40bd8 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,9 @@ More options for the built ISO: --drive= Which drive to install arch on, if absent, the first disk under /dev/ is used + + --minimal + Starts a minimal installation, and skips looking for profiles. --size=100% (Default) Sets the size of the root filesystem (btrfs) @@ -75,8 +78,10 @@ More options for the built ISO: --hostname=Arcinstall (Default) Sets the hostname of the box - --country=SE (Default) + --country=all (Default) Default mirror allocation for fetching packages. + If network is found, archinstall will try to attempt and guess which country the + install originates from, basing it off GeoIP off your public IP (uses https://hvornu.se/ip/ for lookups) --packages='' (Default) Which additional packages to install, defaults to none. @@ -88,7 +93,7 @@ More options for the built ISO: --post=reboot (Default) After a successful install, reboots into the system. Use --post=stay to not reboot. - --default + --unattended This parameter causes the installation script to install arch unattended on the first disk --profile= diff --git a/archinstall.py b/archinstall.py index ec16e7ce..8437575c 100644 --- a/archinstall.py +++ b/archinstall.py @@ -811,8 +811,6 @@ def setup_args_defaults(args, *positionals, **kwargs): if get_default_gateway_linux(): ip = get_external_ip() country = guess_country(ip) - print(ip) - print(country) args['country'] = 'all' if not country else country if not 'localtime' in args: args['localtime'] = 'Europe/Stockholm' if args['country'] == 'SE' else 'GMT+0' # TODO: Arbitrary for now -- cgit v1.2.3-54-g00ecf From 2c65800d2984c31553e9de388eaecc9b72f2e92a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 14:58:18 +0100 Subject: Changing detault for tests --- deployments/default.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/default.json b/deployments/default.json index 95870c6c..1eeac949 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -1,7 +1,7 @@ { "args" : { "password" : "", - "post" : "reboot" + "post" : "stay" }, "post" : { "test exit codes" : { -- cgit v1.2.3-54-g00ecf From 56ad7efe845c19c39aa078fb427228e12ae8e559 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:09:05 +0100 Subject: One step in fixing #20. User-given parameters override template. And next is reworking the inheritance structure of the templates --- archinstall.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/archinstall.py b/archinstall.py index 8437575c..5ce575c0 100644 --- a/archinstall.py +++ b/archinstall.py @@ -28,18 +28,6 @@ harddrives = oDict() commandlog = [] worker_history = oDict() instructions = oDict() -args = {} -positionals = [] -for arg in sys.argv[1:]: - if '--' == arg[:2]: - if '=' in arg: - key, val = [x.strip() for x in arg[2:].split('=')] - else: - key, val = arg[2:], True - args[key] = val - else: - positionals.append(arg) - import logging from systemd.journal import JournalHandler @@ -1134,7 +1122,17 @@ if __name__ == '__main__': ## Setup some defaults # (in case no command-line parameters or netdeploy-params were given) - args = setup_args_defaults(args) + args = setup_args_defaults() + positionals = [] + for arg in sys.argv[1:]: + if '--' == arg[:2]: + if '=' in arg: + key, val = [x.strip() for x in arg[2:].split('=')] + else: + key, val = arg[2:], True + args[key] = val + else: + positionals.append(arg) ## == If we got networking, # Try fetching instructions for this box unless a specific profile was given, and execute them. -- cgit v1.2.3-54-g00ecf From 2d9606777f24078b86d9e2e25efe0181b3e8c51c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:09:54 +0100 Subject: Forgot to setup args --- archinstall.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 5ce575c0..d5ff48a9 100644 --- a/archinstall.py +++ b/archinstall.py @@ -28,6 +28,7 @@ harddrives = oDict() commandlog = [] worker_history = oDict() instructions = oDict() +args = {} import logging from systemd.journal import JournalHandler @@ -1122,7 +1123,7 @@ if __name__ == '__main__': ## Setup some defaults # (in case no command-line parameters or netdeploy-params were given) - args = setup_args_defaults() + args = setup_args_defaults(args) positionals = [] for arg in sys.argv[1:]: if '--' == arg[:2]: -- cgit v1.2.3-54-g00ecf From 6faeeb0bd302ae5f853ab63e46bf7b2c9ba2b544 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:10:49 +0100 Subject: Don't update git until we have some args --- archinstall.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index d5ff48a9..8075e6f4 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1118,9 +1118,6 @@ def run_post_install_steps(*positionals, **kwargs): #print(o) if __name__ == '__main__': - update_git() # Breaks and restarts the script if an update was found. - update_drive_list() - ## Setup some defaults # (in case no command-line parameters or netdeploy-params were given) args = setup_args_defaults(args) @@ -1135,6 +1132,9 @@ if __name__ == '__main__': else: positionals.append(arg) + update_git() # Breaks and restarts the script if an update was found. + update_drive_list() + ## == If we got networking, # Try fetching instructions for this box unless a specific profile was given, and execute them. if args['profile'] is None and not args['minimal']: -- cgit v1.2.3-54-g00ecf From b0804b41d00ec6f58d14f23e864cd290a489acd8 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:17:31 +0100 Subject: Fixing args --- archinstall.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 8075e6f4..05361fab 100644 --- a/archinstall.py +++ b/archinstall.py @@ -576,6 +576,9 @@ def merge_in_includes(instructions, *positionals, **kwargs): ## Update arguments if we found any for key, val in instructions['args'].items(): args[key] = val + if 'user_args' in kwargs: + for key, val in kwargs['user_args'].items(): + args[key] = val return instructions @@ -830,6 +833,9 @@ def load_automatic_instructions(*positionals, **kwargs): ## Update arguments if we found any for key, val in instructions['args'].items(): args[key] = val + if 'user_args' in kwargs: + for key, val in kwargs['user_args'].items(): + args[key] = val else: print('[N] No gateway - No net deploy') @@ -1121,6 +1127,7 @@ if __name__ == '__main__': ## Setup some defaults # (in case no command-line parameters or netdeploy-params were given) args = setup_args_defaults(args) + user_args = {} positionals = [] for arg in sys.argv[1:]: if '--' == arg[:2]: @@ -1129,6 +1136,7 @@ if __name__ == '__main__': else: key, val = arg[2:], True args[key] = val + user_args[key] = val else: positionals.append(arg) @@ -1138,7 +1146,7 @@ if __name__ == '__main__': ## == If we got networking, # Try fetching instructions for this box unless a specific profile was given, and execute them. if args['profile'] is None and not args['minimal']: - instructions = load_automatic_instructions() + instructions = load_automatic_instructions(user_args=user_args) elif args['profile'] and not args['minimal']: instructions = get_instructions(args['profile']) @@ -1159,7 +1167,7 @@ if __name__ == '__main__': first = False # TODO: Might not need to return anything here, passed by reference? - instructions = merge_in_includes(instructions) + instructions = merge_in_includes(instructions, user_args=user_args) cleanup_args() ## If no drive was found in args, select one. -- cgit v1.2.3-54-g00ecf From b4f311584b0f85f66fcbbf20ee8cce10686562d3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:25:27 +0100 Subject: Fixing argument for boot command --- archinstall.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index 05361fab..25b6feb4 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1109,11 +1109,15 @@ def run_post_install_steps(*positionals, **kwargs): ## " login" followed by "Passwodd" in case it's been set in a previous step.. usually this shouldn't be nessecary ## since we set the password as the last step. And then the command itself which will be executed by looking for: ## [root@ ~]# - o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', events={ - bytes(f'login:', 'UTF-8') : b'root\n', - #b'Password:' : bytes(args['password']+'\n', 'UTF-8'), - bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), - }, **opts)) + defaults = { + bytes(f'login:', 'UTF-8') : b'root\n', + #b'Password:' : bytes(args['password']+'\n', 'UTF-8'), + bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), + } + if not 'events' in opts: opts['events'] = {} + events = {**defaults, **opts['events']} + del(opts['events']) + o = b''.join(sys_command('/usr/bin/systemd-nspawn -D /mnt -b --machine temporary', events=events, **opts)) ## Not needed anymore: And cleanup after out selves.. Don't want to leave any residue.. # os.remove('/mnt/etc/systemd/system/console-getty.service.d/override.conf') -- cgit v1.2.3-54-g00ecf From b2f85c93e7a93ad31910902975f408ae106a0bb2 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:33:00 +0100 Subject: Fixing bytes conversion on JSON triggers on command lines --- archinstall.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 25b6feb4..62fd88e1 100644 --- a/archinstall.py +++ b/archinstall.py @@ -312,6 +312,7 @@ class sys_command():#Thread): broke = False if 'events' in self.kwargs: for trigger in list(self.kwargs['events']): + if type(trigger) != bytes: trigger = bytes(trigger, 'UTF-8') if trigger.lower() in self.trace_log[last_trigger_pos:].lower(): trigger_pos = self.trace_log[last_trigger_pos:].lower().find(trigger.lower()) @@ -1087,7 +1088,7 @@ def run_post_install_steps(*positionals, **kwargs): o = simple_command("cd /mnt; mount -t proc /proc proc") o = simple_command("cd /mnt; mount --make-rslave --rbind /sys sys") o = simple_command("cd /mnt; mount --make-rslave --rbind /dev dev") - o = simple_command('chroot /mnt /bin/bash -c "{c}"'.format(c=command), events=opts) + o = simple_command('chroot /mnt /bin/bash -c "{c}"'.format(c=command), opts=opts) o = simple_command("cd /mnt; umount -R dev") o = simple_command("cd /mnt; umount -R sys") o = simple_command("cd /mnt; umount -R proc") -- cgit v1.2.3-54-g00ecf From c2badea10badc3d48d4250955c58732e6dcb08b3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:35:37 +0100 Subject: Debugging --- archinstall.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 62fd88e1..1b442d1c 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1229,7 +1229,9 @@ if __name__ == '__main__': close_disks() print(f'[N] Setting up {args["drive"]}.') - format_disk('drive', start='start', end='size') + if not format_disk('drive', start='start', end='size', debug=True): + pritn(f'[E] Coult not format drive {args["drive"]}') + exit(1) refresh_partition_list('drive') print(f'[N] Partitions: {len(args["partitions"])} (Boot: {list(args["partitions"].keys())[0]})') -- cgit v1.2.3-54-g00ecf From 253e52da228183be504b1fd8249dcb7bbad5f011 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:37:05 +0100 Subject: debugging --- archinstall.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 1b442d1c..2502b00e 100644 --- a/archinstall.py +++ b/archinstall.py @@ -306,6 +306,7 @@ class sys_command():#Thread): break if 'debug' in self.kwargs and self.kwargs['debug'] and len(output): + print(self.cmd[0], 'gave:', output.decode('UTF-8'), origin='spawn', level=4) log(self.cmd[0],'gave:', output.decode('UTF-8'), origin='spawn', level=4) lower = output.lower() @@ -1230,7 +1231,7 @@ if __name__ == '__main__': close_disks() print(f'[N] Setting up {args["drive"]}.') if not format_disk('drive', start='start', end='size', debug=True): - pritn(f'[E] Coult not format drive {args["drive"]}') + print(f'[E] Coult not format drive {args["drive"]}') exit(1) refresh_partition_list('drive') -- cgit v1.2.3-54-g00ecf From f537eee6b35c4f19a347f22209432d3bbeaaa024 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:37:44 +0100 Subject: debugging --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 2502b00e..2794b1a8 100644 --- a/archinstall.py +++ b/archinstall.py @@ -306,7 +306,7 @@ class sys_command():#Thread): break if 'debug' in self.kwargs and self.kwargs['debug'] and len(output): - print(self.cmd[0], 'gave:', output.decode('UTF-8'), origin='spawn', level=4) + print(self.cmd[0], 'gave:', output.decode('UTF-8')) log(self.cmd[0],'gave:', output.decode('UTF-8'), origin='spawn', level=4) lower = output.lower() -- cgit v1.2.3-54-g00ecf From 735a2b02e90131dd2621c7430d4621be88fee4e3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 15:50:08 +0100 Subject: Adding test of multiple event triggers --- deployments/default.json | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/deployments/default.json b/deployments/default.json index 1eeac949..4aa0489d 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -1,15 +1,18 @@ { "args" : { - "password" : "", + "password" : "0000", "post" : "stay" }, "post" : { "test exit codes" : { "exit 1" : {"ignore_errors" : true}, - "echo 'test1'; read moo; echo 'test2'; read mooo" : {"events" : { - "test1" : "something", - "test2" : "something" - }, "boot" : true} + "echo 'ssh test@77.80.220.176" : { + "events" : { + "continue connecting" : "yes", + "s password" : "test" + }, + "boot" : true + } } } } -- cgit v1.2.3-54-g00ecf From 7b1968fa9a27eedb195e0d3e9d416413dafe71bb Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 16:12:10 +0100 Subject: Adding more debug output --- archinstall.py | 4 ++++ deployments/default.json | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 2794b1a8..feb73093 100644 --- a/archinstall.py +++ b/archinstall.py @@ -294,6 +294,10 @@ class sys_command():#Thread): poller = epoll() poller.register(child_fd, EPOLLIN | EPOLLHUP) + if 'events' in self.kwargs and 'debug' in self.kwargs: + print(f'[D] Using triggers for command: {self.cmd}') + print(json.dumps(self.kwargs['events'])) + alive = True last_trigger_pos = 0 while alive and not self.kwargs['emulate']: diff --git a/deployments/default.json b/deployments/default.json index 4aa0489d..78fd346e 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -11,7 +11,8 @@ "continue connecting" : "yes", "s password" : "test" }, - "boot" : true + "boot" : true, + "debug" : true } } } -- cgit v1.2.3-54-g00ecf From 0e52ef0449352fe4ee92bdc31c556075a449f07c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 16:16:04 +0100 Subject: Modifying default template for test --- deployments/default.json | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/deployments/default.json b/deployments/default.json index 5deded3e..78fd346e 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -1,6 +1,19 @@ { "args" : { - "password" : "", - "post" : "reboot" + "password" : "0000", + "post" : "stay" + }, + "post" : { + "test exit codes" : { + "exit 1" : {"ignore_errors" : true}, + "echo 'ssh test@77.80.220.176" : { + "events" : { + "continue connecting" : "yes", + "s password" : "test" + }, + "boot" : true, + "debug" : true + } + } } } -- cgit v1.2.3-54-g00ecf From 3769a3193b24ff77620f0160239058296dc495be Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 16:36:43 +0100 Subject: Tweaking event input --- archinstall.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index feb73093..39911742 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1116,9 +1116,9 @@ def run_post_install_steps(*positionals, **kwargs): ## since we set the password as the last step. And then the command itself which will be executed by looking for: ## [root@ ~]# defaults = { - bytes(f'login:', 'UTF-8') : b'root\n', - #b'Password:' : bytes(args['password']+'\n', 'UTF-8'), - bytes(f'[root@{args["hostname"]} ~]#', 'UTF-8') : bytes(command+'\n', 'UTF-8'), + 'login:' : 'root\n', + #b'Password:' : bytes(args['password']+'\n', + '[root@{args["hostname"]} ~]#' : command+'\n', } if not 'events' in opts: opts['events'] = {} events = {**defaults, **opts['events']} -- cgit v1.2.3-54-g00ecf From cefe7e4f8b714e2c5c1ea7b6153eff42fc051878 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 16:53:47 +0100 Subject: Enhancing trigger values --- archinstall.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index 39911742..07205096 100644 --- a/archinstall.py +++ b/archinstall.py @@ -317,7 +317,12 @@ class sys_command():#Thread): broke = False if 'events' in self.kwargs: for trigger in list(self.kwargs['events']): - if type(trigger) != bytes: trigger = bytes(trigger, 'UTF-8') + if type(trigger) != bytes: + key = self.kwargs['events'][trigger] + del(self.kwargs['events'][trigger]) + trigger = bytes(key, 'UTF-8') + self.kwargs['events'][trigger] = self.kwargs['events'][key] + if trigger.lower() in self.trace_log[last_trigger_pos:].lower(): trigger_pos = self.trace_log[last_trigger_pos:].lower().find(trigger.lower()) @@ -325,6 +330,8 @@ class sys_command():#Thread): log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}", origin='spawn', level=5) last_trigger_pos = trigger_pos + if type(self.kwargs['events'][trigger]) != bytes: + self.kwargs['events'][trigger] = bytes(self.kwargs['events'][trigger], 'UTF-8') os.write(child_fd, self.kwargs['events'][trigger]) del(self.kwargs['events'][trigger]) broke = True @@ -1117,7 +1124,7 @@ def run_post_install_steps(*positionals, **kwargs): ## [root@ ~]# defaults = { 'login:' : 'root\n', - #b'Password:' : bytes(args['password']+'\n', + #'Password:' : args['password']+'\n', '[root@{args["hostname"]} ~]#' : command+'\n', } if not 'events' in opts: opts['events'] = {} -- cgit v1.2.3-54-g00ecf From fc196a589ba2f83cbc188ffe0e7f7c48da05ec3f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:02:40 +0100 Subject: Debugging --- deployments/default.json | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/deployments/default.json b/deployments/default.json index 78fd346e..78ea5472 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -1,19 +1,17 @@ { - "args" : { - "password" : "0000", - "post" : "stay" - }, - "post" : { - "test exit codes" : { - "exit 1" : {"ignore_errors" : true}, - "echo 'ssh test@77.80.220.176" : { - "events" : { - "continue connecting" : "yes", - "s password" : "test" - }, - "boot" : true, - "debug" : true - } - } - } + "args" : { + "password" : "0000", + "post" : "stay" + }, + "post" : { + "test exit codes" : { + "ssh test@77.80.220.176" : {"events" : { + "continue connecting" : "yes", + "s password" : "test" + }, + "boot" : true, + "debug" : true + } + } + } } -- cgit v1.2.3-54-g00ecf From c5360f94e2ca20ae5ce700fd1dc77ba99534c448 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:03:02 +0100 Subject: Debugging --- deployments/default.json | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/deployments/default.json b/deployments/default.json index 78fd346e..78ea5472 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -1,19 +1,17 @@ { - "args" : { - "password" : "0000", - "post" : "stay" - }, - "post" : { - "test exit codes" : { - "exit 1" : {"ignore_errors" : true}, - "echo 'ssh test@77.80.220.176" : { - "events" : { - "continue connecting" : "yes", - "s password" : "test" - }, - "boot" : true, - "debug" : true - } - } - } + "args" : { + "password" : "0000", + "post" : "stay" + }, + "post" : { + "test exit codes" : { + "ssh test@77.80.220.176" : {"events" : { + "continue connecting" : "yes", + "s password" : "test" + }, + "boot" : true, + "debug" : true + } + } + } } -- cgit v1.2.3-54-g00ecf From 198c47333ea93083e141146ceb60d1166914df6e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:10:04 +0100 Subject: Debugging --- archinstall.py | 5 +++-- deployments/default.json | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index 07205096..74e22898 100644 --- a/archinstall.py +++ b/archinstall.py @@ -322,16 +322,17 @@ class sys_command():#Thread): del(self.kwargs['events'][trigger]) trigger = bytes(key, 'UTF-8') self.kwargs['events'][trigger] = self.kwargs['events'][key] + if type(self.kwargs['events'][key]) != bytes: + self.kwargs['events'][key] = bytes(self.kwargs['events'][key], 'UTF-8') if trigger.lower() in self.trace_log[last_trigger_pos:].lower(): trigger_pos = self.trace_log[last_trigger_pos:].lower().find(trigger.lower()) if 'debug' in self.kwargs and self.kwargs['debug']: + print(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}") log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}", origin='spawn', level=5) last_trigger_pos = trigger_pos - if type(self.kwargs['events'][trigger]) != bytes: - self.kwargs['events'][trigger] = bytes(self.kwargs['events'][trigger], 'UTF-8') os.write(child_fd, self.kwargs['events'][trigger]) del(self.kwargs['events'][trigger]) broke = True diff --git a/deployments/default.json b/deployments/default.json index 78ea5472..cd205f84 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -6,8 +6,8 @@ "post" : { "test exit codes" : { "ssh test@77.80.220.176" : {"events" : { - "continue connecting" : "yes", - "s password" : "test" + "continue connecting" : "yes\n", + "s password" : "test\n" }, "boot" : true, "debug" : true -- cgit v1.2.3-54-g00ecf From e505ba6f196acf92b34298866acf5f19939b6d4d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:10:20 +0100 Subject: Debugging --- deployments/default.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployments/default.json b/deployments/default.json index 78ea5472..cd205f84 100644 --- a/deployments/default.json +++ b/deployments/default.json @@ -6,8 +6,8 @@ "post" : { "test exit codes" : { "ssh test@77.80.220.176" : {"events" : { - "continue connecting" : "yes", - "s password" : "test" + "continue connecting" : "yes\n", + "s password" : "test\n" }, "boot" : true, "debug" : true -- cgit v1.2.3-54-g00ecf From c5b44a6935b7b4fe3762202f3d2ae746e7ad24b3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:23:04 +0100 Subject: Fixing issues with the spawning of containers. --- archinstall.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index 74e22898..f449c133 100644 --- a/archinstall.py +++ b/archinstall.py @@ -318,12 +318,13 @@ class sys_command():#Thread): if 'events' in self.kwargs: for trigger in list(self.kwargs['events']): if type(trigger) != bytes: - key = self.kwargs['events'][trigger] + original = self.kwargs['events'][trigger] del(self.kwargs['events'][trigger]) - trigger = bytes(key, 'UTF-8') - self.kwargs['events'][trigger] = self.kwargs['events'][key] - if type(self.kwargs['events'][key]) != bytes: - self.kwargs['events'][key] = bytes(self.kwargs['events'][key], 'UTF-8') + + trigger = bytes(original, 'UTF-8') + self.kwargs['events'][trigger] = self.kwargs['events'][original] + if type(self.kwargs['events'][trigger]) != bytes: + self.kwargs['events'][trigger] = bytes(self.kwargs['events'][trigger], 'UTF-8') if trigger.lower() in self.trace_log[last_trigger_pos:].lower(): trigger_pos = self.trace_log[last_trigger_pos:].lower().find(trigger.lower()) -- cgit v1.2.3-54-g00ecf From 92d9af970d0ea1d318c20bf0d6c1ec05168b5824 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:27:53 +0100 Subject: Fixing issues with the spawning of containers. --- archinstall.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/archinstall.py b/archinstall.py index f449c133..7ecb338a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -319,10 +319,9 @@ class sys_command():#Thread): for trigger in list(self.kwargs['events']): if type(trigger) != bytes: original = self.kwargs['events'][trigger] - del(self.kwargs['events'][trigger]) - trigger = bytes(original, 'UTF-8') self.kwargs['events'][trigger] = self.kwargs['events'][original] + del(self.kwargs['events'][original]) if type(self.kwargs['events'][trigger]) != bytes: self.kwargs['events'][trigger] = bytes(self.kwargs['events'][trigger], 'UTF-8') -- cgit v1.2.3-54-g00ecf From 3ba199628bdd21f908e5c1934f302183aac2e3b5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:38:22 +0100 Subject: Fixing issues with the spawning of containers. --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 7ecb338a..f25c3f0a 100644 --- a/archinstall.py +++ b/archinstall.py @@ -318,7 +318,7 @@ class sys_command():#Thread): if 'events' in self.kwargs: for trigger in list(self.kwargs['events']): if type(trigger) != bytes: - original = self.kwargs['events'][trigger] + original = trigger trigger = bytes(original, 'UTF-8') self.kwargs['events'][trigger] = self.kwargs['events'][original] del(self.kwargs['events'][original]) -- cgit v1.2.3-54-g00ecf From 9eb80c139ff76b0bb02568911625c6c12b7b6bdf Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:39:47 +0100 Subject: Fixing rerun --- archinstall.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archinstall.py b/archinstall.py index f25c3f0a..b1814ed6 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1297,6 +1297,8 @@ if __name__ == '__main__': update_git(pre_conf['git-branch']) del(pre_conf['git-branch']) + rerun = args['ignore-rerun'] + ## Prerequisit steps needs to NOT be executed in arch-chroot. ## Mainly because there's no root structure to chroot into. ## But partly because some configurations need to be done against the live CD. -- cgit v1.2.3-54-g00ecf From cb3d16b0bbec1a45c32fe3ac2e98e6c256f3d6b9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:47:21 +0100 Subject: Fixed password prompt for nspawn --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index b1814ed6..5635561e 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1125,7 +1125,7 @@ def run_post_install_steps(*positionals, **kwargs): ## [root@ ~]# defaults = { 'login:' : 'root\n', - #'Password:' : args['password']+'\n', + 'Password:' : args['password']+'\n', '[root@{args["hostname"]} ~]#' : command+'\n', } if not 'events' in opts: opts['events'] = {} -- cgit v1.2.3-54-g00ecf From bf32476bfd92af8280c17bc04fe73a3932e01b7d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 17:56:27 +0100 Subject: Fixing password order for commnaads --- archinstall.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/archinstall.py b/archinstall.py index 5635561e..2f22f94c 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1356,6 +1356,14 @@ if __name__ == '__main__': add_AUR_support() print('[N] AUR support added. use "yay -Syy --noconfirm " to deploy in POST.') + ## == Passwords + # o = sys_command('arch-chroot /mnt usermod --password {} root'.format(args['password'])) + # o = sys_command("arch-chroot /mnt sh -c 'echo {pin} | passwd --stdin root'".format(pin='"{pin}"'.format(**args, pin=args['password'])), echo=True) + o = simple_command("/usr/bin/arch-chroot /mnt sh -c \"echo 'root:{pin}' | chpasswd\"".format(**args, pin=args['password'])) + if 'user' in args: + o = ('/usr/bin/arch-chroot /mnt useradd -m -G wheel {user}'.format(**args)) + o = ("/usr/bin/arch-chroot /mnt sh -c \"echo '{user}:{pin}' | chpasswd\"".format(**args, pin=args['password'])) + print('[N] Running post installation steps.') run_post_install_steps() time.sleep(2) @@ -1368,14 +1376,6 @@ if __name__ == '__main__': if args['phone-home']: phone_home(args['phone-home']) - ## == Passwords - # o = sys_command('arch-chroot /mnt usermod --password {} root'.format(args['password'])) - # o = sys_command("arch-chroot /mnt sh -c 'echo {pin} | passwd --stdin root'".format(pin='"{pin}"'.format(**args, pin=args['password'])), echo=True) - o = simple_command("/usr/bin/arch-chroot /mnt sh -c \"echo 'root:{pin}' | chpasswd\"".format(**args, pin=args['password'])) - if 'user' in args: - o = ('/usr/bin/arch-chroot /mnt useradd -m -G wheel {user}'.format(**args)) - o = ("/usr/bin/arch-chroot /mnt sh -c \"echo '{user}:{pin}' | chpasswd\"".format(**args, pin=args['password'])) - if args['post'] == 'reboot': o = simple_command('/usr/bin/umount -R /mnt') o = simple_command('/usr/bin/reboot now') -- cgit v1.2.3-54-g00ecf From 42b697a4e35bfe6248f2b57c7166d5e496b2326b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 29 Nov 2019 18:02:11 +0100 Subject: Debugging --- archinstall.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archinstall.py b/archinstall.py index 2f22f94c..64c1a164 100644 --- a/archinstall.py +++ b/archinstall.py @@ -1360,6 +1360,8 @@ if __name__ == '__main__': # o = sys_command('arch-chroot /mnt usermod --password {} root'.format(args['password'])) # o = sys_command("arch-chroot /mnt sh -c 'echo {pin} | passwd --stdin root'".format(pin='"{pin}"'.format(**args, pin=args['password'])), echo=True) o = simple_command("/usr/bin/arch-chroot /mnt sh -c \"echo 'root:{pin}' | chpasswd\"".format(**args, pin=args['password'])) + print(o) + time.sleep(5) if 'user' in args: o = ('/usr/bin/arch-chroot /mnt useradd -m -G wheel {user}'.format(**args)) o = ("/usr/bin/arch-chroot /mnt sh -c \"echo '{user}:{pin}' | chpasswd\"".format(**args, pin=args['password'])) -- cgit v1.2.3-54-g00ecf From 9d65f6eb2d179af2e5c14d486c7533b40a39b10f Mon Sep 17 00:00:00 2001 From: jaybent <55739788+jaybent@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:44:04 +0100 Subject: Rename gitea to gitea.json --- deployments/gitea | 13 ------------- deployments/gitea.json | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 deployments/gitea create mode 100644 deployments/gitea.json diff --git a/deployments/gitea b/deployments/gitea deleted file mode 100644 index 28071bd8..00000000 --- a/deployments/gitea +++ /dev/null @@ -1,13 +0,0 @@ -{ - "args" : { - "password" : "", - "_editor" : "nano", - "_utils" : "openssh git curl dhclient", - "post" : "don't reboot" - }, - "post" : { - "Install workstation packages": { - "pacman -Syy --noconfirm {{_utils} {_editor}" : {"pass-args" : true} - } - } -} diff --git a/deployments/gitea.json b/deployments/gitea.json new file mode 100644 index 00000000..28071bd8 --- /dev/null +++ b/deployments/gitea.json @@ -0,0 +1,13 @@ +{ + "args" : { + "password" : "", + "_editor" : "nano", + "_utils" : "openssh git curl dhclient", + "post" : "don't reboot" + }, + "post" : { + "Install workstation packages": { + "pacman -Syy --noconfirm {{_utils} {_editor}" : {"pass-args" : true} + } + } +} -- cgit v1.2.3-54-g00ecf From 00d0a29c491d5641d589bdacccdd0726c44f4951 Mon Sep 17 00:00:00 2001 From: jaybent <55739788+jaybent@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:56:33 +0100 Subject: Update gitea.json Typo's --- deployments/gitea.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/gitea.json b/deployments/gitea.json index 28071bd8..efb4c15e 100644 --- a/deployments/gitea.json +++ b/deployments/gitea.json @@ -7,7 +7,7 @@ }, "post" : { "Install workstation packages": { - "pacman -Syy --noconfirm {{_utils} {_editor}" : {"pass-args" : true} + "pacman -Syy --noconfirm {_utils} {_editor}" : {"pass-args" : true} } } } -- cgit v1.2.3-54-g00ecf