summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 12:10:15 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 12:10:15 +0300
commit7118f8d3582d6f016090ff096a30951d8bda6f33 (patch)
treef5ac381a7a5c89a47670d9142490e8253ed89d75
parentc0b1099dc2fa4578b5fb53508bf9f871de06bc0e (diff)
fix(wg1-setup.sh): escape WG_HOSTNAME in sed /etc/hosts cleanup
Escape regex metacharacters in WG_HOSTNAME before embedding into the sed delete pattern so '.' (always present in hostnames like hyperstack1.wg1) is treated as a literal dot rather than a wildcard. Replace the literal-space anchor with [[:space:]] so tab-indented lines in /etc/hosts are also matched and removed correctly.
-rwxr-xr-xwg1-setup.sh4
1 files changed, 3 insertions, 1 deletions
diff --git a/wg1-setup.sh b/wg1-setup.sh
index 7307a76..9c58756 100755
--- a/wg1-setup.sh
+++ b/wg1-setup.sh
@@ -371,7 +371,9 @@ fi
# Update /etc/hosts so that WG_HOSTNAME resolves to the VM's WireGuard IP.
# hyperstack.rb uses this hostname in test URLs and informational output.
echo "Updating /etc/hosts: ${SERVER_WG_IP} ${WG_HOSTNAME}..."
-sudo sed -i "/ ${WG_HOSTNAME}$/d" /etc/hosts # Remove stale entry if present
+# Escape regex metacharacters in WG_HOSTNAME so sed treats it as a literal.
+WG_HOSTNAME_ESCAPED=$(printf '%s' "$WG_HOSTNAME" | sed 's/[][\.^$*/]/\\&/g')
+sudo sed -i "/[[:space:]]${WG_HOSTNAME_ESCAPED}$/d" /etc/hosts # Remove stale entry if present
echo "${SERVER_WG_IP} ${WG_HOSTNAME}" | sudo tee -a /etc/hosts > /dev/null
print_success "/etc/hosts updated"