Added a rerun feature. So we don't have to wait for pacstrap every debug run :P

This commit is contained in:
Anton Hvornum 2019-06-20 16:18:44 +00:00
parent 2376ab2742
commit aa2871f3f6
2 changed files with 84 additions and 65 deletions

View File

@ -424,6 +424,8 @@ if __name__ == '__main__':
if not 'default' in args: args['default'] = False if not 'default' in args: args['default'] = False
if not 'profile' in args: args['profile'] = None if not 'profile' in args: args['profile'] = None
if not 'profiles-path' in args: args['profiles-path'] = profiles_path if not 'profiles-path' in args: args['profiles-path'] = profiles_path
if not 'rerun' in args: args['rerun'] = None
rerun = False
if args['drive'][0] != '/': if args['drive'][0] != '/':
## Remap the selected UUID to the device to be formatted. ## Remap the selected UUID to the device to be formatted.
@ -530,6 +532,8 @@ if __name__ == '__main__':
print() print()
print('[!] Disk PASSWORD is: {}'.format(args['password'])) print('[!] Disk PASSWORD is: {}'.format(args['password']))
print() print()
if not args['rerun']:
print('[N] Setting up {drive}.'.format(**args)) print('[N] Setting up {drive}.'.format(**args))
# dd if=/dev/random of=args['drive'] bs=4096 status=progress # 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 # https://github.com/dcantrell/pyparted would be nice, but isn't officially in the repo's #SadPanda
@ -554,6 +558,7 @@ if __name__ == '__main__':
print(f'Partition info: {part_name}') print(f'Partition info: {part_name}')
print(json.dumps(args['paritions'][part_name], indent=4)) print(json.dumps(args['paritions'][part_name], indent=4))
if not args['rerun']:
o = b''.join(sys_command('/usr/bin/mkfs.vfat -F32 {drive}{partition_1}'.format(**args)).exec()) o = b''.join(sys_command('/usr/bin/mkfs.vfat -F32 {drive}{partition_1}'.format(**args)).exec())
if (b'mkfs.fat' not in o and b'mkfs.vfat' not in o) or b'command not found' in o: 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) print('[E] Could not setup {drive}{partition_1}'.format(**args), o)
@ -573,6 +578,7 @@ if __name__ == '__main__':
print('[E] Could not mount encrypted device.', o) print('[E] Could not mount encrypted device.', o)
exit(1) exit(1)
if not args['rerun']:
print('[N] Creating btrfs filesystem inside {drive}{partition_2}'.format(**args)) print('[N] Creating btrfs filesystem inside {drive}{partition_2}'.format(**args))
o = b''.join(sys_command('/usr/bin/mkfs.btrfs -f /dev/mapper/luksdev').exec()) o = b''.join(sys_command('/usr/bin/mkfs.btrfs -f /dev/mapper/luksdev').exec())
if not b'UUID' in o: if not b'UUID' in o:
@ -601,6 +607,11 @@ if __name__ == '__main__':
## (For instance, modifying mirrors are done on LiveCD and replicated intwards) ## (For instance, modifying mirrors are done on LiveCD and replicated intwards)
for title in pre_conf: for title in pre_conf:
print('[N] Network prerequisit step: {}'.format(title)) print('[N] Network prerequisit step: {}'.format(title))
if args['rerun'] and args['rerun'] != title and not rerun:
continue
else:
rerun = True
for command in pre_conf[title]: for command in pre_conf[title]:
raw_command = command raw_command = command
opts = pre_conf[title][raw_command] if type(pre_conf[title][raw_command]) in (dict, oDict) else {} opts = pre_conf[title][raw_command] if type(pre_conf[title][raw_command]) in (dict, oDict) else {}
@ -625,6 +636,7 @@ if __name__ == '__main__':
print('[W] Prerequisit step failed: {}'.format(b''.join(o).decode('UTF-8'))) print('[W] Prerequisit step failed: {}'.format(b''.join(o).decode('UTF-8')))
#print(o) #print(o)
if not args['rerun'] or rerun:
print('[N] Straping in packages.') print('[N] Straping in packages.')
o = b''.join(sys_command('/usr/bin/pacman -Syy').exec()) o = b''.join(sys_command('/usr/bin/pacman -Syy').exec())
o = b''.join(sys_command('/usr/bin/pacstrap /mnt base base-devel btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args)).exec()) o = b''.join(sys_command('/usr/bin/pacstrap /mnt base base-devel btrfs-progs efibootmgr nano wpa_supplicant dialog {packages}'.format(**args)).exec())
@ -633,6 +645,7 @@ if __name__ == '__main__':
print('[E] Failed to strap in packages', o) print('[E] Failed to strap in packages', o)
exit(1) exit(1)
if not args['rerun'] or rerun:
o = b''.join(sys_command('/usr/bin/genfstab -pU /mnt >> /mnt/etc/fstab').exec()) o = b''.join(sys_command('/usr/bin/genfstab -pU /mnt >> /mnt/etc/fstab').exec())
with open('/mnt/etc/fstab', 'a') as 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? fstab.write('\ntmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0\n') # Redundant \n at the start? who knoes?
@ -678,6 +691,11 @@ if __name__ == '__main__':
conf = instructions conf = instructions
for title in conf: for title in conf:
if args['rerun'] and args['rerun'] != title and not rerun:
continue
else:
rerun = True
print('[N] Network Deploy: {}'.format(title)) print('[N] Network Deploy: {}'.format(title))
if type(conf[title]) == str: if type(conf[title]) == str:
print('[N] Loading {} configuration'.format(conf[title])) print('[N] Loading {} configuration'.format(conf[title]))

View File

@ -5,7 +5,8 @@
"packages" : "openssh sudo openvpn easy-rsa", "packages" : "openssh sudo openvpn easy-rsa",
"post" : "stay", "post" : "stay",
"country" : "SE", "country" : "SE",
"mirrors" : true "mirrors" : true,
"rerun" : "install database"
}, },
"post" : { "post" : {
"install database": "postgresql", "install database": "postgresql",