From 7e65665ad65be910438f2d6f5edea03acfc38af8 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 3 Jul 2025 07:42:25 -0600 Subject: [PATCH] Some updates to the start-production script and just general clean up --- .gitignore | 4 +- add-cname-records.sh | 290 ------------------ config.sh | 31 +- .../843f83a4-247a-4c29-8a7e-cde50e2f4222.json | 1 - configs/cloudflare/tunnel-config.yml | 32 +- configs/homepage/services.yaml | 18 +- mkdocs/docs/build/index.md | 4 + .../repo_widget_hook.cpython-311.pyc | Bin 6924 -> 6911 bytes mkdocs/docs/overrides/main.html | 2 +- mkdocs/mkdocs.yml | 2 +- reset-site.sh | 288 +++++++++++++++++ start-production.sh | 42 ++- 12 files changed, 371 insertions(+), 343 deletions(-) delete mode 100755 add-cname-records.sh delete mode 100644 configs/cloudflare/843f83a4-247a-4c29-8a7e-cde50e2f4222.json create mode 100644 reset-site.sh diff --git a/.gitignore b/.gitignore index 793b3ac..d401ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ !/configs/code-server/.config/.gitkeep .env -.env* \ No newline at end of file +.env* + +/configs/cloudflare/*.json \ No newline at end of file diff --git a/add-cname-records.sh b/add-cname-records.sh deleted file mode 100755 index 5e26427..0000000 --- a/add-cname-records.sh +++ /dev/null @@ -1,290 +0,0 @@ -#!/bin/bash -echo "#############################################################" -echo "# " -echo "# DNS Setup for Changemaker.lite Services " -echo "# " -echo "# This script will ADD DNS records for your services. " -echo "# Existing DNS records will NOT be deleted. " -echo "# " -echo "#############################################################" -echo "" -echo "-------------------------------------------------------------" -echo "Cloudflare Credentials Required" -echo "Please ensure your .env file contains the following variables:" -echo " CF_API_TOKEN=your_cloudflare_api_token" -echo " CF_ZONE_ID=your_cloudflare_zone_id" -echo " CF_TUNNEL_ID=your_cloudflared_tunnel_id" -echo " CF_DOMAIN=yourdomain.com" -echo "" -echo "You can find these values in your Cloudflare dashboard:" -echo " - API Token: https://dash.cloudflare.com/profile/api-tokens (Create a token with Zone:DNS:Edit and Access:Apps:Edit permissions for your domain)" -echo " - Zone ID: On your domain's overview page" -echo " - Tunnel ID: In the Zero Trust dashboard under Access > Tunnels" -echo " - Domain: The domain you want to use for your services" -echo "" -echo "-------------------------------------------------------------" -echo "" -read -p "Type 'y' to continue or any other key to abort: " consent -if [[ "$consent" != "y" && "$consent" != "Y" ]]; then - echo "Aborted by user." - exit 1 -fi - -# Source environment variables from the .env file in the same directory -ENV_FILE="$(dirname "$0")/.env" -if [ -f "$ENV_FILE" ]; then - export $(grep -v '^#' "$ENV_FILE" | xargs) -else - echo "Error: .env file not found at $ENV_FILE" - exit 1 -fi - -# Check if required Cloudflare variables are set -if [ -z "$CF_API_TOKEN" ] || [ -z "$CF_ZONE_ID" ] || [ -z "$CF_TUNNEL_ID" ] || [ -z "$CF_DOMAIN" ]; then - echo "Error: One or more required Cloudflare environment variables (CF_API_TOKEN, CF_ZONE_ID, CF_TUNNEL_ID, CF_DOMAIN) are not set in $ENV_FILE." - exit 1 -fi - -# Check if jq is installed -if ! command -v jq &> /dev/null; then - echo "Error: jq is required but not installed. Please install jq to continue." - echo "On Debian/Ubuntu: sudo apt-get install jq" - echo "On RHEL/CentOS: sudo yum install jq" - exit 1 -fi - -# Array of subdomains that need DNS records - updated to match our active services -SUBDOMAINS=( - "dashboard" - "code" - "listmonk" - "docs" - "n8n" - "db" - "git" -) - -# Function to check if DNS record already exists -record_exists() { - local subdomain=$1 - local records=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records?name=$subdomain.$CF_DOMAIN" \ - -H "Authorization: Bearer $CF_API_TOKEN" \ - -H "Content-Type: application/json") - - local count=$(echo $records | jq -r '.result | length') - [ "$count" -gt 0 ] -} - -# Add CNAME records for each subdomain (only if they don't exist) -echo "Adding DNS records for services..." - -for subdomain in "${SUBDOMAINS[@]}"; do - if record_exists "$subdomain"; then - echo "DNS record for $subdomain.$CF_DOMAIN already exists, skipping..." - else - echo "Adding CNAME record for $subdomain.$CF_DOMAIN..." - - response=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records" \ - -H "Authorization: Bearer $CF_API_TOKEN" \ - -H "Content-Type: application/json" \ - --data "{ - \"type\": \"CNAME\", - \"name\": \"$subdomain\", - \"content\": \"$CF_TUNNEL_ID.cfargotunnel.com\", - \"ttl\": 1, - \"proxied\": true - }") - - success=$(echo $response | jq -r '.success') - if [ "$success" == "true" ]; then - echo "✓ Successfully added CNAME record for $subdomain.$CF_DOMAIN" - else - echo "✗ Failed to add CNAME record for $subdomain.$CF_DOMAIN" - echo "Error: $(echo $response | jq -r '.errors[0].message')" - fi - fi -done - -# Add root domain record if it doesn't exist -if record_exists "@"; then - echo "Root domain DNS record already exists, skipping..." -else - echo "Adding root domain CNAME record..." - response=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/dns_records" \ - -H "Authorization: Bearer $CF_API_TOKEN" \ - -H "Content-Type: application/json" \ - --data "{ - \"type\": \"CNAME\", - \"name\": \"@\", - \"content\": \"$CF_TUNNEL_ID.cfargotunnel.com\", - \"ttl\": 1, - \"proxied\": true - }") - - success=$(echo $response | jq -r '.success') - if [ "$success" == "true" ]; then - echo "✓ Successfully added root domain CNAME record" - else - echo "✗ Failed to add root domain CNAME record" - echo "Error: $(echo $response | jq -r '.errors[0].message')" - fi -fi - -echo "" -echo "DNS records setup complete!" -echo "" - -# Prompt for admin email for secured services -echo "-------------------------------------------------------------" -echo "Setting up Cloudflare Access Protection" -echo "-------------------------------------------------------------" -echo "" -echo "The following services will be protected with authentication:" -echo " - dashboard.$CF_DOMAIN" -echo " - code.$CF_DOMAIN" -echo "" -echo "Please enter the admin email address that should have access:" -read ADMIN_EMAIL - -# Validate email format -if [[ ! "$ADMIN_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then - echo "Error: Invalid email format. Please provide a valid email address." - exit 1 -fi - -# Services that require authentication - updated for our use case -PROTECTED_SERVICES=("dashboard" "code") - -# Services that should have bypass policies (public access) - updated for our use case -BYPASS_SERVICES=("listmonk" "docs" "n8n" "db" "git") - -# Function to create access application with email authentication -create_protected_app() { - local service=$1 - echo "Setting up authentication for $service.$CF_DOMAIN..." - - app_response=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/access/apps" \ - -H "Authorization: Bearer $CF_API_TOKEN" \ - -H "Content-Type: application/json" \ - --data "{ - \"name\": \"$service $CF_DOMAIN\", - \"domain\": \"$service.$CF_DOMAIN\", - \"type\": \"self_hosted\", - \"session_duration\": \"24h\", - \"app_launcher_visible\": true, - \"skip_interstitial\": true - }") - - app_id=$(echo $app_response | jq -r '.result.id') - - if [ -z "$app_id" ] || [ "$app_id" == "null" ]; then - echo "✗ Error creating access application for $service" - return 1 - fi - - echo "✓ Created access application for $service (ID: $app_id)" - - # Create authentication policy - policy_response=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/access/apps/$app_id/policies" \ - -H "Authorization: Bearer $CF_API_TOKEN" \ - -H "Content-Type: application/json" \ - --data "{ - \"name\": \"Admin Access\", - \"decision\": \"allow\", - \"include\": [{ - \"email\": { - \"email\": \"$ADMIN_EMAIL\" - } - }], - \"require\": [], - \"exclude\": [] - }") - - policy_success=$(echo $policy_response | jq -r '.success') - - if [ "$policy_success" == "true" ]; then - echo "✓ Created authentication policy for $service" - else - echo "✗ Failed to create authentication policy for $service" - fi -} - -# Function to create bypass application (public access) -create_bypass_app() { - local service=$1 - echo "Setting up public access for $service.$CF_DOMAIN..." - - app_response=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/access/apps" \ - -H "Authorization: Bearer $CF_API_TOKEN" \ - -H "Content-Type: application/json" \ - --data "{ - \"name\": \"$service $CF_DOMAIN\", - \"domain\": \"$service.$CF_DOMAIN\", - \"type\": \"self_hosted\", - \"session_duration\": \"24h\", - \"app_launcher_visible\": false, - \"skip_interstitial\": true - }") - - app_id=$(echo $app_response | jq -r '.result.id') - - if [ -z "$app_id" ] || [ "$app_id" == "null" ]; then - echo "✗ Error creating access application for $service" - return 1 - fi - - echo "✓ Created access application for $service (ID: $app_id)" - - # Create bypass policy - policy_response=$(curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/access/apps/$app_id/policies" \ - -H "Authorization: Bearer $CF_API_TOKEN" \ - -H "Content-Type: application/json" \ - --data "{ - \"name\": \"Public Access\", - \"decision\": \"bypass\", - \"include\": [{ - \"everyone\": {} - }], - \"require\": [], - \"exclude\": [] - }") - - policy_success=$(echo $policy_response | jq -r '.success') - - if [ "$policy_success" == "true" ]; then - echo "✓ Created public access policy for $service" - else - echo "✗ Failed to create public access policy for $service" - fi -} - -echo "Creating Cloudflare Access applications..." -echo "" - -# Create protected applications -for service in "${PROTECTED_SERVICES[@]}"; do - create_protected_app "$service" - echo "" -done - -# Create bypass applications for public services -for service in "${BYPASS_SERVICES[@]}"; do - create_bypass_app "$service" - echo "" -done - -echo "-------------------------------------------------------------" -echo "Setup Complete!" -echo "-------------------------------------------------------------" -echo "" -echo "Protected services (require authentication with $ADMIN_EMAIL):" -for service in "${PROTECTED_SERVICES[@]}"; do - echo " - https://$service.$CF_DOMAIN" -done -echo "" -echo "Public services (no authentication required):" -for service in "${BYPASS_SERVICES[@]}"; do - echo " - https://$service.$CF_DOMAIN" -done -echo "" -echo "All services should be accessible through your Cloudflare tunnel." diff --git a/config.sh b/config.sh index 9882764..bb0276d 100755 --- a/config.sh +++ b/config.sh @@ -366,23 +366,24 @@ update_services_yaml() { cp "$SERVICES_YAML" "$backup_file" echo "Created backup of services.yaml at $backup_file" - # Update all domain references - handle the current domain (albertademocracytaskforce.org) - # First, update any existing domain to the new domain - sed -i "s|albertademocracytaskforce\.org|$new_domain|g" "$SERVICES_YAML" + # Update all href values with the new domain + # Replace any existing domain patterns with the new domain + sed -i "s|href: \"https://code\.[^\"]*\"|href: \"https://code.$new_domain\"|g" "$SERVICES_YAML" + sed -i "s|href: \"https://listmonk\.[^\"]*\"|href: \"https://listmonk.$new_domain\"|g" "$SERVICES_YAML" + sed -i "s|href: \"https://db\.[^\"]*\"|href: \"https://db.$new_domain\"|g" "$SERVICES_YAML" + sed -i "s|href: \"https://map\.[^\"]*\"|href: \"https://map.$new_domain\"|g" "$SERVICES_YAML" + sed -i "s|href: \"https://docs\.[^\"]*\"|href: \"https://docs.$new_domain\"|g" "$SERVICES_YAML" + sed -i "s|href: \"https://n8n\.[^\"]*\"|href: \"https://n8n.$new_domain\"|g" "$SERVICES_YAML" + sed -i "s|href: \"https://git\.[^\"]*\"|href: \"https://git.$new_domain\"|g" "$SERVICES_YAML" + sed -i "s|href: \"https://qr\.[^\"]*\"|href: \"https://qr.$new_domain\"|g" "$SERVICES_YAML" - # Also update any changeme.org references that might exist + # Update the main site href (matches pattern without subdomain) + sed -i "s|href: \"https://[a-zA-Z0-9.-]*\.\(org\|com\|net\|edu\)\"|href: \"https://$new_domain\"|g" "$SERVICES_YAML" + + # Also update any remaining domain references that might exist + sed -i "s|cmlite\.org|$new_domain|g" "$SERVICES_YAML" sed -i "s|changeme\.org|$new_domain|g" "$SERVICES_YAML" - - # Update specific service URLs with proper formatting - sed -i "s|# href: \"https://code\.[^\"]*\"|# href: \"https://code.$new_domain\"|g" "$SERVICES_YAML" - sed -i "s|# href: \"https://listmonk\.[^\"]*\"|# href: \"https://listmonk.$new_domain\"|g" "$SERVICES_YAML" - sed -i "s|# href: \"https://db\.[^\"]*\"|# href: \"https://db.$new_domain\"|g" "$SERVICES_YAML" - sed -i "s|# href: \"https://git\.[^\"]*\"|# href: \"https://git.$new_domain\"|g" "$SERVICES_YAML" - sed -i "s|# href: \"https://docs\.[^\"]*\"|# href: \"https://docs.$new_domain\"|g" "$SERVICES_YAML" - sed -i "s|# href: \"https://n8n\.[^\"]*\"|# href: \"https://n8n.$new_domain\"|g" "$SERVICES_YAML" - - # Update root domain reference - sed -i "s|# href: \"https://[^/\"]*\"|# href: \"https://$new_domain\"|g" "$SERVICES_YAML" | tail -1 + sed -i "s|albertademocracytaskforce\.org|$new_domain|g" "$SERVICES_YAML" echo "✅ Updated service URLs in services.yaml to use domain: $new_domain" return 0 diff --git a/configs/cloudflare/843f83a4-247a-4c29-8a7e-cde50e2f4222.json b/configs/cloudflare/843f83a4-247a-4c29-8a7e-cde50e2f4222.json deleted file mode 100644 index 2142f0d..0000000 --- a/configs/cloudflare/843f83a4-247a-4c29-8a7e-cde50e2f4222.json +++ /dev/null @@ -1 +0,0 @@ -{"AccountTag":"a421828402ca13fbcaad955f285f16f6","TunnelSecret":"949mtkdN202INtEohadCgnEe7QXykBL26dq2uQMt+HQ=","TunnelID":"843f83a4-247a-4c29-8a7e-cde50e2f4222","Endpoint":""} \ No newline at end of file diff --git a/configs/cloudflare/tunnel-config.yml b/configs/cloudflare/tunnel-config.yml index 8e59c70..aaa28b5 100644 --- a/configs/cloudflare/tunnel-config.yml +++ b/configs/cloudflare/tunnel-config.yml @@ -1,27 +1,27 @@ -# Cloudflare Tunnel Configuration for cmlite.org -# Generated by Changemaker.lite start-production.sh on Sun 29 Jun 2025 09:10:15 PM MDT +# Cloudflare Tunnel Configuration for bnkserve.org +# Generated by Changemaker.lite start-production.sh on Thu 03 Jul 2025 07:24:57 AM MDT -tunnel: 843f83a4-247a-4c29-8a7e-cde50e2f4222 -credentials-file: /mnt/storagessd1tb/changemaker.lite.dev/changemaker.lite/configs/cloudflare/843f83a4-247a-4c29-8a7e-cde50e2f4222.json +tunnel: 2fff7cb3-7dd8-407f-86fd-7a681c1e5630 +credentials-file: /home/bunker-mobile-lab/changemaker.lite/configs/cloudflare/2fff7cb3-7dd8-407f-86fd-7a681c1e5630.json ingress: - - hostname: homepage.cmlite.org + - hostname: homepage.bnkserve.org service: http://localhost:3010 - - hostname: code.cmlite.org + - hostname: code.bnkserve.org service: http://localhost:8888 - - hostname: listmonk.cmlite.org - service: http://localhost:9001 - - hostname: docs.cmlite.org + - hostname: listmonk.bnkserve.org + service: http://localhost:9000 + - hostname: docs.bnkserve.org service: http://localhost:4000 - - hostname: cmlite.org - service: http://localhost:4002 - - hostname: n8n.cmlite.org + - hostname: bnkserve.org + service: http://localhost:4001 + - hostname: n8n.bnkserve.org service: http://localhost:5678 - - hostname: db.cmlite.org + - hostname: db.bnkserve.org service: http://localhost:8090 - - hostname: git.cmlite.org + - hostname: git.bnkserve.org service: http://localhost:3030 - - hostname: map.cmlite.org + - hostname: map.bnkserve.org service: http://localhost:3000 - - hostname: qr.cmlite.org + - hostname: qr.bnkserve.org service: http://localhost:8089 - service: http_status:404 diff --git a/configs/homepage/services.yaml b/configs/homepage/services.yaml index 845093b..7fd26e6 100644 --- a/configs/homepage/services.yaml +++ b/configs/homepage/services.yaml @@ -5,25 +5,25 @@ - Code Server: icon: mdi-code-braces - href: "https://code.cmlite.org" + href: "https://code.bnkserver.org" description: VS Code in the browser - Platform Editor container: code-server-changemaker - Listmonk: icon: mdi-email-newsletter - href: "https://listmonk.cmlite.org" + href: "https://listmonk.bnkserver.org" description: Newsletter & mailing list manager container: listmonk_app - NocoDB: icon: mdi-database - href: "https://db.cmlite.org" + href: "https://db.bnkserver.org" description: No-code database platform container: changemakerlite-nocodb-1 - Map Server: icon: mdi-map - href: "https://map.cmlite.org" + href: "https://map.bnkserver.org" description: Map server for geospatial data container: nocodb-map-viewer @@ -31,19 +31,19 @@ - Content & Documentation: - Main Site: icon: mdi-web - href: "https://cmlite.org" + href: "https://bnkserver.org" description: CM-lite campaign website container: mkdocs-site-server-changemaker - MkDocs (Live): icon: mdi-book-open-page-variant - href: "https://docs.cmlite.org" + href: "https://docs.bnkserver.org" description: Live documentation server with hot reload container: mkdocs-changemaker - Mini QR: icon: mdi-qrcode - href: "https://qr.cmlite.org" + href: "https://qr.bnkserver.org" description: QR code generator container: mini-qr @@ -51,7 +51,7 @@ - Automation & Infrastructure: - n8n: icon: mdi-robot-industrial - href: "https://n8n.cmlite.org" + href: "https://n8n.bnkserver.org" description: Workflow automation platform container: n8n-changemaker @@ -69,6 +69,6 @@ - Gitea: icon: mdi-git - href: "https://git.cmlite.org" + href: "https://git.bnkserver.org" description: Git repository hosting container: gitea_changemaker \ No newline at end of file diff --git a/mkdocs/docs/build/index.md b/mkdocs/docs/build/index.md index 14c0505..f45660d 100644 --- a/mkdocs/docs/build/index.md +++ b/mkdocs/docs/build/index.md @@ -26,6 +26,10 @@ cd changemaker.lite docker compose up -d ``` +### Optional - Site Builld + +If you want to have your site prepared for launch, you can now proceed with reseting the site build. See [Build Site](../build/site.md) for more detials. + ### Deploy !!! note "Cloudflare" diff --git a/mkdocs/docs/hooks/__pycache__/repo_widget_hook.cpython-311.pyc b/mkdocs/docs/hooks/__pycache__/repo_widget_hook.cpython-311.pyc index bb804c719ba098c873f2926269b511cd82f921b9..9bd5faec06615702e5f559a765130c82f80c1f2a 100644 GIT binary patch delta 28 icmeA%`)|s!^Whdzgdj^n=k-<76_aG delta 41 vcmexw+GEDOoR^o20SG4NrEcW@!^Ur@pOK%Ns-K*nl3Jvno4uKn{hKfV1*Hub diff --git a/mkdocs/docs/overrides/main.html b/mkdocs/docs/overrides/main.html index 68348ba..0235017 100644 --- a/mkdocs/docs/overrides/main.html +++ b/mkdocs/docs/overrides/main.html @@ -6,6 +6,6 @@ {% endblock %} {% block announce %} - + Changemaker Archive. Learn more {% endblock %} diff --git a/mkdocs/mkdocs.yml b/mkdocs/mkdocs.yml index 3a952c2..65c0861 100644 --- a/mkdocs/mkdocs.yml +++ b/mkdocs/mkdocs.yml @@ -1,6 +1,6 @@ site_name: Changemaker Lite site_description: Build Power. Not Rent It. Own your digital infrastructure. -site_url: https://cmlite.org +site_url: https://bnkserver.org site_author: Bunker Operations docs_dir: docs site_dir: site diff --git a/reset-site.sh b/reset-site.sh new file mode 100644 index 0000000..77b508a --- /dev/null +++ b/reset-site.sh @@ -0,0 +1,288 @@ +#!/bin/bash +# filepath: /home/bunker-mobile-lab/changemaker.lite.love.island/reset-site.sh + +echo "🔄 Resetting Changemaker Lite site to baseline..." + +# Define the mkdocs directory +MKDOCS_DIR="/home/bunker-mobile-lab/changemaker.lite.love.island/mkdocs" +DOCS_DIR="$MKDOCS_DIR/docs" + +# Check if mkdocs directory exists +if [ ! -d "$MKDOCS_DIR" ]; then + echo "❌ MkDocs directory not found: $MKDOCS_DIR" + exit 1 +fi + +cd "$MKDOCS_DIR" || exit 1 + +echo "📂 Current directory: $(pwd)" + +# Create backup directory with timestamp +BACKUP_DIR="../backup-$(date +%Y%m%d_%H%M%S)" +echo "💾 Creating backup at: $BACKUP_DIR" +mkdir -p "$BACKUP_DIR" + +# Backup entire docs directory first +cp -r docs "$BACKUP_DIR/" 2>/dev/null || echo "⚠️ Warning: Could not backup docs directory" + +# List of files and directories to preserve +PRESERVE_FILES=( + # Configuration files + "mkdocs.yml" + "docs/index.md" + + # Blog directory and index + "docs/blog" + "docs/blog/index.md" + + # Stylesheets + "docs/stylesheets/extra.css" + + # Template overrides + "docs/overrides/main.html" + + # JavaScript files + "docs/javascripts/gitea-widget.js" + "docs/javascripts/github-widget.js" + "docs/javascripts/home.js" + + # Hooks + "docs/hooks/repo_widget_hook.py" + + # Assets that might exist + "docs/assets" +) + +echo "🔒 Preserving essential files..." + +# Create temporary directory for preserved files +TEMP_PRESERVE_DIR="/tmp/mkdocs-preserve-$$" +mkdir -p "$TEMP_PRESERVE_DIR" + +# Copy preserved files to temp directory +for file in "${PRESERVE_FILES[@]}"; do + if [ -e "$file" ]; then + # Create directory structure in temp + dirname_path=$(dirname "$file") + mkdir -p "$TEMP_PRESERVE_DIR/$dirname_path" + + # Copy file or directory + cp -r "$file" "$TEMP_PRESERVE_DIR/$file" 2>/dev/null + echo "✅ Preserved: $file" + else + echo "⚠️ Not found (will be created): $file" + fi +done + +echo "🗑️ Cleaning docs directory..." + +# Remove everything from docs except .gitkeep if it exists +find docs/ -mindepth 1 -name ".gitkeep" -prune -o -type f -exec rm -f {} \; 2>/dev/null +find docs/ -mindepth 1 -name ".gitkeep" -prune -o -type d -exec rm -rf {} \; 2>/dev/null + +echo "📁 Recreating directory structure..." + +# Recreate basic directory structure +mkdir -p docs/{stylesheets,javascripts,overrides,hooks,assets,blog/posts} + +echo "♻️ Restoring preserved files..." + +# Restore preserved files +for file in "${PRESERVE_FILES[@]}"; do + if [ -e "$TEMP_PRESERVE_DIR/$file" ]; then + # Create parent directory if needed + dirname_path=$(dirname "$file") + mkdir -p "$dirname_path" + + # Restore file or directory + cp -r "$TEMP_PRESERVE_DIR/$file" "$file" + echo "✅ Restored: $file" + fi +done + +# Clean up temp directory +rm -rf "$TEMP_PRESERVE_DIR" + +echo "📝 Ensuring required files exist..." + +# Ensure blog index exists +if [ ! -f "docs/blog/index.md" ]; then + echo "Creating docs/blog/index.md..." + cat > docs/blog/index.md << 'EOF' + + +EOF +fi + +# Ensure main index exists with baseline content if missing +if [ ! -f "docs/index.md" ]; then + echo "Creating baseline docs/index.md..." + cat > docs/index.md << 'EOF' +--- +template: home.html +hide: + - navigation + - toc +--- + +# Welcome to Changemaker Lite + +Stop feeding your secrets to corporations. Own your political infrastructure. + +## Quick Start + +Get up and running in minutes: + +```bash +# Clone the repository +git clone https://gitea.bnkops.com/admin/changemaker.lite +cd changemaker.lite + +# Configure environment +./config.sh + +# Start all services +docker compose up -d +``` + +## Services + +Changemaker Lite includes essential services for documentation, development, and automation. + +## Getting Started + +1. **Setup**: Run `./config.sh` to configure your environment +2. **Launch**: Start services with `docker compose up -d` +3. **Dashboard**: Access the Homepage at [http://localhost:3010](http://localhost:3010) + +EOF +fi + +# Ensure mkdocs.yml has baseline content if missing +if [ ! -f "mkdocs.yml" ]; then + echo "Creating baseline mkdocs.yml..." + cat > mkdocs.yml << 'EOF' +site_name: Changemaker Lite +site_description: Build Power. Not Rent It. Own your digital infrastructure. +site_url: https://cmlite.org +site_author: Bunker Operations +docs_dir: docs +site_dir: site + +# Repository +repo_url: https://gitea.bnkops.com/admin/changemaker.lite +repo_name: changemaker.lite +edit_uri: "" + +# Theme +theme: + name: material + custom_dir: docs/overrides + palette: + - scheme: slate + primary: deep purple + accent: amber + toggle: + icon: material/weather-night + name: Switch to light mode + - scheme: default + primary: deep purple + accent: amber + toggle: + icon: material/weather-sunny + name: Switch to dark mode + font: + text: Inter + code: JetBrains Mono + features: + - navigation.instant + - navigation.tracking + - navigation.tabs + - navigation.sections + - navigation.expand + - navigation.top + - search.highlight + - search.share + - search.suggest + - content.code.copy + +# Plugins +plugins: + - search + - blog: + blog_dir: blog + post_date_format: medium + archive_name: Archive + categories_name: Categories + +# Extra CSS and JS +extra_css: + - stylesheets/extra.css + +extra_javascript: + - javascripts/home.js + - javascripts/github-widget.js + - javascripts/gitea-widget.js + +hooks: + - docs/hooks/repo_widget_hook.py + +# Navigation +nav: + - Home: index.md + - Blog: + - blog/index.md + +# Copyright +copyright: > + Copyright © 2024 The Bunker Operations +EOF +fi + +echo "🧹 Cleaning up build artifacts..." + +# Remove build directory if it exists +if [ -d "site" ]; then + rm -rf site + echo "✅ Removed build directory" +fi + +# Remove any cache directories +find . -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null +find . -name "*.pyc" -type f -delete 2>/dev/null + +echo "🔍 Verifying reset..." + +# Check that essential files exist +essential_check=true +check_files=("docs/index.md" "mkdocs.yml" "docs/blog/index.md" "docs/stylesheets/extra.css") + +for file in "${check_files[@]}"; do + if [ -f "$file" ]; then + echo "✅ $file exists" + else + echo "❌ $file missing" + essential_check=false + fi +done + +if [ "$essential_check" = true ]; then + echo "" + echo "🎉 Site reset complete!" + echo "📋 Summary:" + echo " • Preserved essential configuration and assets" + echo " • Maintained blog directory and posts" + echo " • Kept custom stylesheets and JavaScript" + echo " • Backup created at: $BACKUP_DIR" + echo "" + echo "🚀 Next steps:" + echo " • Run 'mkdocs serve' to start development server" + echo " • Run 'mkdocs build' to generate static site" +else + echo "" + echo "⚠️ Reset completed with warnings - some essential files are missing" + echo "💾 Backup available at: $BACKUP_DIR" +fi + +echo "" +echo "✨ Reset complete!" \ No newline at end of file diff --git a/start-production.sh b/start-production.sh index 4b931e2..7d72235 100755 --- a/start-production.sh +++ b/start-production.sh @@ -28,6 +28,28 @@ else exit 1 fi +# Prompt user for tunnel name suffix +echo "Choose a name for your tunnel:" +echo "This will create a tunnel named 'changemaker-lite-[your-input]'" +echo "Examples: 'prod', 'staging', 'myproject', 'server1'" +echo "" +read -p "Enter tunnel name suffix (or press Enter for default 'main'): " TUNNEL_SUFFIX + +# Set default if empty +if [ -z "$TUNNEL_SUFFIX" ]; then + TUNNEL_SUFFIX="main" +fi + +# Validate tunnel suffix (alphanumeric and hyphens only) +if [[ ! "$TUNNEL_SUFFIX" =~ ^[a-zA-Z0-9-]+$ ]]; then + echo "Error: Tunnel suffix can only contain letters, numbers, and hyphens." + exit 1 +fi + +TUNNEL_NAME="changemaker-lite-$TUNNEL_SUFFIX" +echo "Using tunnel name: $TUNNEL_NAME" +echo "" + # Check if Cloudflare credentials are properly configured if [ -z "$CF_API_TOKEN" ] || [ "$CF_API_TOKEN" == "your_cloudflare_api_token" ] || \ [ -z "$CF_ZONE_ID" ] || [ "$CF_ZONE_ID" == "your_cloudflare_zone_id" ] || \ @@ -104,11 +126,10 @@ setup_tunnel() { echo "Setting up Cloudflare tunnel..." # Check if we have a tunnel ID in the environment - local tunnel_name="changemaker-lite" local tunnel_id="" # Check if tunnel exists by name - echo "Checking for existing tunnel named '$tunnel_name'..." + echo "Checking for existing tunnel named '$TUNNEL_NAME'..." local tunnel_list_output # Remove --account-tag parameter as it's not supported in this version tunnel_list_output=$(cloudflared tunnel list --output json 2>&1) @@ -130,7 +151,7 @@ setup_tunnel() { # Now try to extract the tunnel info local tunnel_info if echo "$tunnel_list_output" | jq '.' &>/dev/null; then - tunnel_info=$(echo "$tunnel_list_output" | jq -r '.[] | select(.name=="'$tunnel_name'")' 2>/dev/null || echo "") + tunnel_info=$(echo "$tunnel_list_output" | jq -r '.[] | select(.name=="'$TUNNEL_NAME'")' 2>/dev/null || echo "") else echo "Failed to parse tunnel list. Cannot check for existing tunnels." tunnel_info="" @@ -140,7 +161,7 @@ setup_tunnel() { # Tunnel exists tunnel_id=$(echo "$tunnel_info" | jq -r '.id' 2>/dev/null) if [ -n "$tunnel_id" ] && [ "$tunnel_id" != "null" ]; then - echo "✅ Found existing tunnel: $tunnel_name (ID: $tunnel_id)" + echo "✅ Found existing tunnel: $TUNNEL_NAME (ID: $tunnel_id)" # Update the environment variable if needed if [ "$CF_TUNNEL_ID" != "$tunnel_id" ]; then @@ -154,10 +175,10 @@ setup_tunnel() { fi else # Create new tunnel - echo "Creating new tunnel: $tunnel_name" + echo "Creating new tunnel: $TUNNEL_NAME" local tunnel_create_output # Remove --account-tag parameter as it's not supported in this version - tunnel_create_output=$(cloudflared tunnel create "$tunnel_name" 2>&1) + tunnel_create_output=$(cloudflared tunnel create "$TUNNEL_NAME" 2>&1) echo "Tunnel creation output:" echo "$tunnel_create_output" @@ -167,8 +188,8 @@ setup_tunnel() { fi # Try multiple methods to extract the tunnel ID from output - # Method 1: Try the original regex pattern - tunnel_id=$(echo "$tunnel_create_output" | grep -oP 'Created tunnel changemaker-lite with id \K[a-f0-9-]+' || echo "") + # Method 1: Try the original regex pattern with new tunnel name + tunnel_id=$(echo "$tunnel_create_output" | grep -oP "Created tunnel $TUNNEL_NAME with id \K[a-f0-9-]+" || echo "") # Method 2: Look for UUID pattern if [ -z "$tunnel_id" ]; then @@ -192,7 +213,7 @@ setup_tunnel() { fi fi - echo "✅ Created new tunnel: $tunnel_name (ID: $tunnel_id)" + echo "✅ Created new tunnel: $TUNNEL_NAME (ID: $tunnel_id)" # Update the environment variable sed -i "s/CF_TUNNEL_ID=.*/CF_TUNNEL_ID=$tunnel_id/" "$ENV_FILE" @@ -597,6 +618,9 @@ echo "# Production Deployment Complete! " echo "# " echo "#############################################################" echo "" +echo "Tunnel Name: $TUNNEL_NAME" +echo "Tunnel ID: $CF_TUNNEL_ID" +echo "" echo "Your services are now accessible at:" echo "" echo "Public services:"