diagnose-git-sync.sh
1 #!/bin/bash 2 set -e 3 4 # Colors for output 5 RED='\033[0;31m' 6 GREEN='\033[0;32m' 7 YELLOW='\033[1;33m' 8 NC='\033[0m' # No Color 9 10 echo "=================================" 11 echo "🩺 GIT-SYNC COMPREHENSIVE DIAGNOSTICS" 12 echo "=================================" 13 echo "📅 Date: Mon May 26 21:36:33 CDT 2025" 14 echo "" 15 16 # Helper function to print section headers 17 print_section() { 18 echo "---------------------------------" 19 echo "📌 " 20 echo "---------------------------------" 21 } 22 23 # Helper function to print success 24 print_success() { 25 echo -e "✅ " 26 } 27 28 # Helper function to print warning 29 print_warning() { 30 echo -e "⚠️ " 31 } 32 33 # Helper function to print error 34 print_error() { 35 echo -e "❌ " 36 } 37 38 # 1. Check Current Directory 39 print_section "Current Directory" 40 echo "📁 Current Directory: /home/mrhavens/fieldwork/fold-stack" 41 if [[ "/home/mrhavens/fieldwork/fold-stack" != *"/fieldwork/fold-stack" ]]; then 42 print_error "You are not in the expected fold-stack directory. Please run this script from ~/fieldwork/fold-stack." 43 exit 1 44 fi 45 print_success "Directory check passed." 46 47 # 2. Check Docker Container Status 48 print_section "Git-Sync Container Status" 49 if docker ps --format '{{.Names}}' | grep -q "git_sync_dev"; then 50 print_success "Git-Sync container (git_sync_dev) is running." 51 else 52 print_error "Git-Sync container (git_sync_dev) is not running. Start it with: ./scripts/up-dev.sh" 53 exit 1 54 fi 55 56 # 3. Check Configuration Files 57 print_section "Configuration Files Check" 58 CONFIG_FILES=( 59 "/config/git-sync/remotes.conf" 60 "/config/git-sync/rclone.conf" 61 "/config/git-sync/.env" 62 "/config/git-sync/rules.json" 63 ) 64 for file in ""; do 65 if docker exec git_sync_dev test -f ""; then 66 print_success " exists." 67 else 68 print_error " is missing." 69 fi 70 done 71 72 # 4. Check SSH Keys 73 print_section "SSH Keys Check" 74 SSH_KEYS=( 75 "/config/git-sync/secrets/github.key" 76 "/config/git-sync/secrets/forgejo.key" 77 ) 78 for key in ""; do 79 if docker exec git_sync_dev test -f ""; then 80 print_success " exists." 81 # Check permissions 82 PERMS= 83 if [ "" -eq 600 ]; then 84 print_success " has correct permissions (600)." 85 else 86 print_warning " permissions are (should be 600)." 87 fi 88 else 89 print_warning " is missing (sync to this remote may fail)." 90 fi 91 done 92 93 # 5. Check Remote Connectivity 94 print_section "Remote Connectivity Test" 95 while IFS='|' read -r remote_name type url enabled; do 96 if [ "" -eq 1 ]; then 97 echo "Testing ()..." 98 if [ "" = "git" ]; then 99 if docker exec git_sync_dev git ls-remote "" >/dev/null 2>&1; then 100 print_success " connectivity test passed." 101 else 102 print_error " connectivity test failed. Check SSH key or URL." 103 fi 104 elif [ "" = "rclone" ]; then 105 if docker exec git_sync_dev rclone lsd "" --config /config/git-sync/rclone.conf >/dev/null 2>&1; then 106 print_success " connectivity test passed." 107 else 108 print_error " connectivity test failed. Check rclone.conf or credentials." 109 fi 110 elif [ "" = "radicle" ]; then 111 print_warning "Radicle connectivity test not implemented (placeholder)." 112 fi 113 else 114 print_warning "Skipping disabled remote: " 115 fi 116 done < config/git-sync/remotes.conf 117 118 # 6. Check Logs for Errors 119 print_section "Git-Sync Logs Check (last 50 lines)" 120 LOGS=[Mon May 26 21:26:36 CDT 2025] [INFO] Starting sync loop with interval 300 seconds. 121 [Mon May 26 21:26:36 CDT 2025] [INFO] Checking for changes in local repository... 122 fatal: detected dubious ownership in repository at '/repos/local' 123 To add an exception for this directory, call: 124 125 git config --global --add safe.directory /repos/local 126 [Mon May 26 21:26:36 CDT 2025] [INFO] Starting sync loop with interval 300 seconds. 127 [Mon May 26 21:26:36 CDT 2025] [INFO] Checking for changes in local repository... 128 fatal: detected dubious ownership in repository at '/repos/local' 129 To add an exception for this directory, call: 130 131 git config --global --add safe.directory /repos/local 132 echo "" 133 if echo "" | grep -q "\[ERROR\]"; then 134 print_error "Errors found in logs. Search for [ERROR] above." 135 else 136 print_success "No errors found in recent logs." 137 fi 138 139 # 7. Check Volume Permissions 140 print_section "Local Repository Volume Permissions" 141 ls -ld ./volumes/repos || print_error "Missing volumes/repos (needed for Git-Sync)" 142 ls -la ./volumes/repos || print_warning "Local repository volume contents not accessible" 143 144 print_section "Logs Volume Permissions" 145 ls -ld ./volumes/logs || print_error "Missing volumes/logs (needed for logging)" 146 ls -la ./volumes/logs || print_warning "Logs volume contents not accessible" 147 148 # 8. Check Lockfile 149 print_section "Lockfile Check" 150 if docker exec git_sync_dev test -f "/repos/local/.git-sync.lock"; then 151 print_success "Lockfile exists (/repos/local/.git-sync.lock)." 152 else 153 print_error "Lockfile missing (/repos/local/.git-sync.lock). Sync may not be atomic." 154 fi 155 156 # 9. Check Local Repository 157 print_section "Local Repository Check" 158 if docker exec git_sync_dev test -d "/repos/local/.git"; then 159 print_success "Local repository is initialized at /repos/local." 160 else 161 print_error "Local repository not initialized at /repos/local. Initialize it with: git init" 162 fi 163 164 # 10. Summary of Findings 165 print_section "Summary of Findings" 166 echo "Check the above output for any errors (❌) or warnings (⚠️)." 167 echo "Common issues and fixes:" 168 echo "- If the container is not running, restart the stack: ./scripts/down-dev.sh && ./scripts/up-dev.sh" 169 echo "- If SSH keys are missing or have wrong permissions, fix them: chmod 600 config/git-sync/secrets/*" 170 echo "- If remotes are unreachable, verify URLs and credentials in config/git-sync/remotes.conf and rclone.conf" 171 echo "- If logs show errors, check network connectivity or remote availability" 172 173 echo "" 174 echo "=================================" 175 echo "✅ Diagnostics Completed" 176 echo "=================================" 177 echo "If issues persist, share the output with support or run:" 178 echo " docker logs git_sync_dev --follow"