summaryrefslogtreecommitdiff
path: root/stage2/04-cloud-init/01-run.sh
diff options
context:
space:
mode:
authorpaulober <44974737+paulober@users.noreply.github.com>2025-08-28 15:28:59 +0100
committerXECDesign <XECDesign@users.noreply.github.com>2025-09-30 08:30:20 +0100
commit372e56363338c0dd2f5bc5fa5f2e4d147685b23d (patch)
treeea9c5d4a119e6469f48556029e5c21f654d289ae /stage2/04-cloud-init/01-run.sh
parent734e1a634912d73d31f407b3668ed00e5f2e7609 (diff)
Add cloud-init support
Signed-off-by: paulober <44974737+paulober@users.noreply.github.com>
Diffstat (limited to 'stage2/04-cloud-init/01-run.sh')
-rwxr-xr-xstage2/04-cloud-init/01-run.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/stage2/04-cloud-init/01-run.sh b/stage2/04-cloud-init/01-run.sh
new file mode 100755
index 0000000..e4b8c64
--- /dev/null
+++ b/stage2/04-cloud-init/01-run.sh
@@ -0,0 +1,28 @@
+#!/bin/bash -e
+
+if [ "${ENABLE_CLOUD_INIT}" != "1" ]; then
+ log "Skipping cloud-init stage"
+ exit 0
+fi
+
+install -v -D -m 644 -t "${ROOTFS_DIR}/etc/cloud/cloud.cfg.d/" files/99_raspberry-pi.cfg
+
+# some preseeding without any runtime effect yet
+# install meta-data file for NoCloud data-source to work
+install -v -m 755 files/meta-data "${ROOTFS_DIR}/boot/firmware/meta-data"
+install -v -m 755 files/user-data "${ROOTFS_DIR}/boot/firmware/user-data"
+install -v -m 755 files/network-config "${ROOTFS_DIR}/boot/firmware/network-config"
+
+# setup default netplan config which will instruct netplan to pass control over to network-manager
+# at boot time. This will make NetworkManager manage all devices and by default.
+# Any Ethernet device will come up with DHCP, once carrier is detected
+install -v -D -m 600 -t "${ROOTFS_DIR}/lib/netplan/" files/00-network-manager-all.yaml
+
+if [ -n "${FIRST_USER_NAME}" ]; then
+ # set the default user name to the one provided via FIRST_USER_NAME
+ # this will make cloud-init create the user with that name instead of 'pi'
+ sed -i "s/name: pi/name: ${FIRST_USER_NAME}/" "${ROOTFS_DIR}/etc/cloud/cloud.cfg"
+else
+ # remove the users:\n - default section from cloud.cfg
+ sed -i "/^users:/,/^- default/d" "${ROOTFS_DIR}/etc/cloud/cloud.cfg"
+fi