Update docker/headscale/start.sh

This commit is contained in:
colin 2024-01-22 15:22:34 +00:00
parent 671636ab86
commit 27469fc417
1 changed files with 23 additions and 0 deletions

View File

@ -58,6 +58,29 @@ replace_config_values() {
echo "Config file generated at $config_output"
}
ensure_private_key_exists() {
local key_path="/var/lib/headscale/derp_server_private.key"
# Check if the file exists and is a valid private key
if [[ -f "$key_path" ]] && openssl rsa -check -noout -in "$key_path" > /dev/null 2>&1; then
echo "Valid private key already exists at $key_path."
else
# Generate a new 2048-bit RSA private key
mkdir -p /var/lib/headscale
openssl genpkey -algorithm RSA -out "$key_path" -pkeyopt rsa_keygen_bits:2048
if [[ $? -eq 0 ]]; then
echo "New private key generated at $key_path."
else
echo "Failed to generate private key."
return 1
fi
fi
}
echo testgen derp private key
ensure_private_key_exists
# Run the function to replace variables and start headscale
replace_config_values
echo configuration implementation system finished.