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