From e95e00f879e24c0f087763ec471fb9bdf9a8f92b Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Mon, 13 May 2024 15:24:21 +0100 Subject: [PATCH 1/2] Set a default IMG_NAME This also adds the 'ARCH' environment variable, which will help reduce the delta between master and arm64 branches. --- README.md | 2 +- build.sh | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c48e708..c584825 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ environment variables. The following environment variables are supported: - * `IMG_NAME` **required** (Default: unset) + * `IMG_NAME` (Default: raspios-$RELEASE-$ARCH, for example: "raspios-bookworm-armhf") The name of the image to build with the current stage directories. Use this variable to set the root name of your OS, eg `IMG_NAME=Frobulator`. diff --git a/build.sh b/build.sh index 054b3f5..3cb10e7 100755 --- a/build.sh +++ b/build.sh @@ -167,10 +167,9 @@ export PI_GEN=${PI_GEN:-pi-gen} export PI_GEN_REPO=${PI_GEN_REPO:-https://github.com/RPi-Distro/pi-gen} export PI_GEN_RELEASE=${PI_GEN_RELEASE:-Raspberry Pi reference} -if [ -z "${IMG_NAME}" ]; then - echo "IMG_NAME not set" 1>&2 - exit 1 -fi +export ARCH=armhf +export RELEASE=${RELEASE:-bookworm} # Don't forget to update stage0/prerun.sh +export IMG_NAME="${IMG_NAME:-raspios-$RELEASE-$ARCH}" export USE_QEMU="${USE_QEMU:-0}" export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}" @@ -198,7 +197,6 @@ export TARGET_HOSTNAME=${TARGET_HOSTNAME:-raspberrypi} export FIRST_USER_NAME=${FIRST_USER_NAME:-pi} export FIRST_USER_PASS export DISABLE_FIRST_BOOT_USER_RENAME=${DISABLE_FIRST_BOOT_USER_RENAME:-0} -export RELEASE=${RELEASE:-bookworm} # Don't forget to update stage0/prerun.sh export WPA_COUNTRY export ENABLE_SSH="${ENABLE_SSH:-0}" export PUBKEY_ONLY_SSH="${PUBKEY_ONLY_SSH:-0}" @@ -215,7 +213,6 @@ export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"} export PUBKEY_SSH_FIRST_USER export CLEAN -export IMG_NAME export APT_PROXY export STAGE From d87f764fcbc2e9bdbfd407d2cbf9b5faf5600df1 Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Mon, 13 May 2024 15:54:28 +0100 Subject: [PATCH 2/2] build.sh: Warn user of unsupported build environment architecture and fail early if binfmt_misc isn't working as expected --- Dockerfile | 4 ++-- README.md | 2 +- build.sh | 9 +++++++++ depends | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 673f756..0e6d86d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,8 +7,8 @@ RUN apt-get -y update && \ apt-get -y install --no-install-recommends \ git vim parted \ quilt coreutils qemu-user-static debootstrap zerofree zip dosfstools \ - libarchive-tools libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc\ - binfmt-support ca-certificates fdisk gpg pigz\ + libarchive-tools libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc \ + binfmt-support ca-certificates fdisk gpg pigz arch-test \ && rm -rf /var/lib/apt/lists/* COPY . /pi-gen/ diff --git a/README.md b/README.md index c584825..279baaa 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ To install the required dependencies for `pi-gen` you should run: ```bash apt-get install coreutils quilt parted qemu-user-static debootstrap zerofree zip \ dosfstools libarchive-tools libcap2-bin grep rsync xz-utils file git curl bc \ -gpg pigz xxd +gpg pigz xxd arch-test ``` The file `depends` contains a list of tools needed. The format of this diff --git a/build.sh b/build.sh index 3cb10e7..d094eee 100755 --- a/build.sh +++ b/build.sh @@ -244,6 +244,15 @@ fi dependencies_check "${BASE_DIR}/depends" +echo "Checking native $ARCH executable support..." +if ! arch-test -n "$ARCH"; then + echo "WARNING: Only a native build environment is supported. Checking emulated support..." + if ! arch-test "$ARCH"; then + echo "No fallback mechanism found. Ensure your OS has binfmt_misc support enabled and configured." + exit 1 + fi +fi + #check username is valid if [[ ! "$FIRST_USER_NAME" =~ ^[a-z][-a-z0-9_]*$ ]]; then echo "Invalid FIRST_USER_NAME: $FIRST_USER_NAME" diff --git a/depends b/depends index 10fcdd4..acbb5cd 100644 --- a/depends +++ b/depends @@ -19,3 +19,4 @@ lsmod:kmod bc gpg pigz +arch-test