From bd44aeafb89b3040900a60b84f479968880b0cb2 Mon Sep 17 00:00:00 2001 From: colin Date: Sun, 21 Jan 2024 15:43:40 +0000 Subject: [PATCH] Add docker/headscale/prep.sh --- docker/headscale/prep.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docker/headscale/prep.sh diff --git a/docker/headscale/prep.sh b/docker/headscale/prep.sh new file mode 100644 index 0000000..ee068f2 --- /dev/null +++ b/docker/headscale/prep.sh @@ -0,0 +1,39 @@ +#!/bin/bash +strip_yaml_comments() { + local file=$1 + if [[ ! -f "$file" ]]; then + echo "File not found: $file" + return 1 + fi + grep -v '^#' "$file" | grep -v '^$' +} + +download_and_process_config() { + local url="https://raw.githubusercontent.com/juanfont/headscale/main/config-example.yaml" + local target_dir="/etc/headscale" + local target_file="${target_dir}/config-example.yaml" + local processed_file="${target_dir}/config-example-processed.yaml" + + # Create target directory if it does not exist + mkdir -p "$target_dir" + + # Download the file using curl + curl -o "$target_file" "$url" + + if [ $? -eq 0 ]; then + echo "Config downloaded successfully to $target_file" + # Process the downloaded file to strip comments + strip_yaml_comments "$target_file" > "$processed_file" + if [ $? -eq 0 ]; then + echo "Processed config file saved to $processed_file" + else + echo "Failed to process the config file" + return 1 + fi + else + echo "Failed to download the config file" + return 1 + fi +} + +download_and_process_config \ No newline at end of file