#!/bin/bash
# AcreetionOS Bidirectional Sync
REMOTE_IP=$1
LOCAL_DATA="/drive1/gitlab/data"

if [ -z "$REMOTE_IP" ]; then
    echo "Usage: $0 <REMOTE_IP>"
    exit 1
fi

echo "🔄 Syncing to $REMOTE_IP..."

# Sync Git data and Large Files (LFS)
# -a (archive), -u (update/skip newer), -z (compress)
rsync -auvz -e "ssh -p 22" $LOCAL_DATA/git-data/repositories/ root@$REMOTE_IP:$LOCAL_DATA/git-data/repositories/
rsync -auvz -e "ssh -p 22" $LOCAL_DATA/gitlab-rails/shared/lfs-objects/ root@$REMOTE_IP:$LOCAL_DATA/gitlab-rails/shared/lfs-objects/

# Register new repos in the GitLab UI
docker exec gitlab gitlab-rake gitlab:import:repos
docker exec gitlab update-permissions
