home · contact · privacy
Move heredocs into template files. master
authorPlom Heller <plom@plomlompom.com>
Wed, 9 Sep 2026 02:28:09 +0000 (04:28 +0200)
committerPlom Heller <plom@plomlompom.com>
Wed, 9 Sep 2026 02:28:09 +0000 (04:28 +0200)
setup_scripts/_lib.sh
setup_scripts/install_debian.sh
setup_scripts/setup_git_mirror.sh
setup_scripts/start_root_t490s.sh
templates/fstab [new file with mode: 0644]
templates/git-daemon.service [new file with mode: 0644]
templates/update-efi-hook [new file with mode: 0644]
templates/wifi.nmconnection [new file with mode: 0644]

index 3fd20410a6ba8408a9f62fa20b34d259a947cd60..1c917b3a59af8e61aa0c27712caa29300c386690 100644 (file)
@@ -31,6 +31,7 @@ PATH_PARTITION_LUKSVG="${PATH_BOOT_DEVICE}p${IDX_PARTITION_LUKSVG}"
 PATH_PROFILE="${HOME}/${FNAME_PROFILE}"
 PATH_REPO=$(cd .. && pwd)
 NAME_REPO_DIR=$(basename "${PATH_REPO}")
+PATH_TEMPLATES="${PATH_REPO}/templates"
 
 # path constructors
 path_luks_mapper() {
@@ -213,3 +214,12 @@ efi_copy_kernel_vmlinuz() {
         cp "${PREFIX}/${FILENAME}" "${PATH_EFI_NAME_BOOT}/"
     done
 }
+render_template() {
+    local PATH_TEMPLATE=$1
+    # eval'd instead of just `cat`, so ${...}/$(...) inside the template
+    # get expanded against the calling script's own variables, exactly as
+    # if its content were still an inline heredoc in that script.
+    eval "cat <<RENDER_TEMPLATE_EOF
+$(cat "${PATH_TEMPLATE}")
+RENDER_TEMPLATE_EOF"
+}
index e2e560a7889a76edc1c317fa70f329e047112745..de37d295d2860b46127abe5493744a6111e79a46 100755 (executable)
@@ -29,8 +29,12 @@ PATH_MNT_HOSTS="${PATH_MNT_ROOT}${PATH_HOSTS}"
 PATH_MNT_NM_CONN="${PATH_MNT_ROOT}${PATH_NM_CONNECTIONS}/${FNAME_NM_CONN}"
 PATH_MNT_NM_CONNECTIONS="${PATH_MNT_ROOT}${PATH_NM_CONNECTIONS}"
 PATH_VG=$(path_vg "${NAME_LUKSVG}")
+# shellcheck disable=SC2034
+# (used only inside templates/fstab, rendered via render_template)
 PATH_VG_DATA=${PATH_VG}/${NAME_DATA}
 PATH_VG_ROOT=${PATH_VG}/${NAME_ROOT}
+# shellcheck disable=SC2034
+# (used only inside templates/fstab, rendered via render_template)
 PATH_VG_SWAP=${PATH_VG}/${NAME_SWAP}
 
 # sanity checks
@@ -66,11 +70,7 @@ debootstrap "${DEB_SUITE}" "${PATH_MNT_ROOT}"
 rbind_mnt
 
 msg 'Setting up fstab …'
-cat <<EOF >| "${PATH_MNT_FSTAB}"
-${PATH_VG_ROOT} / ext4 errors=remount-ro 0 1
-${PATH_VG_DATA} /${NAME_DATA} ext4 errors=remount-ro 0 2
-${PATH_VG_SWAP} none swap sw 0 0
-EOF
+render_template "${PATH_TEMPLATES}/fstab" >| "${PATH_MNT_FSTAB}"
 
 msg 'Setting up crypttab …'
 printf '%s %s none luks\n' "${NAME_LUKSVG}" "${PATH_PARTITION_LUKSVG}" \
@@ -106,26 +106,7 @@ msg 'Writing NetworkManager connection profile for "%s" …' \
     "${NAME_WIFI_SSID}"
 mkdir -p "${PATH_MNT_NM_CONNECTIONS}"
 chmod 700 "${PATH_MNT_NM_CONNECTIONS}"
-cat <<EOF >| "${PATH_MNT_NM_CONN}"
-[connection]
-id=${NAME_WIFI_SSID}
-uuid=$(cat /proc/sys/kernel/random/uuid)
-type=wifi
-
-[wifi]
-mode=infrastructure
-ssid=${NAME_WIFI_SSID}
-
-[wifi-security]
-key-mgmt=wpa-psk
-psk=${NAME_WIFI_PSK}
-
-[ipv4]
-method=auto
-
-[ipv6]
-method=auto
-EOF
+render_template "${PATH_TEMPLATES}/wifi.nmconnection" >| "${PATH_MNT_NM_CONN}"
 chmod 600 "${PATH_MNT_NM_CONN}"
 
 mkdir "${PATH_EFI_NAME_BOOT}"
index 25f61435cb50641194d3e52cce99e0bd378f4e92..c4e529d2c38ad25d627f8d3df942d15d30724a5b 100755 (executable)
@@ -7,6 +7,7 @@ PATH_GIT_BASE=/srv/git
 # constants derived from changeables
 PATH_GIT_DAEMON_UNIT=/etc/systemd/system/git-daemon.service
 PATH_GIT_MIRROR="${PATH_GIT_BASE}/${NAME_REPO_DIR}.git"
+PATH_TEMPLATE_GIT_DAEMON="${PATH_TEMPLATES}/git-daemon.service"
 
 [ -e "${PATH_GIT_MIRROR}" ]\
     && error "${PATH_GIT_MIRROR} already exists"
@@ -24,20 +25,7 @@ msg 'Own repo to %s so they can update it via ssh …' "${USERNAME}"
 chown -R "${USERNAME}:${USERNAME}" "${PATH_GIT_MIRROR}"
 
 msg 'Writing and enabling git-daemon systemd unit …'
-cat <<EOF >| "${PATH_GIT_DAEMON_UNIT}"
-[Unit]
-Description=Anonymous read-only git daemon
-After=network.target
-
-[Service]
-User=${USERNAME}
-ExecStart=/usr/bin/git daemon --reuseaddr \
-    --base-path=${PATH_GIT_BASE} ${PATH_GIT_BASE}
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
-EOF
+render_template "${PATH_TEMPLATE_GIT_DAEMON}" >| "${PATH_GIT_DAEMON_UNIT}"
 systemctl daemon-reload
 systemctl enable --now git-daemon
 
index ab2244eb3f0ee082409de1a159f00965f7085fd3..9b1a42947a4b4027415c0aef3b973d4aabe90ad9 100755 (executable)
@@ -17,15 +17,14 @@ TLP_THRESH_STOP=80
 
 # constants derived from changeables
 PATH_TO_COPY="${PATH_REPO}/to_copy"
+# shellcheck disable=SC2034
+# (used only inside templates/update-efi-hook, rendered via render_template)
 PATH_UPDATE_EFI_SCRIPT="${PATH_REPO}/setup_scripts/update_efi.sh"
 
 # before any apt-get call gets a chance to pull in a kernel update of its own …
 msg 'Installing initramfs hook to refresh EFI boot files on kernel updates …'
 mkdir -p "$(dirname "${PATH_HOOK_UPDATE_EFI}")"
-cat <<EOF >| "${PATH_HOOK_UPDATE_EFI}"
-#!/bin/sh
-exec "${PATH_UPDATE_EFI_SCRIPT}"
-EOF
+render_template "${PATH_TEMPLATES}/update-efi-hook" >| "${PATH_HOOK_UPDATE_EFI}"
 chmod +x "${PATH_HOOK_UPDATE_EFI}"
 
 start_root t490s
diff --git a/templates/fstab b/templates/fstab
new file mode 100644 (file)
index 0000000..44d6fb4
--- /dev/null
@@ -0,0 +1,3 @@
+${PATH_VG_ROOT} / ext4 errors=remount-ro 0 1
+${PATH_VG_DATA} /${NAME_DATA} ext4 errors=remount-ro 0 2
+${PATH_VG_SWAP} none swap sw 0 0
diff --git a/templates/git-daemon.service b/templates/git-daemon.service
new file mode 100644 (file)
index 0000000..675229c
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Anonymous read-only git daemon
+After=network.target
+
+[Service]
+User=${USERNAME}
+ExecStart=/usr/bin/git daemon --reuseaddr \
+    --base-path=${PATH_GIT_BASE} ${PATH_GIT_BASE}
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/templates/update-efi-hook b/templates/update-efi-hook
new file mode 100644 (file)
index 0000000..ce241f3
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec "${PATH_UPDATE_EFI_SCRIPT}"
diff --git a/templates/wifi.nmconnection b/templates/wifi.nmconnection
new file mode 100644 (file)
index 0000000..99deb5f
--- /dev/null
@@ -0,0 +1,18 @@
+[connection]
+id=${NAME_WIFI_SSID}
+uuid=$(cat /proc/sys/kernel/random/uuid)
+type=wifi
+
+[wifi]
+mode=infrastructure
+ssid=${NAME_WIFI_SSID}
+
+[wifi-security]
+key-mgmt=wpa-psk
+psk=${NAME_WIFI_PSK}
+
+[ipv4]
+method=auto
+
+[ipv6]
+method=auto