Skip to content

Commit

Permalink
mkosi: shellcheck clean, add apt for deb builds (#871)
Browse files Browse the repository at this point in the history
* mkosi: add 'apt' to system-packages

mkosi v14 will run 'apt' from the host, rather than inside the guest
via nspawn, so add it to the system dependencies

* mkosi: make recipe shellcheck-happy
  • Loading branch information
bluca authored Sep 19, 2022
1 parent d87d96e commit 7aac08d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ my %subst_defaults = (
'veritysetup', 'tar', 'xz', 'xfsprogs', 'zstd', 'zypper',
],
'system-packages:mkosi:deb' => [
'mkosi', 'btrfs-progs', 'cpio', 'cryptsetup-bin', 'dctrl-tools',
'mkosi', 'apt', 'btrfs-progs', 'cpio', 'cryptsetup-bin', 'dctrl-tools',
'debootstrap', 'debconf', 'dosfstools', 'dpkg-dev', 'e2fsprogs', 'fdisk',
'gnupg', 'linux-base', 'lsb-release', 'python3-cryptography',
'squashfs-tools', 'systemd-container', 'tar', 'xz-utils', 'xfsprogs',
Expand Down
21 changes: 11 additions & 10 deletions build-recipe-mkosi
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ recipe_setup_mkosi() {
for i in OTHER SOURCES ; do
mkdir -p "$BUILD_ROOT$TOPDIR/$i"
done
if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
if test "$MYSRCDIR" = "$BUILD_ROOT/.build-srcdir" ; then
mv "$MYSRCDIR"/* "$BUILD_ROOT$TOPDIR/SOURCES/"
else
copy_sources "$MYSRCDIR" "$BUILD_ROOT$TOPDIR/SOURCES/"
#cp -r "$MYSRCDIR/mkosi.cache" "$BUILD_ROOT$TOPDIR/SOURCES/"
Expand All @@ -43,21 +43,21 @@ recipe_prepare_mkosi() {
recipe_build_mkosi() {
local ARCH DIST RELEASE_ARG
if [ -x "$BUILD_ROOT/bin/rpm" ]; then
ARCH=$(chroot $BUILD_ROOT sh -c "rpm --eval '%{_target_cpu}'")
ARCH=$(chroot "$BUILD_ROOT" sh -c "rpm --eval '%{_target_cpu}'")
elif [ -x "$BUILD_ROOT/usr/bin/dpkg-architecture" ]; then
ARCH=$(chroot $BUILD_ROOT sh -c "dpkg-architecture -qDEB_BUILD_ARCH")
ARCH=$(chroot "$BUILD_ROOT" sh -c "dpkg-architecture -qDEB_BUILD_ARCH")
# The distro release is usually specified in the recipe, but it is not mandatory.
DIST=$(grep Release= "${RECIPEFILE}" | sed "s/\s*Release\s*=\s*\(.*\)\s*/\1/")
if [ -z "$DIST" ]; then
DIST=$(chroot $BUILD_ROOT sh -c "lsb_release --codename" | awk '{ print $2 }')
DIST=$(chroot "$BUILD_ROOT" sh -c "lsb_release --codename" | awk '{ print $2 }')
fi

# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=845651
# For our use case it makes sense to always return the testing codename. In
# the example cited in the above bug, the metadata for sid would be incorrect
# anyway, and we would want the ones for potato.
if test "${DIST}" = "n/a" ; then
DIST=$(chroot $BUILD_ROOT sh -c "sed 's/\(.*\)\/.*/\1/' /etc/debian_version")
DIST=$(chroot "$BUILD_ROOT" sh -c "sed 's/\(.*\)\/.*/\1/' /etc/debian_version")
fi

# Pass it to mkosi, so that the configured mirror is the same as the repository created below
Expand All @@ -68,12 +68,12 @@ recipe_build_mkosi() {
cleanup_and_exit 1
fi

test -d $BUILD_ROOT/.build.binaries || cleanup_and_exit 1 "missing $BUILD_ROOT/.build.binaries"
test -d "$BUILD_ROOT/.build.binaries" || cleanup_and_exit 1 "missing $BUILD_ROOT/.build.binaries"

if test "$DO_INIT" = true; then
if [ -x "$BUILD_ROOT/usr/bin/dpkg-architecture" ] && [ ! -d "$BUILD_ROOT/.build.binaries/dists" ]; then
echo "creating debian repository metadata..."
createrepo_debian $BUILD_ROOT/.build.binaries ${ARCH} ${DIST}
createrepo_debian "$BUILD_ROOT/.build.binaries" "${ARCH}" "${DIST}"
elif [ -x "$BUILD_ROOT/bin/rpm" ] && [ ! -d "$BUILD_ROOT/.build.binaries/repodata" ]; then
echo "creating rpm repository metadata..."
if chroot "$BUILD_ROOT" test -x /usr/bin/createrepo_c; then
Expand All @@ -85,15 +85,15 @@ recipe_build_mkosi() {
fi
elif [ -x "$BUILD_ROOT/usr/bin/repo-add" ]; then
echo "creating Arch Linux repository metadata..."
chroot $BUILD_ROOT sh -c "repo-add /.build.binaries/core.db.tar.gz /.build.binaries/*"
chroot "$BUILD_ROOT" sh -c "repo-add /.build.binaries/core.db.tar.gz /.build.binaries/*"
fi
fi

local image_version=""
if [ -n "$RELEASE" ]; then
image_version="--image-version=${RELEASE}"
fi
chroot $BUILD_ROOT sh -c \
chroot "$BUILD_ROOT" sh -c \
"cd $TOPDIR/SOURCES && mkosi --default $RECIPEFILE $RELEASE_ARG $image_version --nspawn-keep-unit --output-dir $TOPDIR/OTHER --checksum --repository-key-check=no --with-network=never --local-mirror file:///.build.binaries/ --cache /.build.binaries/ build" \
|| cleanup_and_exit 1

Expand All @@ -114,6 +114,7 @@ recipe_build_mkosi() {
# compress the manifest file which can be quite large
gzip -9 -f "$BUILD_ROOT/$TOPDIR/OTHER/"*.manifest

# shellcheck disable=SC2034
BUILD_SUCCEEDED=true
}

Expand Down

0 comments on commit 7aac08d

Please sign in to comment.