mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 05:35:44 -05:00
provide /bin/pacman_aarch64 wrapper script, chroot: handle extra repos in pacman.conf
Signed-off-by: InsanePrawn <insane.prawny@gmail.com>
This commit is contained in:
parent
1364a97ddb
commit
cde685f06e
5 changed files with 46 additions and 53 deletions
|
@ -18,7 +18,6 @@ RUN cd /tmp && \
|
|||
RUN yes | pacman -Scc
|
||||
|
||||
RUN sed -i "s/SigLevel.*/SigLevel = Never/g" /etc/pacman.conf
|
||||
RUN sed -i "s|run_pacman |run_pacman --root \"/chroot/copy\" --arch aarch64 --config \"/app/src/pacman_copy.conf\" |g" $(which makepkg)
|
||||
RUN mkdir -p /app/bin
|
||||
RUN ln -sf $(which aarch64-linux-gnu-strip) /app/bin/strip
|
||||
|
||||
|
|
4
bin/pacman_aarch64
Executable file
4
bin/pacman_aarch64
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
PACMAN_CHROOT="${PACMAN_CHROOT:-/chroot/copy}"
|
||||
|
||||
exec pacman --root "$PACMAN_CHROOT" --arch aarch64 --config "$PACMAN_CHROOT"/etc/pacman.conf "$@"
|
19
chroot.py
19
chroot.py
|
@ -1,9 +1,24 @@
|
|||
import logging
|
||||
import subprocess
|
||||
import os
|
||||
import shutil
|
||||
|
||||
def create_chroot(chroot_path, packages=['base'], pacman_conf='/app/src/pacman.conf', chroot_base_path='/chroot', extra_repos={}):
|
||||
pacman_conf_target=chroot_path+'/etc/pacman.conf'
|
||||
|
||||
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()])
|
||||
with open(pacman_conf_target, 'a') as file:
|
||||
file.write(extra_conf)
|
||||
|
||||
|
||||
def create_chroot(chroot_path, packages=['base'], pacman_conf='/app/src/pacman.conf'):
|
||||
result = subprocess.run(['pacstrap',
|
||||
'-C', pacman_conf,
|
||||
'-C', pacman_conf_target,
|
||||
'-c',
|
||||
'-G',
|
||||
chroot_path]
|
||||
|
|
9
image.py
9
image.py
|
@ -117,13 +117,6 @@ def cmd_build(verbose):
|
|||
device, flavour = get_device_and_flavour()
|
||||
image_name = get_image_name(device, flavour)
|
||||
|
||||
shutil.copyfile('/app/src/pacman.conf', '/app/src/pacman_copy.conf')
|
||||
with open('/app/src/pacman_copy.conf', 'a') as file:
|
||||
file.write(
|
||||
'\n\n[main]\nServer = https://gitlab.com/kupfer/packages/prebuilts/-/raw/main/$repo')
|
||||
file.write(
|
||||
'\n\n[device]\nServer = https://gitlab.com/kupfer/packages/prebuilts/-/raw/main/$repo')
|
||||
|
||||
if not os.path.exists(image_name):
|
||||
result = subprocess.run(['fallocate',
|
||||
'-l', '4G',
|
||||
|
@ -141,7 +134,7 @@ def cmd_build(verbose):
|
|||
|
||||
rootfs_mount = mount_rootfs_image(image_name)
|
||||
|
||||
create_chroot(rootfs_mount, packages=(['base','base-kupfer'] + devices[device] + flavours[flavour]), pacman_conf='/app/src/pacman_copy.conf')
|
||||
create_chroot(rootfs_mount, packages=(['base','base-kupfer'] + devices[device] + flavours[flavour]), pacman_conf='/app/src/pacman.conf', extra_repos={'main': {'Server': 'https://gitlab.com/kupfer/packages/prebuilts/-/raw/main/$repo'}, 'device': {'Server': 'https://gitlab.com/kupfer/packages/prebuilts/-/raw/main/$repo'}})
|
||||
|
||||
|
||||
"""
|
||||
|
|
66
packages.py
66
packages.py
|
@ -6,12 +6,17 @@ import multiprocessing
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from chroot import create_chroot
|
||||
|
||||
makepkg_env = os.environ.copy() | {
|
||||
'LANG': 'C',
|
||||
'MAKEFLAGS': f'-j{multiprocessing.cpu_count()}',
|
||||
}
|
||||
|
||||
makepkg_cross_env = makepkg_env | {
|
||||
'PACMAN': '/app/bin/pacman_aarch64'
|
||||
}
|
||||
|
||||
makepkg_cmd = ['makepkg',
|
||||
'--config', '/app/src/makepkg.conf',
|
||||
'--noconfirm',
|
||||
|
@ -93,41 +98,16 @@ def check_prebuilts():
|
|||
exit(1)
|
||||
|
||||
|
||||
def setup_chroot():
|
||||
if not os.path.exists('/chroot/root'):
|
||||
logging.info('Initializing root chroot')
|
||||
result = subprocess.run(['mkarchroot',
|
||||
'-s',
|
||||
'-C', '/app/src/pacman.conf',
|
||||
'-f', '/etc/locale.gen',
|
||||
'/chroot/root',
|
||||
'base-devel'])
|
||||
if result.returncode != 0:
|
||||
logging.fatal('Failed to initialize root chroot')
|
||||
shutil.rmtree('/chroot/root')
|
||||
exit(1)
|
||||
else:
|
||||
logging.info('Updating root chroot')
|
||||
result = subprocess.run(pacman_cmd +
|
||||
['-Syuu',
|
||||
'--root', '/chroot/root',
|
||||
'--arch', 'aarch64',
|
||||
'--config', '/app/src/pacman.conf'])
|
||||
if result.returncode != 0:
|
||||
logging.fatal('Failed to update root chroot')
|
||||
exit(1)
|
||||
def setup_chroot(chroot_path='/chroot/root'):
|
||||
logging.info('Initializing root chroot')
|
||||
create_chroot(chroot_path, packages=['base-devel'], pacman_conf='/app/src/pacman.conf', extra_repos={'main': {'Server': 'file:///src/prebuilts/main'}, 'device': {'Server': 'file:///src/prebuilts/device'}})
|
||||
|
||||
shutil.copyfile('/app/src/pacman.conf', '/app/src/pacman_copy.conf')
|
||||
with open('/app/src/pacman_copy.conf', 'a') as file:
|
||||
file.write('\n\n[main]\nServer = file:///src/prebuilts/main')
|
||||
file.write('\n\n[device]\nServer = file:///src/prebuilts/device')
|
||||
shutil.copyfile('/app/src/pacman_copy.conf',
|
||||
'/chroot/root/etc/pacman.conf')
|
||||
logging.info('Updating root chroot')
|
||||
result = subprocess.run(pacman_cmd +
|
||||
['-Sy',
|
||||
'--root', '/chroot/root',
|
||||
['-Syuu',
|
||||
'--root', chroot_path,
|
||||
'--arch', 'aarch64',
|
||||
'--config', '/chroot/root/etc/pacman.conf'])
|
||||
'--config', chroot_path+'/etc/pacman.conf'])
|
||||
if result.returncode != 0:
|
||||
logging.fatal('Failed to update root chroot')
|
||||
exit(1)
|
||||
|
@ -219,7 +199,7 @@ def update_package_version_and_sources(package: Package):
|
|||
cmd.append('--noextract')
|
||||
logging.info(f'Updating package version for {package.path}')
|
||||
result = subprocess.run(cmd,
|
||||
env=makepkg_env,
|
||||
env=makepkg_cross_env,
|
||||
cwd=package.path)
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to update package version for {package.path}')
|
||||
|
@ -233,7 +213,7 @@ def check_package_version_built(package: Package) -> bool:
|
|||
['--nobuild',
|
||||
'--noprepare',
|
||||
'--packagelist'],
|
||||
env=makepkg_env,
|
||||
env=makepkg_cross_env,
|
||||
cwd=package.path,
|
||||
capture_output=True)
|
||||
if result.returncode != 0:
|
||||
|
@ -258,17 +238,21 @@ def setup_dependencies_and_sources(package: Package):
|
|||
"""
|
||||
if package.mode == 'cross':
|
||||
for p in package.depends:
|
||||
subprocess.run(pacman_cmd + ['-S', p], stderr=subprocess.DEVNULL)
|
||||
result = subprocess.run(pacman_cmd + ['-S', p], stderr=subprocess.DEVNULL)
|
||||
if result.returncode != 0:
|
||||
logging.fatal(
|
||||
f'Failed to setup dependencies for {package.path}')
|
||||
exit(1)
|
||||
|
||||
result = subprocess.run(makepkg_cmd +
|
||||
['--nobuild',
|
||||
'--holdver',
|
||||
'--syncdeps'],
|
||||
env=makepkg_env,
|
||||
env=makepkg_cross_env,
|
||||
cwd=package.path)
|
||||
if result.returncode != 0:
|
||||
logging.fatal(
|
||||
f'Failed to setup dependencies and sources for {package.path}')
|
||||
f'Failed to check sources for {package.path}')
|
||||
exit(1)
|
||||
|
||||
|
||||
|
@ -281,7 +265,7 @@ def build_package(package: Package):
|
|||
if package.mode == 'cross':
|
||||
logging.info(f'Cross-compiling {package.path}')
|
||||
result = subprocess.run(makepkg_cmd+makepkg_compile_opts,
|
||||
env=makepkg_env | {
|
||||
env=makepkg_cross_env | {
|
||||
'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'},
|
||||
cwd=package.path)
|
||||
if result.returncode != 0:
|
||||
|
@ -310,11 +294,9 @@ def build_package(package: Package):
|
|||
f'Failed to bind mount folder to chroot')
|
||||
exit(1)
|
||||
|
||||
env = []
|
||||
for key in makepkg_env:
|
||||
env.append(f'{key}={makepkg_env[key]}')
|
||||
env = [f'{key}={value}' for key, value in makepkg_env.items()]
|
||||
result = subprocess.run(
|
||||
['arch-chroot', '/chroot/copy', '/bin/bash', '-c', f'cd /src/{package.path} && {" ".join(env)} makepkg --noconfirm --ignorearch {" ".join(makepkg_compile_opts)}'])
|
||||
['arch-chroot', '/chroot/copy', '/usr/bin/env'] + env + [ '/bin/bash', '-c', f'cd /src/{package.path} && makepkg --noconfirm --ignorearch {" ".join(makepkg_compile_opts)}'])
|
||||
if result.returncode != 0:
|
||||
logging.fatal(f'Failed to host-compile package {package.path}')
|
||||
exit(1)
|
||||
|
|
Loading…
Add table
Reference in a new issue