35 lines
1018 B
Bash
35 lines
1018 B
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
|
|
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 < "$config_template" > "$config_output"
|
|
|
|
echo "Config file generated at $config_output"
|
|
}
|
|
|
|
# Run the function to replace variables and start headscale
|
|
replace_config_values
|
|
headscale
|