From d8118e0fce37f9be4dba39680f6cb2bd43a96988 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 26 Jul 2025 07:20:01 -0500 Subject: [PATCH] autoprovision: split script+unit into separate files Now that we're using Jinja to render the kickstart scripts, we can separate out scripts, systemd unit files, etc. into their own files and `include` them. This makes editing them much easier, especially since syntax highlighting will work correctly. --- autoprovision.ks.j2 | 16 ++++++++++++++ fedora-rpi.ks.j2 | 2 +- fedora.ks.j2 | 2 +- autoprovision.ks => notify-online.service | 27 ----------------------- notify-online.sh | 13 +++++++++++ 5 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 autoprovision.ks.j2 rename autoprovision.ks => notify-online.service (57%) create mode 100644 notify-online.sh diff --git a/autoprovision.ks.j2 b/autoprovision.ks.j2 new file mode 100644 index 0000000..b10b98c --- /dev/null +++ b/autoprovision.ks.j2 @@ -0,0 +1,16 @@ +%post +cat > /root/.ssh/authorized_keys < /usr/local/libexec/notify-online.sh <<'EOF' +{% include "notify-online.sh" %} +EOF +chmod +x /usr/local/libexec/notify-online.sh + +cat > /etc/systemd/system/notify-online.service <<'EOF' +{% include "notify-online.service" %} +EOF + +systemctl enable --no-reload notify-online.service +%end diff --git a/fedora-rpi.ks.j2 b/fedora-rpi.ks.j2 index 663da86..b5d5453 100644 --- a/fedora-rpi.ks.j2 +++ b/fedora-rpi.ks.j2 @@ -2,4 +2,4 @@ ignoredisk --only-use /dev/mmcblk0 {% include "fedora-disk-dch.ks" %} {% include "fedora-rpi-common.ks.j2" %} -{% include "autoprovision.ks" %} +{% include "autoprovision.ks.j2" %} diff --git a/fedora.ks.j2 b/fedora.ks.j2 index a968b53..efb3e23 100644 --- a/fedora.ks.j2 +++ b/fedora.ks.j2 @@ -16,4 +16,4 @@ qemu-guest-agent -fwupd %end -{% include "autoprovision.ks" %} +{% include "autoprovision.ks.j2" %} diff --git a/autoprovision.ks b/notify-online.service similarity index 57% rename from autoprovision.ks rename to notify-online.service index 9727a9b..6ebc36d 100644 --- a/autoprovision.ks +++ b/notify-online.service @@ -1,26 +1,3 @@ -%post -cat > /root/.ssh/authorized_keys < /usr/local/libexec/notify-online.sh <<'EOF' -#!/bin/sh - -set -- \ - -F "hostname=$(hostname -f)" \ - -F 'sshkeys=<-;type=text/plain' - -fw_cfg=/sys/firmware/qemu_fw_cfg/by_name/opt/dch/cfg-branch/raw -if [ -r "${fw_cfg}" ]; then - set -- "$@" -F branch="$(cat "${fw_cfg}")" -fi - -cat /etc/ssh/ssh_host_*_key.pub \ -| curl -fsS https://webhooks.pyrocufflink.blue/host/online "$@" -EOF -chmod +x /usr/local/libexec/notify-online.sh - -cat > /etc/systemd/system/notify-online.service <<'EOF' [Unit] Description=Notify infrastructure services that this host is online ConditionFirstBoot=yes @@ -63,7 +40,3 @@ SystemCallFilter=~@privileged @resources [Install] WantedBy=multi-user.target -EOF - -systemctl enable --no-reload notify-online.service -%end diff --git a/notify-online.sh b/notify-online.sh new file mode 100644 index 0000000..24fa5e3 --- /dev/null +++ b/notify-online.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -- \ + -F "hostname=$(hostname -f)" \ + -F 'sshkeys=<-;type=text/plain' + +fw_cfg=/sys/firmware/qemu_fw_cfg/by_name/opt/dch/cfg-branch/raw +if [ -r "${fw_cfg}" ]; then + set -- "$@" -F branch="$(cat "${fw_cfg}")" +fi + +cat /etc/ssh/ssh_host_*_key.pub \ + | curl -fsS https://webhooks.pyrocufflink.blue/host/online "$@"