From 7118f8d3582d6f016090ff096a30951d8bda6f33 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 May 2026 12:10:15 +0300 Subject: 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. --- wg1-setup.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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" -- cgit v1.2.3