From da008c6284b36255aaca3caa4b368d7b1c44de0d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 13 Nov 2019 23:36:22 +0000 Subject: Adding runas in options to POST commands. To be able to run AUR commands as a certain user since yay refuses to build as root --- archinstall.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/archinstall.py b/archinstall.py index 18ad9f22..10266545 100644 --- a/archinstall.py +++ b/archinstall.py @@ -827,9 +827,10 @@ if __name__ == '__main__': 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)\\""').exec()) o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "chown -R aibuilder.aibuilder /home/aibuilder/yay"').exec()) o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "su - aibuilder -c \\"(cd /home/aibuilder/yay; makepkg -si --noconfirm)\\" >/dev/null"').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 "userdel aibuilder"').exec()) - o = b''.join(sys_command('/usr/bin/arch-chroot /mnt sh -c "rm -rf /home/aibuilder"').exec()) + ## 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').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()) print('[N] AUR support added. use "yay -Syy --noconfirm " to deploy in POST.') conf = {} @@ -852,6 +853,7 @@ if __name__ == '__main__': 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 {} @@ -870,6 +872,10 @@ if __name__ == '__main__': 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 @@ -925,6 +931,11 @@ if __name__ == '__main__': print('[W] Post install command failed: {}'.format(o.decode('UTF-8'))) #print(o) + 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').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()) + ## == 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-70-g09d2