init-cursor: авто-bootstrap git на новом ПК, install.ps1 с Gitea.

Один вызов init-cursor настраивает SSH при необходимости и копирует rules в проект.
This commit is contained in:
2026-06-18 11:23:30 +10:00
parent bdf405e2c1
commit 7f8e7c0cb2
10 changed files with 600 additions and 284 deletions
+85 -28
View File
@@ -1,33 +1,71 @@
#!/usr/bin/env bash
# Копирует Cursor rules из локального $HOME/CursorRules в текущий проект.
init-cursor() {
local source="$HOME/CursorRules"
local rules_src="$source/.cursor/rules"
local scripts="$source/scripts"
local update=0
local skip_git_remotes=0
# Инициализация Cursor в текущем проекте; на новом хосте сначала настраивает git/SSH.
while [[ $# -gt 0 ]]; do
case "$1" in
-Update|--update) update=1; shift ;;
-SkipGitRemotes|--skip-git-remotes) skip_git_remotes=1; shift ;;
*) shift ;;
esac
done
get_cursor_rules_dest() {
printf '%s' "$HOME/CursorRules"
}
if [[ ! -d "$source" ]]; then
echo "Error: $source not found — run bootstrap.sh on this machine first" >&2
return 1
get_cursor_bootstrap_root() {
local rules_dest script_dir
rules_dest="$(get_cursor_rules_dest)"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ -f "$script_dir/scripts/invoke-machine-bootstrap.sh" ]]; then
printf '%s' "$script_dir"
return 0
fi
if [[ -f "$rules_dest/local/git-ssh-hosts.conf" ]]; then
printf '%s' "$rules_dest"
return 0
fi
if [[ -f "$script_dir/local/git-ssh-hosts.conf" ]]; then
printf '%s' "$script_dir"
return 0
fi
return 1
}
if [[ "$update" == '1' && -d "$source/.git" ]]; then
initialize_cursor_rules_environment() {
local update=0
[[ "${1:-}" == '--update' ]] && update=1
local rules_dest bootstrap_root
rules_dest="$(get_cursor_rules_dest)"
bootstrap_root="$(get_cursor_bootstrap_root)" || {
echo 'Error: CursorRules not found. Run install.sh from Gitea first:' >&2
echo ' curl -fsSL https://git.kalinamall.ru/PapaTramp/Rules/raw/branch/main/install.sh | bash' >&2
return 1
}
local skip_clone=0
[[ -d "$rules_dest/.git" ]] && skip_clone=1
ROOT="$bootstrap_root" RULES_DEST="$rules_dest" SKIP_CLONE="$skip_clone" \
bash "$bootstrap_root/scripts/invoke-machine-bootstrap.sh"
if [[ "$update" -eq 1 && -d "$rules_dest/.git" ]]; then
echo '[*] Updating CursorRules from remote...'
if git -C "$source" pull --ff-only; then
if git -C "$rules_dest" pull --ff-only; then
echo '[+] CursorRules updated'
else
echo '[!] git pull failed in CursorRules' >&2
fi
fi
}
install_cursor_in_current_project() {
local skip_git_remotes=0
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-git-remotes) skip_git_remotes=1; shift ;;
*) shift ;;
esac
done
local source rules_src scripts
source="$(get_cursor_rules_dest)"
rules_src="$source/.cursor/rules"
scripts="$source/scripts"
if [[ -f "$source/.cursorignore" ]]; then
cp -f "$source/.cursorignore" .
@@ -41,7 +79,7 @@ init-cursor() {
fi
if [[ -d .git ]]; then
local gitignore='.gitignore'
local gitignore='.gitignore' line
for line in '.cursor/' '.cursorignore'; do
if [[ ! -f "$gitignore" ]]; then
printf '%s\n' "$line" > "$gitignore"
@@ -53,21 +91,19 @@ init-cursor() {
done
fi
if [[ "$skip_git_remotes" == '1' ]]; then
if [[ "$skip_git_remotes" -eq 1 ]]; then
echo '[!] Git remotes skipped'
return 0
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo '[!] Not a git repo remotes skipped'
echo '[!] Not a git repo - remotes skipped'
return 0
fi
if [[ -f "$scripts/Set-GitRemotes.sh" ]]; then
echo '[*] Configuring git remotes...'
bash "$scripts/Set-GitRemotes.sh" || true
elif [[ -f "$scripts/Set-GitRemotes.ps1" ]]; then
echo '[!] Set-GitRemotes.ps1 only; install bash script or pwsh' >&2
fi
if [[ -f "$scripts/Ensure-GiteaHomeRepo.ps1" ]]; then
@@ -76,10 +112,31 @@ init-cursor() {
echo "[*] Ensuring home Gitea repo: $repo_name"
if command -v pwsh >/dev/null 2>&1; then
pwsh -NoProfile -File "$scripts/Ensure-GiteaHomeRepo.ps1" -RepoName "$repo_name" || true
elif command -v powershell >/dev/null 2>&1; then
powershell -NoProfile -ExecutionPolicy Bypass -File "$scripts/Ensure-GiteaHomeRepo.ps1" -RepoName "$repo_name" || true
else
echo '[!] PowerShell not found — skip Ensure-GiteaHomeRepo.ps1' >&2
fi
fi
}
init-cursor() {
local update=0
local skip_git_remotes=0
while [[ $# -gt 0 ]]; do
case "$1" in
-Update|--update) update=1; shift ;;
-SkipGitRemotes|--skip-git-remotes) skip_git_remotes=1; shift ;;
*) shift ;;
esac
done
if [[ "$update" -eq 1 ]]; then
initialize_cursor_rules_environment --update || return 1
else
initialize_cursor_rules_environment || return 1
fi
if [[ "$skip_git_remotes" -eq 1 ]]; then
install_cursor_in_current_project --skip-git-remotes
else
install_cursor_in_current_project
fi
echo '[+] init-cursor complete'
}