#!/bin/bash
# Repository cleanup and organization script
set -euo pipefail
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${GREEN}Repository Cleanup and Organization${NC}"
echo "======================================"
# 1. Clean up root directory - move scripts
echo -e "\n${YELLOW}1. Moving scripts to /scripts directory...${NC}"
if [[ -f "docker-cleanup.sh" ]]; then
mv -v docker-cleanup.sh scripts/
echo " ✓ Moved docker-cleanup.sh"
fi
if [[ -f "build-optimized.sh" ]]; then
mkdir -p scripts/archive
mv -v build-optimized.sh scripts/archive/
echo " ✓ Archived build-optimized.sh"
fi
# 2. Move documentation to appropriate folders
echo -e "\n${YELLOW}2. Organizing documentation...${NC}"
mkdir -p docs/setup
mkdir -p docs/api
# Move setup/config docs
for file in API.md ARCHITECTURE.md MCP_SETUP.md README-DOCKER.md GETTING-STARTED.md; do
if [[ -f "$file" ]]; then
case "$file" in
API.md)
mv -v "$file" docs/api/
echo " ✓ Moved $file to docs/api/"
;;
ARCHITECTURE.md)
mv -v "$file" docs/
echo " ✓ Moved $file to docs/"
;;
MCP_SETUP.md|README-DOCKER.md|GETTING-STARTED.md)
mv -v "$file" docs/setup/
echo " ✓ Moved $file to docs/setup/"
;;
esac
fi
done
# 3. Create config directory
echo -e "\n${YELLOW}3. Creating config directory...${NC}"
mkdir -p config
if [[ -f "mcp-config.json" ]]; then
mv -v mcp-config.json config/mcp-config.example.json
echo " ✓ Moved mcp-config.json to config/mcp-config.example.json"
fi
# 4. Update .gitignore
echo -e "\n${YELLOW}4. Updating .gitignore...${NC}"
cat >> .gitignore << 'EOF'
# Logs and temporary files
*.log
*.lock
.install.lock
install.log
# Config files (keep examples only)
config/*.json
!config/*.example.json
# Test outputs
tests/output/
tests/*.log
# IDE files
.vscode/
.idea/
*.swp
*.swo
*~
# OS files
.DS_Store
Thumbs.db
EOF
echo " ✓ Updated .gitignore"
# 5. Create directory README files
echo -e "\n${YELLOW}5. Creating directory README files...${NC}"
# Create docs/README.md
cat > docs/README.md << 'EOF'
# Documentation
## Setup & Installation
- [Getting Started](setup/GETTING-STARTED.md) - Quick start guide
- [Docker Setup](setup/README-DOCKER.md) - Docker-specific configuration
- [MCP Setup](setup/MCP_SETUP.md) - Model Context Protocol setup
## Architecture & API
- [Architecture Overview](ARCHITECTURE.md) - System design and components
- [API Reference](api/API.md) - MCP API documentation
## Troubleshooting & Recovery
- [Troubleshooting Guide](TROUBLESHOOTING.md) - Common issues and solutions
- [WSL Recovery](WSL_RECOVERY_STEPS.md) - WSL2-specific recovery steps
## Development
- [Implementation Plan](IMPLEMENTATION_PLAN.md) - Development roadmap
- [Extension Ideas](EXTENSION_IDEAS.md) - Future enhancements
- [Docker Optimization](DOCKERFILE_OPTIMIZATION_REPORT.md) - Build optimization details
- [Multistage Benefits](MULTISTAGE_BENEFITS.md) - Docker build strategy
EOF
echo " ✓ Created docs/README.md"
# Create scripts/README.md
cat > scripts/README.md << 'EOF'
# Scripts
## Core Scripts
- `install.sh` - Main installation script
- `build.sh` - Build Docker containers
- `health-check.sh` - Check system health
## Maintenance
- `cleanup-repo.sh` - Clean and organize repository
- `docker-cleanup.sh` - Clean Docker resources
- `clean-output.sh` - Clean output directory
## Model Management
- `download-models.sh` - Download AI models
- `download-upscale-models.sh` - Download upscaling models
## Testing
- `test-upscale.sh` - Test upscaling functionality
## Development
- `setup-claude-code.sh` - Setup Claude Code integration
## Archive
- `archive/` - Deprecated or reference scripts
EOF
echo " ✓ Created scripts/README.md"
# Create models/README.md
cat > models/README.md << 'EOF'
# Models Directory Structure
## Directories
### Core Models
- `unet/` - FLUX diffusion models (schnell, dev)
- `clip/` - Text encoders (CLIP-L, T5-XXL)
- `vae/` - Variational Autoencoders
- `checkpoints/` - Stable Diffusion checkpoints
### Enhancement Models
- `upscale_models/` - Image upscaling models (4x-UltraSharp, 4x-AnimeSharp)
- `controlnet/` - ControlNet models for guided generation
- `loras/` - LoRA fine-tuning models
- `embeddings/` - Textual inversion embeddings
### Specialized Models
- `rmbg/` - Background removal models (RMBG-2.0)
- `RMBG/` - RMBG model files and configs
### Legacy
- `sd1.5/` - Stable Diffusion 1.5 models
## Model Files
Current models:
- FLUX schnell fp8: ~11GB (Apache 2.0 license)
- CLIP-L: ~235MB
- T5-XXL fp8: ~4.9GB
- VAE: ~320MB
- RMBG-2.0: ~176MB
- Upscale models: ~64MB each
## Usage
Models are automatically detected and linked by the install script.
To manually add models, place them in the appropriate directory and restart the containers.
EOF
echo " ✓ Created models/README.md"
# 6. Clean up temporary files
echo -e "\n${YELLOW}6. Cleaning temporary files...${NC}"
rm -f .install.lock install.log
echo " ✓ Removed temporary files"
# 7. Create symlinks for important docs in root (optional)
echo -e "\n${YELLOW}7. Creating convenience symlinks...${NC}"
if [[ ! -L "QUICK_START.md" ]]; then
ln -s docs/setup/GETTING-STARTED.md QUICK_START.md
echo " ✓ Created QUICK_START.md symlink"
fi
echo -e "\n${GREEN}✅ Repository cleanup complete!${NC}"
echo -e "\nNext steps:"
echo " 1. Review moved files: git status"
echo " 2. Commit changes: git add . && git commit -m 'chore: reorganize repository structure'"
echo " 3. Update any hardcoded paths in documentation"