From: Plom Heller Date: Wed, 9 Sep 2026 02:28:09 +0000 (+0200) Subject: Move heredocs into template files. X-Git-Url: https://plomlompom.com/repos/foo.html?a=commitdiff_plain;h=732d505b153d302f17744bb8c1fe37cb17a15f1c;p=confplom Move heredocs into template files. --- diff --git a/setup_scripts/_lib.sh b/setup_scripts/_lib.sh index 3fd2041..1c917b3 100644 --- a/setup_scripts/_lib.sh +++ b/setup_scripts/_lib.sh @@ -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 <| "${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 <| "${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}" diff --git a/setup_scripts/setup_git_mirror.sh b/setup_scripts/setup_git_mirror.sh index 25f6143..c4e529d 100755 --- a/setup_scripts/setup_git_mirror.sh +++ b/setup_scripts/setup_git_mirror.sh @@ -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 <| "${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 diff --git a/setup_scripts/start_root_t490s.sh b/setup_scripts/start_root_t490s.sh index ab2244e..9b1a429 100755 --- a/setup_scripts/start_root_t490s.sh +++ b/setup_scripts/start_root_t490s.sh @@ -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 <| "${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 index 0000000..44d6fb4 --- /dev/null +++ b/templates/fstab @@ -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 index 0000000..675229c --- /dev/null +++ b/templates/git-daemon.service @@ -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 index 0000000..ce241f3 --- /dev/null +++ b/templates/update-efi-hook @@ -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 index 0000000..99deb5f --- /dev/null +++ b/templates/wifi.nmconnection @@ -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