Apply formatting

This commit is contained in:
jld3103 2021-08-08 18:32:42 +02:00
parent 8b943a903a
commit 98040d8a31
10 changed files with 375 additions and 232 deletions

View file

@ -4,27 +4,30 @@ import os
import shutil
def create_chroot(chroot_path, packages=['base'], pacman_conf='/app/local/etc/pacman.conf', chroot_base_path='/chroot', extra_repos={}):
pacman_conf_target = chroot_path+'/etc/pacman.conf'
def create_chroot(
chroot_path,
packages=['base'],
pacman_conf='/app/local/etc/pacman.conf',
chroot_base_path='/chroot',
extra_repos={},
):
pacman_conf_target = chroot_path + '/etc/pacman.conf'
os.makedirs(chroot_path+'/etc', exist_ok=True)
os.makedirs(chroot_path + '/etc', exist_ok=True)
shutil.copyfile(pacman_conf, pacman_conf_target)
extra_conf = ''
for repo_name, repo_options in extra_repos.items():
extra_conf += f'\n\n[{repo_name}]\n'
extra_conf += '\n'.join(['%s = %s' % (name, value)
for name, value in repo_options.items()])
extra_conf += '\n'.join(['%s = %s' % (name, value) for name, value in repo_options.items()])
with open(pacman_conf_target, 'a') as file:
file.write(extra_conf)
result = subprocess.run(['pacstrap',
'-C', pacman_conf_target,
'-c',
'-G',
chroot_path]
+ packages
+ ['--needed', '--overwrite=*', '-yyuu'])
result = subprocess.run(['pacstrap', '-C', pacman_conf_target, '-c', '-G', chroot_path] + packages + [
'--needed',
'--overwrite=*',
'-yyuu',
])
if result.returncode != 0:
logging.fatal('Failed to install system')
exit(1)
@ -33,8 +36,7 @@ def create_chroot(chroot_path, packages=['base'], pacman_conf='/app/local/etc/pa
def create_chroot_user(chroot_path):
user = 'kupfer'
password = '123456'
groups = ['network', 'video', 'audio', 'optical', 'storage',
'input', 'scanner', 'games', 'lp', 'rfkill', 'wheel']
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}',
@ -43,11 +45,13 @@ def create_chroot_user(chroot_path):
f'echo "{user}:{password}" | chpasswd',
f'chown {user}:{user} /home/{user} -R',
])
result = subprocess.run(['arch-chroot',
chroot_path,
'/bin/bash',
'-c',
install_script])
result = subprocess.run([
'arch-chroot',
chroot_path,
'/bin/bash',
'-c',
install_script,
])
if result.returncode != 0:
logging.fatal('Failed to setup user')
exit(1)