README: краткая шпаргалка; install.sh как install.ps1 (SSH/HTTPS авто).

This commit is contained in:
2026-06-19 23:41:57 +10:00
parent 2e3b303029
commit 7388ef1462
3 changed files with 137 additions and 54 deletions
+77 -44
View File
@@ -1,81 +1,114 @@
# Rules
Правила и скрипты для настройки нового компьютера: SSH-ключи, Cursor rules, git remotes, home Gitea.
Скрипты для Cursor rules, SSH и git remotes (`kalinamall`, `home`, `github`).
## Один вызов: `init-cursor`
## Быстро: что запускать
| Состояние машины | Что делает `init-cursor` |
|------------------|--------------------------|
| Ничего не настроено | SSH-ключи, Gitea API, clone Rules в `$HOME/CursorRules`, профиль shell |
| Git уже настроен | Только копирует rules в текущий проект + remotes |
| Ситуация | Windows | Mac / Linux |
|----------|---------|-------------|
| **Новый комп**ичего не настроено) | Скопировать `install.ps1` с рабочего ПК → запустить в каталоге проекта | То же с `install.sh` |
| **Комп уже настраивали** (`~/CursorRules` есть) | `init-cursor` в каталоге проекта | `init-cursor` |
| **Только обновить rules** | `init-cursor -Update` | `init-cursor --update` |
Источник правил — локальный клон `$HOME/CursorRules` (после bootstrap). Обновить: `init-cursor -Update`.
Скрипты **сами** проверяют SSH, clone, ключи и remotes. Вручную выбирать SSH/HTTPS не нужно.
## Новый Windows-ПК
---
Репозиторий **приватный**`irm .../raw/.../install.ps1` без авторизации даст **404**.
## Новый компьютер
### Вариант A: SSH уже работает (этот ПК)
Нужен только **git**. Repo приватный — `curl`/`irm` по raw-URL **не работают**.
### 1. Скопировать один файл с рабочей машины
```powershell
cd C:\Users\papat\Projects\your-repo
git clone --depth 1 ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git $HOME\CursorRules
& $HOME\CursorRules\install.ps1
# Windows — с другого ПК (пример)
scp user@work-pc:CursorRules/install.ps1 $env:TEMP\
```
### Вариант B: SSH ещё нет (HTTPS, логин один раз)
```powershell
git clone --depth 1 https://git.kalinamall.ru/PapaTramp/Rules.git $HOME\CursorRules
& $HOME\CursorRules\install.ps1
```bash
# Mac — с другого ПК
scp user@work-pc:CursorRules/install.sh /tmp/
```
Дальше в любом проекте:
USB, общая папка — тоже подходит.
### 2. Запустить в каталоге **вашего проекта**
```powershell
# Windows
cd C:\path\to\your-repo
& $env:TEMP\install.ps1
```
```bash
# Mac
cd ~/projects/your-repo
bash /tmp/install.sh
```
Скрипт сам:
1. Клонирует Rules в `~/CursorRules` (SSH → если не вышло, HTTPS с логином)
2. Настраивает SSH-ключи и Gitea API (если ещё нет)
3. Копирует rules в текущий проект, настраивает remotes
4. Добавляет `init-cursor` в профиль shell
---
## Уже настроенный компьютер
```powershell
cd C:\path\to\your-repo
init-cursor
```
## Новый Linux-хост
```bash
cd ~/projects/your-repo
curl -fsSL https://git.kalinamall.ru/PapaTramp/Rules/raw/branch/main/install.sh | bash
init-cursor
```
Затем:
Если команда не найдена — один раз:
```powershell
. $HOME\CursorRules\init-cursor.ps1 # Windows
```
```bash
init-cursor
init-cursor --update
source ~/CursorRules/init-cursor.sh # Mac
```
## Что происходит внутри
---
1. **install.ps1 / install.sh** — shallow clone Rules по HTTPS (первый раз)
2. **init-cursor** вызывает `Invoke-MachineBootstrap` / `invoke-machine-bootstrap.sh`:
- `local/git-user.conf` — git user.name / email
- `scripts/Setup-GitSsh*` — ключи и `~/.ssh/config`
- `scripts/Register-GiteaSshKeys*` — pubkey в Gitea API
- clone/update `$HOME/CursorRules` (SSH, fallback HTTPS)
3. Копирует `.cursorignore`, `.cursor/rules/*.mdc`, дополняет `.gitignore`
4. `Set-GitRemotes*` + `Ensure-GiteaHomeRepo.ps1` для текущего репозитория
## Обновить rules / скрипты
## Git remotes
```powershell
init-cursor -Update # Windows
```
| Remote | Хост | URL |
|--------|------|-----|
| `kalinamall` | git.kalinamall.ru | `ssh://git@git.kalinamall.ru:2222/PapaTramp/<Repo>.git` |
| `home` | git.papatramp.ru | `ssh://git@git.papatramp.ru:2222/PapaTramp/<Repo>.git` |
| `github` | github.com/PTah | `git@github.com:PTah/<Repo>.git` |
```bash
init-cursor --update # Mac
```
`origin` не используется. `Set-GitRemotes` переименует старый `origin` по хосту. Push/pull Rules: `git push kalinamall`.
Обновит `$HOME/CursorRules` с Gitea и перекопирует rules в проект.
## Конфиги (local/)
---
## Git remotes (в каждом проекте)
| Remote | Куда |
|--------|------|
| `kalinamall` | git.kalinamall.ru |
| `home` | git.papatramp.ru |
| `github` | github.com/PTah |
Push: `git push kalinamall`
---
## Конфиги (`local/`)
| Файл | Назначение |
|------|------------|
| `git-ssh-hosts.conf` | Хосты и профили SSH-ключей |
| `git-user.conf` | `user.name` / `user.email` |
| `git-ssh-hosts.conf` | SSH-хосты и ключи |
| `git-user.conf` | git user.name / email |
| `kalinamall-gitea.conf` | API kalinamall |
| `papatramp-gitea.conf` | API home Gitea |
+8 -3
View File
@@ -1,11 +1,16 @@
#Requires -Version 5.1
<#
.SYNOPSIS
Первая загрузка Rules и запуск init-cursor в текущем проекте.
Точка входа на новом ПК: clone Rules, bootstrap, init-cursor в текущем проекте.
.DESCRIPTION
SSH / HTTPS / ключи / remotes — автоматически. Запускать из каталога проекта.
На голом ПК: скопируйте этот файл с рабочей машины (scp/USB), затем:
& .\install.ps1
.EXAMPLE
git clone --depth 1 ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git $HOME\CursorRules
& $HOME\CursorRules\install.ps1
cd C:\path\to\your-repo
& $env:TEMP\install.ps1
#>
[CmdletBinding()]
param(
+52 -7
View File
@@ -1,17 +1,62 @@
#!/usr/bin/env bash
# Первая загрузка с Gitea: clone Rules и запуск init-cursor в текущем проекте.
# Первая загрузка Rules и init-cursor. SSH/HTTPS и bootstrap — автоматически.
set -euo pipefail
RULES_DEST="${RULES_DEST:-$HOME/CursorRules}"
HTTPS_URL="${HTTPS_URL:-https://git.kalinamall.ru/PapaTramp/Rules.git}"
SSH_URL="${SSH_URL:-ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git}"
SKIP_GIT_REMOTES=0
UPDATE=0
if [[ ! -d "$RULES_DEST/.git" ]]; then
echo '[*] Cloning Rules from Gitea (HTTPS, login once if asked)...'
[[ -e "$RULES_DEST" ]] && { echo "Path exists and is not a git repo: $RULES_DEST" >&2; exit 1; }
git clone --depth 1 "$HTTPS_URL" "$RULES_DEST"
echo "[+] Cloned to $RULES_DEST"
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"
init-cursor "$@"
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