This commit is contained in:
Oliver
2025-10-16 16:38:39 -03:00
parent 8ed294f3b7
commit 1808864021
14 changed files with 176 additions and 34 deletions

View File

@@ -15,7 +15,8 @@ localfile="$1"
remotefile="$2"
remotetmp_base="/var/tmp/4server"
while read -r host; do
# Read hosts from file descriptor 3 to prevent ssh from consuming stdin
while read -r host <&3; do
host_env_file="$host_vars_dir/$host/$host.env"
if [ ! -f "$host_env_file" ]; then
@@ -28,24 +29,19 @@ while read -r host; do
source "$host_env_file"
set +a
NEBULA_KEY=$(<"$host_vars_dir/$host/$host.key")
NEBULA_CRT=$(<"$host_vars_dir/$host/$host.crt")
SSH_PRIVATE=$(<"$host_vars_dir/$host/$host")
SSH_PUBLIC=$(<"$host_vars_dir/$host/$host.pub")
content=$(<"$localfile")
for key in "${keys[@]}"; do
value="${!key}" # indirect reference
# Replace placeholder {{KEY}} with value using Bash's parameter expansion
content="${content//\{\{$key\}\}/$value}"
done
content=$(<"$localfile")
for key in "${keys[@]}"; do
value="${!key}" # indirect reference
# Replace placeholder {{KEY}} with value using Bash's parameter expansion
content="${content//\{\{$key\}\}/$value}"
done
# Copy content to remote temporary file
remotetmp="${remotetmp_base}_${host}"
@@ -55,7 +51,5 @@ done
# Move temporary file to final location with doas
ssh "$host" "doas mv '$remotetmp' '$remotefile'"
done < /app/host_vars/hosts
done 3< /app/host_vars/hosts