#!/bin/bash ## ## Tractatus Unified Deployment Script ## Replaces: deploy-full-project-SAFE.sh and deploy-frontend.sh ## ## Features: ## - Automatic JS/CSS change detection ## - Unified cache versioning (update-cache-version.js) ## - Auto-commit cache version changes ## - Security exclusions via .rsyncignore ## - Frontend-only or full project deployment ## - Optional service restart ## ## Usage: ## ./scripts/deploy.sh # Full deployment with auto-detection ## ./scripts/deploy.sh --frontend-only # Deploy public/ directory only ## ./scripts/deploy.sh --force-cache # Force cache update regardless ## ./scripts/deploy.sh --restart # Restart service after deployment ## ./scripts/deploy.sh --dry-run # Show what would be deployed ## ./scripts/deploy.sh --yes # Auto-confirm all prompts (non-interactive) ## set -e # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' BLUE='\033[0;34m' NC='\033[0m' # Configuration DEPLOY_KEY="/home/theflow/.ssh/tractatus_deploy" REMOTE_USER="ubuntu" REMOTE_HOST="vps-93a693da.vps.ovh.net" REMOTE_PATH="/var/www/tractatus" PROJECT_ROOT="/home/theflow/projects/tractatus" # Parse flags FRONTEND_ONLY=false FORCE_CACHE=false RESTART_SERVICE=false DRY_RUN=false AUTO_YES=false while [[ $# -gt 0 ]]; do case $1 in --frontend-only) FRONTEND_ONLY=true shift ;; --force-cache) FORCE_CACHE=true shift ;; --restart) RESTART_SERVICE=true shift ;; --dry-run) DRY_RUN=true shift ;; --yes) AUTO_YES=true shift ;; *) echo -e "${RED}Unknown option: $1${NC}" echo "Usage: $0 [--frontend-only] [--force-cache] [--restart] [--dry-run] [--yes]" exit 1 ;; esac done # Header echo "" echo -e "${BLUE}╔════════════════════════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ TRACTATUS UNIFIED DEPLOYMENT ║${NC}" echo -e "${BLUE}╚════════════════════════════════════════════════════════════════╝${NC}" echo "" if [ "$DRY_RUN" = true ]; then echo -e "${YELLOW}🔍 DRY-RUN MODE - No changes will be made${NC}" echo "" fi if [ "$FRONTEND_ONLY" = true ]; then echo -e "${YELLOW}📁 Mode: Frontend-only (public/ directory)${NC}" else echo -e "${YELLOW}📁 Mode: Full project deployment${NC}" fi echo "" # Step 1: Pre-deployment checks echo -e "${GREEN}[1/7] PRE-DEPLOYMENT CHECKS${NC}" echo "" # Check if we're in the right directory if [ ! -f "$PROJECT_ROOT/package.json" ]; then echo -e "${RED}✗ ERROR: Not in project root directory${NC}" echo "Expected: $PROJECT_ROOT" exit 1 fi echo -e " ✓ Project root verified" # Check .rsyncignore exists (for full deployment) if [ "$FRONTEND_ONLY" = false ] && [ ! -f "$PROJECT_ROOT/.rsyncignore" ]; then echo -e "${RED}✗ ERROR: .rsyncignore not found!${NC}" echo "This file is required to prevent sensitive data deployment." exit 1 fi if [ "$FRONTEND_ONLY" = false ]; then echo -e " ✓ .rsyncignore found" fi # Check for confidential documents (inst_012/inst_015) echo -e " Checking for confidential documents..." if [ "$FRONTEND_ONLY" = true ]; then PUBLIC_FILES=$(find public -type f \( -name "*.md" -o -name "*.html" -o -name "*.txt" \) 2>/dev/null || true) else PUBLIC_FILES=$(find public docs -type f \( -name "*.md" -o -name "*.html" -o -name "*.txt" \) 2>/dev/null || true) fi if [ -n "$PUBLIC_FILES" ]; then if ! node scripts/check-confidential-docs.js $PUBLIC_FILES 2>&1 | grep -q "No confidential"; then echo -e "${RED}✗ ERROR: Confidential documents detected - DEPLOYMENT BLOCKED (inst_012/inst_015)${NC}" echo "" node scripts/check-confidential-docs.js $PUBLIC_FILES exit 1 fi fi echo -e " ✓ No confidential documents" # Verify deployment structure (inst_025) echo -e " Verifying deployment structure..." if ! node scripts/verify-deployment-structure.js > /dev/null 2>&1; then echo -e "${YELLOW} ⚠ WARNING: Deployment structure verification failed${NC}" fi echo -e " ✓ Deployment structure validated" # Check file permissions (inst_020_CONSOLIDATED) echo -e " Checking file permissions..." if ! node scripts/check-file-permissions.js public > /dev/null 2>&1; then echo -e "${YELLOW} ⚠ WARNING: Some file permissions may need correction${NC}" fi echo -e " ✓ File permissions checked" # CSP check: no inline scripts in HTML files echo -e " Checking for inline scripts (CSP compliance)..." INLINE_SCRIPTS=$(grep -rn '