#!/bin/bash # Server Audit - Run on AWS to see current state # Usage: ssh server 'bash -s' < ctrl/server/audit.sh echo "=== SERVER AUDIT ===" echo "Date: $(date)" echo "Host: $(hostname)" echo "User: $USER" echo "" # ============================================================================= # Directory Structure # ============================================================================= echo "=== DIRECTORY STRUCTURE ===" echo "" echo "Home directory contents:" ls -lah ~/ echo "" echo "core_nest structure (if exists):" if [ -d ~/core_nest ]; then tree ~/core_nest -L 2 -I ".git" 2>/dev/null || find ~/core_nest -maxdepth 2 -type d | sort else echo " ~/core_nest does NOT exist" fi echo "" echo "pawprint location:" if [ -d ~/pawprint ]; then ls -lah ~/pawprint/ | head -10 echo " ..." else echo " ~/pawprint does NOT exist" fi echo "" # ============================================================================= # Docker # ============================================================================= echo "=== DOCKER ===" echo "" echo "Docker version:" docker --version 2>/dev/null || echo " Docker NOT installed" echo "" echo "Docker Compose version:" docker compose version 2>/dev/null || echo " Docker Compose NOT installed" echo "" echo "Running containers:" docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null || echo " None or Docker not running" echo "" echo "All containers (including stopped):" docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}" 2>/dev/null | head -20 echo "" echo "Docker networks:" docker network ls 2>/dev/null || echo " None" echo "" echo "Docker volumes:" docker volume ls 2>/dev/null | grep -E "core_nest|amar|pawprint|DRIVER" || echo " No core_nest/amar/pawprint volumes" echo "" # ============================================================================= # Nginx # ============================================================================= echo "=== NGINX ===" echo "" echo "Nginx version:" nginx -v 2>&1 || echo " Nginx NOT installed" echo "" echo "Nginx status:" systemctl status nginx --no-pager -l 2>/dev/null | head -5 || echo " Cannot check status" echo "" echo "Sites enabled:" ls -lah /etc/nginx/sites-enabled/ 2>/dev/null || echo " Directory does not exist" echo "" echo "Sites available (core_nest related):" ls -lah /etc/nginx/sites-available/ 2>/dev/null | grep -E "nest|amar|pawprint|artery|album|ward" || echo " None found" echo "" # ============================================================================= # SSL Certificates # ============================================================================= echo "=== SSL CERTIFICATES ===" echo "" echo "Certbot version:" certbot --version 2>/dev/null || echo " Certbot NOT installed" echo "" echo "Certificates:" if [ -d /etc/letsencrypt/live ]; then sudo ls -lah /etc/letsencrypt/live/ 2>/dev/null || echo " Permission denied" else echo " /etc/letsencrypt/live does NOT exist" fi echo "" # ============================================================================= # Environment Files # ============================================================================= echo "=== ENVIRONMENT FILES ===" echo "" for location in ~/core_nest/amar ~/core_nest/pawprint ~/pawprint; do if [ -d "$location" ]; then echo "$location/.env:" if [ -f "$location/.env" ]; then echo " EXISTS" echo " Size: $(stat -c%s "$location/.env" 2>/dev/null || stat -f%z "$location/.env" 2>/dev/null) bytes" echo " NEST_NAME: $(grep "^NEST_NAME=" "$location/.env" 2>/dev/null || echo "not set")" echo " NETWORK_NAME: $(grep "^NETWORK_NAME=" "$location/.env" 2>/dev/null || echo "not set")" else echo " does NOT exist" fi echo "$location/.env.example:" [ -f "$location/.env.example" ] && echo " EXISTS" || echo " does NOT exist" echo "" fi done # ============================================================================= # Ports in Use # ============================================================================= echo "=== PORTS IN USE ===" echo "" echo "Listening on ports (3000, 8000, 13000-13003):" sudo netstat -tlnp 2>/dev/null | grep -E ":3000|:8000|:1300[0-3]" || sudo ss -tlnp | grep -E ":3000|:8000|:1300[0-3]" || echo " Cannot check (need sudo)" echo "" # ============================================================================= # Systemd Services # ============================================================================= echo "=== SYSTEMD SERVICES ===" echo "" echo "Pawprint-related services:" systemctl list-units --type=service --all 2>/dev/null | grep -E "pawprint|artery|album|ward" || echo " None found" echo "" # ============================================================================= # Disk Usage # ============================================================================= echo "=== DISK USAGE ===" echo "" echo "Overall:" df -h / 2>/dev/null echo "" echo "Docker space:" docker system df 2>/dev/null || echo " Docker not available" echo "" # ============================================================================= # Summary # ============================================================================= echo "=== SUMMARY ===" echo "" echo "Key Questions:" echo "" echo "1. Is there an existing core_nest deployment?" [ -d ~/core_nest ] && echo " YES - ~/core_nest exists" || echo " NO" echo "" echo "2. Are Docker containers running?" docker ps -q 2>/dev/null | wc -l | xargs -I {} echo " {} containers running" echo "" echo "3. Is nginx configured for core_nest?" [ -f /etc/nginx/sites-enabled/core_nest.conf ] && echo " YES - core_nest.conf installed" || echo " NO" echo "" echo "4. Are there old individual nginx configs?" ls /etc/nginx/sites-enabled/ 2>/dev/null | grep -E "amar|pawprint|artery|album|ward" | wc -l | xargs -I {} echo " {} old configs found" echo "" echo "5. SSL certificates present?" [ -d /etc/letsencrypt/live/nest.mcrn.ar ] && echo " *.nest.mcrn.ar: YES" || echo " *.nest.mcrn.ar: NO" [ -d /etc/letsencrypt/live/mcrn.ar ] && echo " *.mcrn.ar: YES" || echo " *.mcrn.ar: NO" echo "" echo "=== END AUDIT ==="