From 933b33ee15bb257fd3226e8de0e40f832edc511f Mon Sep 17 00:00:00 2001 From: colin Date: Sun, 21 Jan 2024 15:45:52 +0000 Subject: [PATCH] Add docker/headscale/start.sh --- docker/headscale/start.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 docker/headscale/start.sh diff --git a/docker/headscale/start.sh b/docker/headscale/start.sh new file mode 100644 index 0000000..9f96883 --- /dev/null +++ b/docker/headscale/start.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +replace_config_values() { + local config_template="/etc/headscale/config-example.yaml" + local config_output="/etc/headscale/config.yaml" + + # Check if the output config file already exists + if [[ -f "$config_output" ]]; then + echo "$config_output already exists." + return 0 + fi + + # Ensure the template file exists + if [[ ! -f "$config_template" ]]; then + echo "Template file $config_template not found." + return 1 + 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} + done + echo "$line" + done < "$temp_file" > "$config_output" + rm "$temp_file" + + echo "Config file generated at $config_output" +} + +# Example usage in your startup script +replace_config_values