manual-push-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 MANUAL PUSH" 12 echo "=================================" 13 echo "📅 Date: Mon May 26 21:43:00 CDT 2025" 14 echo "" 15 16 # Helper function to print success 17 print_success() { 18 echo -e "✅ " 19 } 20 21 # Helper function to print warning 22 print_warning() { 23 echo -e "⚠️ " 24 } 25 26 # Helper function to print error 27 print_error() { 28 echo -e "❌ " 29 } 30 31 # 1. Check if Git-Sync Container is Running 32 if docker ps --format '{{.Names}}' | grep -q "git_sync_dev"; then 33 print_success "Git-Sync container (git_sync_dev) is running." 34 else 35 print_error "Git-Sync container (git_sync_dev) is not running. Start it with: ./scripts/up-dev.sh" 36 exit 1 37 fi 38 39 # 2. Check Local Repository 40 if docker exec git_sync_dev test -d "/repos/local/.git"; then 41 print_success "Local repository is initialized at /repos/local." 42 else 43 print_error "Local repository not initialized at /repos/local. Initialize it with: git init" 44 exit 1 45 fi 46 47 # 3. Load Environment Variables 48 if [ -f "config/git-sync/.env" ]; then 49 set -a 50 source config/git-sync/.env 51 set +a 52 else 53 print_error "config/git-sync/.env not found. Exiting." 54 exit 1 55 fi 56 57 # 4. Initialize Log File 58 TIMESTAMP=1748313780 59 LOG_FILE="manual-push-.log" 60 docker exec git_sync_dev touch "/logs/" 61 docker exec git_sync_dev chmod 644 "/logs/" 62 docker exec git_sync_dev sh -c "echo '[Mon May 26 21:43:00 CDT 2025] Starting manual push' >> /logs/" 63 64 # Function to log messages 65 log_message() { 66 local level= 67 local message= 68 docker exec git_sync_dev sh -c "echo '[Mon May 26 21:43:00 CDT 2025] [] ' >> /logs/" 69 if [ "" = "INFO" ] && [ "" = "INFO" ]; then 70 echo "[Mon May 26 21:43:00 CDT 2025] [] " 71 elif [ "" = "ERROR" ]; then 72 echo "[Mon May 26 21:43:00 CDT 2025] [] " >&2 73 fi 74 } 75 76 # Function to sync to a Git remote (GitHub/Forgejo) 77 sync_to_git_remote() { 78 local remote_name= 79 local url= 80 log_message "INFO" "Manually syncing to at ..." 81 if docker exec git_sync_dev sh -c "cd /repos/local && git remote | grep -q "; then 82 docker exec git_sync_dev sh -c "cd /repos/local && git remote set-url " 83 else 84 docker exec git_sync_dev sh -c "cd /repos/local && git remote add " 85 fi 86 attempt=1 87 while [ -le ]; do 88 if docker exec git_sync_dev sh -c "cd /repos/local && git push --all --force"; then 89 log_message "INFO" "Successfully synced to ." 90 print_success "Synced to " 91 break 92 else 93 log_message "ERROR" "Failed to sync to (attempt /)." 94 print_error "Failed to sync to (attempt /)" 95 attempt=1 96 sleep 0 97 fi 98 done 99 if [ -gt ]; then 100 log_message "ERROR" "Max retries reached for . Giving up." 101 print_error "Max retries reached for " 102 fi 103 } 104 105 # Function to sync to Radicle 106 sync_to_radicle() { 107 local remote_name= 108 local url= 109 log_message "INFO" "Manually syncing to Radicle at ..." 110 # Placeholder for Radicle sync 111 log_message "INFO" "Radicle sync not fully implemented. Skipping." 112 print_warning "Radicle sync not implemented" 113 } 114 115 # Function to sync to Rclone remote (Internet Archive/Web3.storage) 116 sync_to_rclone_remote() { 117 local remote_name= 118 local url= 119 log_message "INFO" "Manually syncing to at ..." 120 # Create a Git bundle 121 BUNDLE_FILE="/tmp/repo-1748313780.bundle" 122 docker exec git_sync_dev sh -c "cd /repos/local && git bundle create --all" 123 # Sync the bundle using Rclone 124 attempt=1 125 while [ -le ]; do 126 if docker exec git_sync_dev rclone copy --config /config/git-sync/rclone.conf --progress --log-level INFO; then 127 log_message "INFO" "Successfully synced bundle to ." 128 print_success "Synced bundle to " 129 docker exec git_sync_dev rm 130 break 131 else 132 log_message "ERROR" "Failed to sync to (attempt /)." 133 print_error "Failed to sync to (attempt /)" 134 attempt=1 135 sleep 0 136 fi 137 done 138 if [ -gt ]; then 139 log_message "ERROR" "Max retries reached for . Giving up." 140 print_error "Max retries reached for " 141 docker exec git_sync_dev rm 142 fi 143 } 144 145 # 5. Perform Manual Push to All Remotes 146 echo "Pushing to all enabled remotes..." 147 while IFS='|' read -r remote_name type url enabled; do 148 if [ "" -eq 1 ]; then 149 if [ "" = "git" ]; then 150 sync_to_git_remote 151 elif [ "" = "radicle" ]; then 152 sync_to_radicle 153 elif [ "" = "rclone" ]; then 154 sync_to_rclone_remote 155 fi 156 else 157 print_warning "Skipping disabled remote: " 158 fi 159 done < config/git-sync/remotes.conf 160 161 # 6. Summary 162 echo "" 163 echo "=================================" 164 echo "✅ Manual Push Completed" 165 echo "=================================" 166 echo "Log file: ./volumes/logs/" 167 echo "Check sync status: ./scripts/report-git-sync.sh" 168 echo "Troubleshoot issues: ./scripts/diagnose-git-sync.sh"