image: factor out create_chroot into its own file

Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
InsanePrawn 2021-08-06 02:21:50 +02:00
parent 1f5357bca6
commit 1364a97ddb
2 changed files with 38 additions and 30 deletions

36
chroot.py Normal file
View file

@ -0,0 +1,36 @@
import logging
import subprocess
def create_chroot(chroot_path, packages=['base'], pacman_conf='/app/src/pacman.conf'):
result = subprocess.run(['pacstrap',
'-C', pacman_conf,
'-c',
'-G',
chroot_path]
+ packages
+ ['--needed', '--overwrite=*', '-yyuu'])
if result.returncode != 0:
logging.fatal('Failed to install system')
exit(1)
user = 'kupfer'
password = '123456'
groups = ['network', 'video', 'audio', 'optical', 'storage',
'input', 'scanner', 'games', 'lp', 'rfkill', 'wheel']
install_script = '\n'.join([
f'if ! id -u "{user}" >/dev/null 2>&1; then',
f' useradd -m {user}',
f'fi',
f'usermod -a -G {",".join(groups)} {user}',
f'echo "{user}:{password}" | chpasswd',
f'chown {user}:{user} /home/{user} -R',
])
result = subprocess.run(['arch-chroot',
chroot_path,
'/bin/bash',
'-c',
install_script])
if result.returncode != 0:
logging.fatal('Failed to setup user')
exit(1)

View file

@ -7,6 +7,7 @@ import subprocess
import time import time
import click import click
from logger import * from logger import *
from chroot import create_chroot
devices = { devices = {
'oneplus-enchilada': ['sdm845-oneplus-enchilada'], 'oneplus-enchilada': ['sdm845-oneplus-enchilada'],
@ -140,36 +141,7 @@ def cmd_build(verbose):
rootfs_mount = mount_rootfs_image(image_name) rootfs_mount = mount_rootfs_image(image_name)
result = subprocess.run(['pacstrap', create_chroot(rootfs_mount, packages=(['base','base-kupfer'] + devices[device] + flavours[flavour]), pacman_conf='/app/src/pacman_copy.conf')
'-C', '/app/src/pacman_copy.conf',
'-c',
'-G',
rootfs_mount,
'base', 'base-kupfer']
+ devices[device]
+ flavours[flavour]
+ ['--needed', '--overwrite=*', '-yyuu'])
with open(os.path.join(rootfs_mount, 'install'), 'w') as file:
user = 'kupfer'
password = '123456'
groups = ['network', 'video', 'audio', 'optical', 'storage',
'input', 'scanner', 'games', 'lp', 'rfkill', 'wheel']
file.write('\n'.join([
f'if ! id -u "{user}" >/dev/null 2>&1; then',
f' useradd -m {user}',
f'fi',
f'usermod -a -G {",".join(groups)} {user}',
f'echo "{user}:{password}" | chpasswd',
f'chown {user}:{user} /home/{user} -R',
]))
result = subprocess.run(['arch-chroot',
rootfs_mount,
'/bin/bash', '/install'])
os.unlink(os.path.join(rootfs_mount, 'install'))
if result.returncode != 0:
logging.fatal('Failed to setup user')
exit(1)
""" """