#!/usr/bin/env bash
PAT="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"
REPO_URL="https://${PAT}@github.com/myronblair/do-server-config.git"
REPO_DIR="/opt/do-server-config"

if [[ -d "$REPO_DIR/.git" ]]; then
    cd "$REPO_DIR"
    git config user.email "backup@orbishosting.com"
    git config user.name  "DO Server Backup"
    git pull --rebase origin main -q 2>/dev/null || true
else
    git clone "$REPO_URL" "$REPO_DIR"
    cd "$REPO_DIR"
    git config user.email "backup@orbishosting.com"
    git config user.name  "DO Server Backup"
fi
exec bash "$REPO_DIR/backup.sh"
