Files

63 lines
1.6 KiB
Bash

#!/usr/bin/env bash
# Первая загрузка Rules и init-cursor. SSH/HTTPS и bootstrap — автоматически.
set -euo pipefail
RULES_DEST="${RULES_DEST:-$HOME/CursorRules}"
HTTPS_URL="${HTTPS_URL:-https://git.papatramp.ru/PapaTramp/Rules.git}"
SSH_URL="${SSH_URL:-ssh://git@git.papatramp.ru:2222/PapaTramp/Rules.git}"
SKIP_GIT_REMOTES=0
UPDATE=0
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-git-remotes) SKIP_GIT_REMOTES=1; shift ;;
--update|-Update) UPDATE=1; shift ;;
*) shift ;;
esac
done
log_step() { printf '[*] %s\n' "$1"; }
log_ok() { printf '[+] %s\n' "$1"; }
log_warn() { printf '[!] %s\n' "$1"; }
ensure_rules_clone() {
if [[ -d "$RULES_DEST/.git" ]]; then
log_step 'Updating CursorRules...'
git -C "$RULES_DEST" pull --ff-only
return 0
fi
if [[ -e "$RULES_DEST" ]]; then
local backup="${RULES_DEST}.bak-$(date +%Y%m%d-%H%M%S)"
log_warn "Replacing non-git folder: $RULES_DEST -> $backup"
mv "$RULES_DEST" "$backup"
fi
log_step 'Cloning Rules via SSH...'
if git clone --depth 1 "$SSH_URL" "$RULES_DEST" 2>/dev/null; then
log_ok "Cloned to $RULES_DEST"
return 0
fi
log_warn 'SSH clone failed - trying HTTPS (enter Gitea login once)...'
git clone --depth 1 "$HTTPS_URL" "$RULES_DEST"
log_ok "Cloned to $RULES_DEST"
}
ensure_rules_clone
# shellcheck source=/dev/null
source "$RULES_DEST/init-cursor.sh"
if [[ "$UPDATE" -eq 1 ]]; then
if [[ "$SKIP_GIT_REMOTES" -eq 1 ]]; then
init-cursor --update --skip-git-remotes
else
init-cursor --update
fi
elif [[ "$SKIP_GIT_REMOTES" -eq 1 ]]; then
init-cursor --skip-git-remotes
else
init-cursor
fi