mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 05:35:44 -05:00
image: factor out create_chroot into its own file
Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
parent
1f5357bca6
commit
1364a97ddb
2 changed files with 38 additions and 30 deletions
36
chroot.py
Normal file
36
chroot.py
Normal 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)
|
||||||
|
|
32
image.py
32
image.py
|
@ -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)
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue