#!/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