Files
cc/alpine/template
Oliver dc80dd9522 merge
2025-08-08 16:34:03 -03:00

40 lines
864 B
Bash
Executable File

#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <localfile> <remotefile> <host_vars_dir>"
exit 1
fi
hosts_file="/mnt/encrypted_volume/${HOSTS_FILE:-hosts.txt}"
localfile="$1"
remotefile="$2"
host_vars_dir="$3"
while read -r host; do
echo "Processing host: $host"
host_env_file="$host_vars_dir/$host"
if [ ! -f "$host_env_file" ]; then
echo "Warning: env file for host '$host' not found at $host_env_file. Skipping."
continue
fi
declare -A vars=()
while IFS='=' read -r key value; do
[[ -z "$key" || -z "$value" ]] && continue
vars["$key"]="$value"
done < "$host_env_file"
content=$(cat "$localfile")
for key in "${!vars[@]}"; do
content=$(echo "$content" | sed "s|{$key}|${vars[$key]}|g")
done
echo "Copying to $host:$remotefile"
echo "$content" | ssh "$host" "cat > $remotefile"
done < "$hosts_file"