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() {
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"
+}
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
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}" \
"${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}"
# 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"
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
# 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
--- /dev/null
+${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
--- /dev/null
+[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
--- /dev/null
+#!/bin/sh
+exec "${PATH_UPDATE_EFI_SCRIPT}"
--- /dev/null
+[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