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