chroots: use path from config

Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
InsanePrawn 2021-09-13 04:19:13 +02:00
parent 63a9cf1218
commit 04cce26ca0
3 changed files with 43 additions and 37 deletions

View file

@ -2,15 +2,16 @@ import logging
import subprocess
import os
import shutil
from config import config
def create_chroot(
chroot_path,
packages=['base'],
pacman_conf='/app/local/etc/pacman.conf',
chroot_base_path='/chroot',
extra_repos={},
):
def get_chroot_path(chroot_name, override_basepath: str = None) -> str:
base_path = config.file['paths']['chroots'] if not override_basepath else override_basepath
return os.path.join(base_path, chroot_name)
def create_chroot(chroot_name, packages=['base'], pacman_conf='/app/local/etc/pacman.conf', extra_repos={}, chroot_base_path: str = None):
chroot_path = get_chroot_path(chroot_name, override_basepath=chroot_base_path)
pacman_conf_target = chroot_path + '/etc/pacman.conf'
os.makedirs(chroot_path + '/etc', exist_ok=True)
@ -29,14 +30,19 @@ def create_chroot(
'-yyuu',
])
if result.returncode != 0:
logging.fatal('Failed to install system')
exit(1)
raise Exception('Failed to install chroot')
return chroot_path
def create_chroot_user(chroot_path):
user = 'kupfer'
password = '123456'
groups = ['network', 'video', 'audio', 'optical', 'storage', 'input', 'scanner', 'games', 'lp', 'rfkill', 'wheel']
def create_chroot_user(
chroot_name,
chroot_base_path: str = None,
user='kupfer',
password='123456',
groups=['network', 'video', 'audio', 'optical', 'storage', 'input', 'scanner', 'games', 'lp', 'rfkill', 'wheel'],
):
chroot_path = get_chroot_path(chroot_name, override_basepath=chroot_base_path)
install_script = '\n'.join([
f'if ! id -u "{user}" >/dev/null 2>&1; then',
f' useradd -m {user}',