From 39df4cea32dd55c8167fe52afd2eeb803b969a7b Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 22 Jan 2024 16:49:47 +0000 Subject: [PATCH] Update docker/headscale/start.sh --- docker/headscale/start.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docker/headscale/start.sh b/docker/headscale/start.sh index 16b9f7b..e7004f4 100644 --- a/docker/headscale/start.sh +++ b/docker/headscale/start.sh @@ -80,6 +80,28 @@ ensure_private_key_exists() { echo testgen derp private key ensure_private_key_exists +ensure_noise_private_key_exists() { + local key_path="/var/lib/headscale/noise_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 Noise 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 Noise private key generated at $key_path." + else + echo "Failed to generate Noise private key." + return 1 + fi + fi +} + +echo testgen noise private key +ensure_noise_private_key_exists + # Run the function to replace variables and start headscale replace_config_values