commit: 3c6e8b1b99f45bbf710b668a613cec2f46f3030a
parent 9bc2ca1726c71e29c0e07554cb615f813cff4492
Author: fosslinux <fosslinux@aussies.space>
Date: Mon, 30 May 2022 21:42:18 +1000
Merge pull request #174 from stikonas/preseed
Allow preseeding with binary packages.
Diffstat:
5 files changed, 63 insertions(+), 19 deletions(-)
diff --git a/rootfs.py b/rootfs.py
@@ -60,6 +60,8 @@ def main():
parser.add_argument("--no-create-config",
help="Do not automatically create config file",
action="store_true")
+ parser.add_argument("-r", "--repo",
+ help="Path to prebuilt binary packages.", nargs=None)
# QEMU arguments
parser.add_argument("-q", "--qemu", help="Use QEMU",
@@ -137,7 +139,8 @@ print(shutil.which('chroot'))
create_disk_image=False)
system_a.prepare(mount_tmpfs=True,
copy_sysc=True,
- create_initramfs=False)
+ create_initramfs=False,
+ repo_path=args.repo)
# sysa
arch = stage0_arch_map.get(args.arch, args.arch)
diff --git a/sysa.py b/sysa.py
@@ -34,7 +34,7 @@ class SysA(SysGeneral):
self.sysb_dir = sysb_dir
self.sysc_tmp = sysc_tmp
- def prepare(self, mount_tmpfs, copy_sysc, create_initramfs):
+ def prepare(self, mount_tmpfs, copy_sysc, create_initramfs, repo_path):
"""
Prepare directory structure for System A.
We create an empty tmp directory, unpack stage0-posix.
@@ -54,6 +54,10 @@ class SysA(SysGeneral):
if copy_sysc:
self.sysc()
+ if repo_path:
+ repo_dir = os.path.join(self.tmp_dir, 'usr', 'src', 'repo-preseeded')
+ shutil.copytree(repo_path, repo_dir)
+
if create_initramfs:
self.make_initramfs()
diff --git a/sysa/helpers.sh b/sysa/helpers.sh
@@ -73,6 +73,47 @@ _grep() {
fi
}
+get_revision() {
+ local pkg=$1
+ cd "${SRCDIR}/repo"
+ # Get revision (n time this package has been built)
+ revision="$(echo "${pkg}"*)"
+ # Different versions of bash
+ if [ "${revision}" = "${pkg}*" ] || [ -z "${revision}" ]; then
+ revision=0
+ else
+ revision="${revision##*_}"
+ revision="${revision%%.*}"
+ revision=$((++revision))
+ fi
+}
+
+# Installs binary packages from an earlier run
+# This is useful to speed up development cycle
+bin_preseed() {
+ if [ -d "${SRCDIR}/repo-preseeded" ]; then
+ get_revision "${pkg}"
+ cd "${SRCDIR}/repo-preseeded"
+ if src_checksum "${pkg}" $((revision)); then
+ echo "${pkg}: installing prebuilt package."
+ if [[ "${pkg}" == bash-* ]]; then
+ # tar does not like overwriting running bash
+ # shellcheck disable=SC2153
+ rm -f "${PREFIX}/bin/bash" "${PREFIX}/bin/sh"
+ fi
+ mv "${pkg}_${revision}"* ../repo
+ # shellcheck disable=SC2144
+ if [ -f *-repodata ]; then
+ mv -- *-repodata ../repo
+ fi
+ cd "${SRCDIR}/repo"
+ src_apply "${pkg}" $((revision))
+ cd "${SOURCES}"
+ return
+ fi
+ fi
+}
+
# Common build steps
# Build function provides a few common stages with default implementation
# that can be overridden on per package basis in the build script.
@@ -86,6 +127,8 @@ build() {
script_name=${2:-${pkg}.sh}
dirname=${4:-${pkg}}
+ bin_preseed
+
cd "${SOURCES}/${pkg}" || (echo "Cannot cd into ${pkg}!"; kill $$)
echo "${pkg}: beginning build using script ${script_name}"
base_dir="${PWD}"
@@ -126,23 +169,12 @@ build() {
build_stage=src_install
call $build_stage
- cd /usr/src/repo
- # Get revision (n time this package has been built)
- revision="$(echo "${pkg}"*)"
- # Different versions of bash
- if [ "${revision}" = "${pkg}*" ] || [ -z "${revision}" ]; then
- revision=0
- else
- revision="${revision##*_}"
- revision="${revision%%.*}"
- revision=$((++revision))
- fi
-
echo "${pkg}: creating package."
+ get_revision "${pkg}"
cd "${DESTDIR}"
src_pkg
- src_checksum
+ src_checksum "${pkg}" "${revision}"
echo "${pkg}: cleaning up."
rm -rf "${SOURCES}/${pkg}/build"
@@ -150,7 +182,7 @@ build() {
mkdir -p "${DESTDIR}"
echo "${pkg}: installing package."
- src_apply
+ src_apply "${pkg}" "${revision}"
echo "${pkg}: build successful"
@@ -271,17 +303,21 @@ src_pkg() {
}
src_checksum() {
+ local pkg=$1 revision=$2
+ local rval=0
if ! [ "$UPDATE_CHECKSUMS" = True ] ; then
- echo "${pkg}: checksumming created package."
# We avoid using pipes as that is not supported by initial sha256sum from mescc-tools-extra
local checksum_file=/tmp/checksum
_grep "${pkg}_${revision}" "${SOURCES}/SHA256SUMS.pkgs" > "${checksum_file}"
- sha256sum -c "${checksum_file}"
+ echo "${pkg}: checksumming created package."
+ sha256sum -c "${checksum_file}" || rval=$?
rm "${checksum_file}"
fi
+ return "${rval}"
}
src_apply() {
+ local pkg="${1}" revision="${2}"
if command -v xbps-install >/dev/null 2>&1; then
xbps-install -y -R /usr/src/repo "${pkg%%-[0-9]*}"
else
diff --git a/sysc/init b/sysc/init
@@ -14,6 +14,7 @@ export PREFIX=/usr
export SOURCES=/usr/src
export DESTDIR=/tmp/destdir
export DISTFILES=/distfiles
+export SRCDIR="${SOURCES}"
echo
echo "Installing packages into sysc"
diff --git a/sysc/run.sh b/sysc/run.sh
@@ -31,4 +31,4 @@ create_fhs
build bash-5.1
-exec env -i PATH="${PATH}" PREFIX="${PREFIX}" SOURCES="${SOURCES}" DESTDIR="${DESTDIR}" DISTFILES="${DISTFILES}" bash run2.sh
+exec env -i PATH="${PATH}" PREFIX="${PREFIX}" SOURCES="${SOURCES}" DESTDIR="${DESTDIR}" DISTFILES="${DISTFILES}" SRCDIR="${SRCDIR}" bash run2.sh