From a38bd75474aab969ce233fd79cf34589b1a2ab18 Mon Sep 17 00:00:00 2001 From: colin Date: Sun, 21 Jan 2024 23:08:28 +0000 Subject: [PATCH] Update docker/headscale/start.sh --- docker/headscale/start.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/docker/headscale/start.sh b/docker/headscale/start.sh index 918b714..4d39d03 100644 --- a/docker/headscale/start.sh +++ b/docker/headscale/start.sh @@ -17,21 +17,18 @@ replace_config_values() { fi # Read the template and replace variables - local temp_file=$(mktemp) - cp "$config_template" "$temp_file" - while read -r line; do - while [[ "$line" =~ (\$\{[a-zA-Z_][a-zA-Z_0-9]*\}) ]]; do - LHS=${BASH_REMATCH[1]} - RHS="$(eval echo "\"$LHS\"")" - line=${line//$LHS/$RHS} + while IFS= read -r line || [[ -n "$line" ]]; do + while [[ "$line" =~ \$\{([a-zA-Z_][a-zA-Z_0-9]*)\} ]]; do + var_name=${BASH_REMATCH[1]} + var_value=$(eval echo "\$$var_name") + line=${line//\$\{$var_name\}/$var_value} done echo "$line" - done < "$temp_file" > "$config_output" - rm "$temp_file" + done < "$config_template" > "$config_output" echo "Config file generated at $config_output" } -# Example usage in your startup script +# Run the function to replace variables and start headscale replace_config_values -headscale \ No newline at end of file +headscale