From df86400eb5f909b74ea4a3b896c01ba4092dae60 Mon Sep 17 00:00:00 2001 From: oliver Date: Tue, 13 Oct 2026 09:04:10 -0300 Subject: [PATCH] o --- alpine/template | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/alpine/template b/alpine/template index 6c0a841..3bdc469 100755 --- a/alpine/template +++ b/alpine/template @@ -15,6 +15,11 @@ localfile="$1" remotefile="$2" remotetmp_base="/var/tmp/4server" +# If the destination is a directory (trailing slash), keep the local file name +case "$remotefile" in + */) remotefile="${remotefile}$(basename "$localfile")" ;; +esac + # 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" @@ -34,7 +39,6 @@ while read -r host <&3; do SSH_PRIVATE=$(<"$host_vars_dir/$host/$host") SSH_PUBLIC=$(<"$host_vars_dir/$host/$host.pub") - content=$(<"$localfile") for key in "${keys[@]}"; do @@ -42,7 +46,6 @@ while read -r host <&3; do # 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}" echo "Copying to $host:$remotefile" @@ -52,4 +55,3 @@ while read -r host <&3; do ssh "$host" "doas mv '$remotetmp' '$remotefile'" done 3< /app/host_vars/hosts -