From 679e1bf58594a6014faee4d89aedb407ad87c234 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 21:33:54 +0000 Subject: Adding fix for issue #15. Not tested. --- archinstall.py | 28 +++++++++++++++++++++++++--- deployments/workstation_aur.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 deployments/workstation_aur.json diff --git a/archinstall.py b/archinstall.py index e2257c63..6a01a433 100644 --- a/archinstall.py +++ b/archinstall.py @@ -311,7 +311,7 @@ def get_drive_from_part_uuid(partuuid): return None -def update_git(): +def update_git(branch='master'): default_gw = get_default_gateway_linux() if(default_gw): print('[N] Checking for updates...') @@ -328,12 +328,16 @@ def update_git(): return # b'From github.com:Torxed/archinstall\n 339d687..80b97f3 master -> origin/master\nUpdating 339d687..80b97f3\nFast-forward\n README.md | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n' - if output != b'Already up to date': + if output != b'Already up to date' or branch != 'master': #tmp = re.findall(b'[0-9]+ file changed', output) #print(tmp) #if len(tmp): # num_changes = int(tmp[0].split(b' ',1)[0]) # if(num_changes): + + if branch != 'master': + print(f'[N] Changing branch to {branch}') + output = simple_command(f'(cd /root/archinstall; git checkout {branch}; git pull)') if not 'rebooted' in args: ## Reboot the script (in same context) @@ -488,6 +492,7 @@ if __name__ == '__main__': 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 'support-aur' in args: args['support-aur'] = 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 'drive' in args: @@ -703,6 +708,9 @@ if __name__ == '__main__': elif 'prerequisits' in instructions: pre_conf = instructions['prerequisits'] + if 'git-branch' in pre_conf: + update_git(pre_conf['git-branch']) + ## 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. @@ -743,7 +751,7 @@ if __name__ == '__main__': o = b''.join(sys_command('/usr/bin/pacman -Syy').exec()) 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)).exec()) - if not os.path.isdir('/mnt/etc'): + 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) @@ -787,12 +795,26 @@ if __name__ == '__main__': 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['support-aur']: + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "useradd -m -G wheel aibuilder"').exec()) + o = b''.join(sys_command("/usr/bin/sed -i 's/# %wheel ALL=(ALL) NO/%wheel ALL=(ALL) NO/' /mnt/etc/sudoers").exec()) + + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "git clone https://aur.archlinux.org/yay.git"').exec()) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "chown -R aibuilder.aibuilder yay"').exec()) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "su - aibuilder -c \"(cd /root/yay; makepkg -si --noconfirm)\" >/dev/null"').exec()) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "sed -i \'s/%wheel ALL=(ALL) NO/# %wheel ALL=(ALL) NO/\' /mnt/etc/sudoers"').exec()) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "userdel aibuilder"').exec()) + o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "rm -rf /home/aibuilder"').exec()) + 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(pre_conf['git-branch']) + for title in conf: if args['rerun'] and args['rerun'] != title and not rerun: continue diff --git a/deployments/workstation_aur.json b/deployments/workstation_aur.json new file mode 100644 index 00000000..5cc59515 --- /dev/null +++ b/deployments/workstation_aur.json @@ -0,0 +1,33 @@ +{ + "pre" : { + "git-branch" : "aur-support" + }, + "args" : { + "password" : "", + "_keyboard_layout" : "sv-latin1", + "_editor" : "nano", + "_mediaplayer" : "lollypop gstreamer gst-plugins-good gnome-keyring", + "_filebrowser" : "nemo gpicview-gtk3", + "_webbrowser" : "chromium", + "_window_manager" : "awesome", + "_window_manager_dependencies" : "xorg-server xorg-xrandr xorg-xinit xterm", + "_window_manager_utilities" : "feh slock xscreensaver terminus-font-otb gnu-free-fonts ttf-liberation xsel", + "_virtulization" : "qemu ovmf", + "_utils" : "openssh sshfs git htop pkgfile scrot dhclient wget smbclient cifs-utils libu2f-host", + "_audio" : "pulseaudio pulseaudio-alsa pavucontrol", + "post" : "don't reboot" + }, + "post" : { + "Install workstation packages": { + "pacman -Syy --noconfirm {_webbrowser} {_utils} {_mediaplayer} {_window_manager} {_window_manager_dependencies} {_window_manager_utilities} {_virtulization} {_filebrowser} {_editor}" : {"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 loclization" : { + "sh -c \"echo 'setxkbmap se' >> /etc/X11/xinit/xinitrc\"" : null, + "sh -c \"echo 'KEYMAP={_keyboard_layout}\nFONT=lat9w-16' >> /etc/vconsole.conf\"" : {"pass-args" : true} + }, + "Configure desktop environment" : "awesome" + } +} -- cgit v1.2.3-54-g00ecf From f9f6d890ae936c9a9eed79ef90b46e87c9395022 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 21:52:33 +0000 Subject: Added fix for #23. Not tested --- archinstall.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/archinstall.py b/archinstall.py index 6a01a433..2ae7c747 100644 --- a/archinstall.py +++ b/archinstall.py @@ -75,7 +75,7 @@ except: ## FIXME: dependency checks (fdisk, lsblk etc) def sig_handler(signal, frame): - print('Aborting further installation steps!') + print('\nAborting further installation steps!') print(' Here\'s a summary of the commandline:') print(f' {sys.argv}') @@ -420,11 +420,19 @@ def get_application_instructions(target): instructions = {} try: instructions = grab_url_data('{}/applications/{}.json'.format(args['profiles-path'], target)) + print('[N] Found application instructions for: {}'.format(target)) except urllib.error.HTTPError: print('[N] No instructions found for: {}'.format(target)) - return instructions + print('[N] Trying local instructions under ./deployments/applications') + local_path = './deployments/applications' if isfile('./archinstall.py') else './archinstall/deployments/applications': # Dangerous assumption + if isfile(f'{local_path}/deployments/applications/{target}.json'): + with open(f'{local_path}/deployments/applications/{target}.json', 'r') as fh: + instructions = fh.read() + + print('[N] Found local application instructions for: {}'.format(target)) + else: + return instructions - print('[N] Found application instructions for: {}'.format(target)) try: instructions = json.loads(instructions.decode('UTF-8'), object_pairs_hook=oDict) except: @@ -438,11 +446,19 @@ def get_instructions(target): instructions = {} try: instructions = grab_url_data('{}/{}.json'.format(args['profiles-path'], target)) + print('[N] Found net-deploy instructions called: {}'.format(target)) except urllib.error.HTTPError: print('[N] No instructions found called: {}'.format(target)) - return instructions + print('[N] Trying local instructions under ./deployments') + local_path = './deployments' if isfile('./archinstall.py') else './archinstall/deployments': # Dangerous assumption + if isfile(f'{local_path}/deployments/{target}.json'): + with open(f'{local_path}/deployments/{target}.json', 'r') as fh: + instructions = fh.read() + + print('[N] Found local instructions called: {}'.format(target)) + else: + return instructions - print('[N] Found net-deploy instructions called: {}'.format(target)) try: instructions = json.loads(instructions.decode('UTF-8'), object_pairs_hook=oDict) except: -- cgit v1.2.3-54-g00ecf From f61ffee65a553081513a3144c3d38ef9e91f152e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 21:54:41 +0000 Subject: Syntax error on conditional assignment --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index 2ae7c747..b9a35c49 100644 --- a/archinstall.py +++ b/archinstall.py @@ -424,7 +424,7 @@ def get_application_instructions(target): except urllib.error.HTTPError: print('[N] No instructions found for: {}'.format(target)) print('[N] Trying local instructions under ./deployments/applications') - local_path = './deployments/applications' if isfile('./archinstall.py') else './archinstall/deployments/applications': # Dangerous assumption + local_path = './deployments/applications' if isfile('./archinstall.py') else './archinstall/deployments/applications' # Dangerous assumption if isfile(f'{local_path}/deployments/applications/{target}.json'): with open(f'{local_path}/deployments/applications/{target}.json', 'r') as fh: instructions = fh.read() -- cgit v1.2.3-54-g00ecf From 89a1a89a063b790842ec931f7c0ef5e9bfce2b0a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 21:55:24 +0000 Subject: Syntax error on conditional assignment --- archinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall.py b/archinstall.py index b9a35c49..e61d5104 100644 --- a/archinstall.py +++ b/archinstall.py @@ -450,7 +450,7 @@ def get_instructions(target): except urllib.error.HTTPError: print('[N] No instructions found called: {}'.format(target)) print('[N] Trying local instructions under ./deployments') - local_path = './deployments' if isfile('./archinstall.py') else './archinstall/deployments': # Dangerous assumption + local_path = './deployments' if isfile('./archinstall.py') else './archinstall/deployments' # Dangerous assumption if isfile(f'{local_path}/deployments/{target}.json'): with open(f'{local_path}/deployments/{target}.json', 'r') as fh: instructions = fh.read() -- cgit v1.2.3-54-g00ecf From 3c10bbfe272442ba9aa66202bad042dba9e622cd Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 21:56:14 +0000 Subject: Forgot that isfile wasn't imported the way I normally do it. --- archinstall.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index e61d5104..ae9e9c9d 100644 --- a/archinstall.py +++ b/archinstall.py @@ -424,8 +424,8 @@ def get_application_instructions(target): except urllib.error.HTTPError: print('[N] No instructions found for: {}'.format(target)) print('[N] Trying local instructions under ./deployments/applications') - local_path = './deployments/applications' if isfile('./archinstall.py') else './archinstall/deployments/applications' # Dangerous assumption - if isfile(f'{local_path}/deployments/applications/{target}.json'): + local_path = './deployments/applications' if os.path.isfile('./archinstall.py') else './archinstall/deployments/applications' # Dangerous assumption + if os.path.isfile(f'{local_path}/deployments/applications/{target}.json'): with open(f'{local_path}/deployments/applications/{target}.json', 'r') as fh: instructions = fh.read() @@ -450,8 +450,8 @@ def get_instructions(target): except urllib.error.HTTPError: print('[N] No instructions found called: {}'.format(target)) print('[N] Trying local instructions under ./deployments') - local_path = './deployments' if isfile('./archinstall.py') else './archinstall/deployments' # Dangerous assumption - if isfile(f'{local_path}/deployments/{target}.json'): + local_path = './deployments' if os.path.isfile('./archinstall.py') else './archinstall/deployments' # Dangerous assumption + if os.path.isfile(f'{local_path}/deployments/{target}.json'): with open(f'{local_path}/deployments/{target}.json', 'r') as fh: instructions = fh.read() -- cgit v1.2.3-54-g00ecf From 0ff066c813957d570f6561d59df6b3cf931536a8 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 21:59:20 +0000 Subject: Added /deployments/ twice. Silly me. --- archinstall.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index ae9e9c9d..b6fd9515 100644 --- a/archinstall.py +++ b/archinstall.py @@ -425,8 +425,8 @@ def get_application_instructions(target): print('[N] No instructions found for: {}'.format(target)) print('[N] Trying local instructions under ./deployments/applications') local_path = './deployments/applications' if os.path.isfile('./archinstall.py') else './archinstall/deployments/applications' # Dangerous assumption - if os.path.isfile(f'{local_path}/deployments/applications/{target}.json'): - with open(f'{local_path}/deployments/applications/{target}.json', 'r') as fh: + 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 application instructions for: {}'.format(target)) @@ -451,8 +451,8 @@ def get_instructions(target): print('[N] No instructions found called: {}'.format(target)) print('[N] 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}/deployments/{target}.json'): - with open(f'{local_path}/deployments/{target}.json', 'r') as fh: + 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)) -- cgit v1.2.3-54-g00ecf From 1d06491e42a74a4013325f8e9a66549c9c8896e3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 22:00:32 +0000 Subject: Moved the decoding logic for network data. - To the actual place where the network was executed. --- archinstall.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/archinstall.py b/archinstall.py index b6fd9515..4d85c9ce 100644 --- a/archinstall.py +++ b/archinstall.py @@ -419,7 +419,7 @@ def grab_url_data(path): def get_application_instructions(target): instructions = {} try: - instructions = grab_url_data('{}/applications/{}.json'.format(args['profiles-path'], target)) + instructions = grab_url_data('{}/applications/{}.json'.format(args['profiles-path'], target)).decode('UTF-8') print('[N] Found application instructions for: {}'.format(target)) except urllib.error.HTTPError: print('[N] No instructions found for: {}'.format(target)) @@ -434,7 +434,7 @@ def get_application_instructions(target): return instructions try: - instructions = json.loads(instructions.decode('UTF-8'), object_pairs_hook=oDict) + instructions = json.loads(instructions, object_pairs_hook=oDict) except: print('[E] JSON syntax error in {}'.format('{}/applications/{}.json'.format(args['profiles-path'], target))) traceback.print_exc() @@ -445,7 +445,7 @@ def get_application_instructions(target): def get_instructions(target): instructions = {} try: - instructions = grab_url_data('{}/{}.json'.format(args['profiles-path'], target)) + 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] No instructions found called: {}'.format(target)) @@ -460,7 +460,7 @@ def get_instructions(target): return instructions try: - instructions = json.loads(instructions.decode('UTF-8'), object_pairs_hook=oDict) + 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() -- cgit v1.2.3-54-g00ecf