ntfy/docker/headscale/start.sh

37 lines
1.0 KiB
Bash

#!/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
headscale