diff --git a/README.md b/README.md index 439c69097c..fa71fc2f96 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,10 @@ The following environment variables are supported: If set, then instead of working through the numeric stages in order, this list will be followed. For example setting to `"stage0 stage1 mystage stage2"` will run the contents of `mystage` before stage2. Note that quotes are needed around the list. An absolute or relative path can be given for stages outside the pi-gen directory. + * `ENABLE_CLOUD_INIT` (Default: `1`) + + If set to `1`, cloud-init and netplan will be installed and configured. This will allow you to configure your Raspberry Pi using cloud-init configuration files. The cloud-init configuration files should be placed in the bootfs or by editing the files in `stage2/04-cloud-init/files`. Cloud-init will be configured to read them on first boot. + A simple example for building Raspberry Pi OS: ```bash diff --git a/build.sh b/build.sh index 78effd044d..f2496491bd 100755 --- a/build.sh +++ b/build.sh @@ -243,6 +243,8 @@ export QUILT_NO_DIFF_INDEX=1 export QUILT_NO_DIFF_TIMESTAMPS=1 export QUILT_REFRESH_ARGS="-p ab" +export ENABLE_CLOUD_INIT=${ENABLE_CLOUD_INIT:-1} + # shellcheck source=scripts/common source "${SCRIPT_DIR}/common" # shellcheck source=scripts/dependencies_check diff --git a/export-image/01-user-rename/01-run.sh b/export-image/01-user-rename/01-run.sh index aa5dd94102..5897e5b212 100755 --- a/export-image/01-user-rename/01-run.sh +++ b/export-image/01-user-rename/01-run.sh @@ -1,9 +1,21 @@ #!/bin/bash -e if [[ "${DISABLE_FIRST_BOOT_USER_RENAME}" == "0" ]]; then + # with cloud-init enabled this will throw an error + # when run more than once, as the service will be deleted on_chroot <<- EOF SUDO_USER="${FIRST_USER_NAME}" rename-user -f -s EOF + + # delete userconfig service as cloud-init will take care of launching it + rm -f "${ROOTFS_DIR}/lib/systemd/system/userconfig.service" else rm -f "${ROOTFS_DIR}/etc/xdg/autostart/piwiz.desktop" + + # if cloud-init enabled disable setup wizard launch completely + if [[ "${ENABLE_CLOUD_INIT}" == "1" ]]; then + on_chroot <<- EOF + touch /var/lib/userconf-pi/deactivate + EOF + fi fi diff --git a/stage2/01-sys-tweaks/01-run.sh b/stage2/01-sys-tweaks/01-run.sh index 897463e6df..8ebe1dbe36 100755 --- a/stage2/01-sys-tweaks/01-run.sh +++ b/stage2/01-sys-tweaks/01-run.sh @@ -1,13 +1,17 @@ #!/bin/bash -e -install -m 755 files/resize2fs_once "${ROOTFS_DIR}/etc/init.d/" +if [ "${ENABLE_CLOUD_INIT}" != "1" ]; then + # if cloud-init is enabled, it will take care of resizing the rootfs + install -m 755 files/resize2fs_once "${ROOTFS_DIR}/etc/init.d/" +fi + +# TODO: move into conditional block above when cloud-init adds support for commands in final message +install -m 755 files/rc.local "${ROOTFS_DIR}/etc/" install -m 644 files/50raspi "${ROOTFS_DIR}/etc/apt/apt.conf.d/" install -m 644 files/console-setup "${ROOTFS_DIR}/etc/default/" -install -m 755 files/rc.local "${ROOTFS_DIR}/etc/" - if [ -n "${PUBKEY_SSH_FIRST_USER}" ]; then install -v -m 0700 -o 1000 -g 1000 -d "${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh echo "${PUBKEY_SSH_FIRST_USER}" >"${ROOTFS_DIR}"/home/"${FIRST_USER_NAME}"/.ssh/authorized_keys @@ -39,10 +43,6 @@ if [ "${USE_QEMU}" = "1" ]; then systemctl disable resize2fs_once EOF echo "leaving QEMU mode" -else - on_chroot << EOF -systemctl enable resize2fs_once -EOF fi on_chroot <