From 27469fc417011c249c3ae068b1a719fe4c0da344 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 22 Jan 2024 15:22:34 +0000 Subject: [PATCH] Update docker/headscale/start.sh --- docker/headscale/start.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docker/headscale/start.sh b/docker/headscale/start.sh index 38ecb2e..ecbad91 100644 --- a/docker/headscale/start.sh +++ b/docker/headscale/start.sh @@ -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.