Добавить bootstrap для новых ПК и Linux-скрипты.

SSH-ключи и Gitea API до clone Rules; init-cursor копирует из локального $HOME/CursorRules.
This commit is contained in:
2026-06-18 10:01:11 +10:00
parent cd7513d96c
commit bdf405e2c1
13 changed files with 1147 additions and 13 deletions
+140
View File
@@ -0,0 +1,140 @@
#Requires -Version 5.1
<#
.SYNOPSIS
Первичная настройка нового компьютера: SSH, Gitea keys, clone Rules, init-cursor в профиль.
.DESCRIPTION
1. git user.name / user.email
2. SSH-ключи и ~/.ssh/config
3. Регистрация pubkey в Gitea (kalinamall, papatramp)
4. git clone Rules -> $HOME\CursorRules
5. Подключение init-cursor в PowerShell profile
На голом ПК скопируйте каталог Rules с рабочей машины (scp/USB), затем:
.\bootstrap.ps1
.EXAMPLE
.\bootstrap.ps1
#>
[CmdletBinding()]
param(
[string]$RulesDest = '',
[string]$CloneUrl = 'ssh://git@git.kalinamall.lan:2222/PapaTramp/Rules.git',
[switch]$SkipClone,
[switch]$SkipProfile,
[switch]$WhatIf
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function Write-Step([string]$Message) { Write-Host "[*] $Message" -ForegroundColor Cyan }
function Write-Ok([string]$Message) { Write-Host "[+] $Message" -ForegroundColor Green }
function Write-Warn([string]$Message) { Write-Host "[!] $Message" -ForegroundColor Yellow }
$root = $PSScriptRoot
$configDir = Join-Path $root 'local'
if (-not $RulesDest) {
$RulesDest = Join-Path $HOME 'CursorRules'
}
function Read-KeyValueFile {
param([string]$Path)
$data = @{}
if (-not (Test-Path -LiteralPath $Path)) { return $data }
Get-Content -LiteralPath $Path | ForEach-Object {
if ($_ -match '^([^#=]+)=(.*)$') {
$data[$Matches[1].Trim()] = $Matches[2].Trim()
}
}
return $data
}
Write-Step 'Bootstrap: new machine setup'
$userCfgPath = Join-Path $configDir 'git-user.conf'
if (Test-Path -LiteralPath $userCfgPath) {
$userCfg = Read-KeyValueFile -Path $userCfgPath
if ($userCfg.UserName) {
git config --global user.name $userCfg.UserName | Out-Null
Write-Ok "git user.name = $($userCfg.UserName)"
}
if ($userCfg.UserEmail) {
git config --global user.email $userCfg.UserEmail | Out-Null
Write-Ok "git user.email = $($userCfg.UserEmail)"
}
}
$setupArgs = @{
ConfigDir = $configDir
WhatIf = $WhatIf.IsPresent
}
& (Join-Path $root 'scripts\Setup-GitSsh.ps1') @setupArgs
$registerArgs = @{
ConfigDir = $configDir
WhatIf = $WhatIf.IsPresent
}
& (Join-Path $root 'scripts\Register-GiteaSshKeys.ps1') @registerArgs
if (-not $WhatIf) {
Write-Step 'Testing git@git.kalinamall.lan'
ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.lan 2>&1 | ForEach-Object { Write-Host $_ }
if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne 1) {
Write-Warn 'SSH test failed — check VPN/LAN and Gitea SSH keys'
}
}
if (-not $SkipClone) {
if ($WhatIf) {
Write-Step "WhatIf: clone $CloneUrl -> $RulesDest"
}
elseif (Test-Path (Join-Path $RulesDest '.git')) {
Write-Step "Updating $RulesDest"
git -C $RulesDest pull --ff-only
Write-Ok 'CursorRules updated'
}
else {
if (Test-Path -LiteralPath $RulesDest) {
throw "Path exists and is not a git repo: $RulesDest"
}
Write-Step "Cloning $CloneUrl"
git clone $CloneUrl $RulesDest
Write-Ok "Cloned to $RulesDest"
}
}
if (-not $SkipProfile) {
$profileHook = ". `"$RulesDest\init-cursor.ps1`""
$profilePath = $PROFILE.CurrentUserAllHosts
if (-not $profilePath) { $profilePath = $PROFILE.CurrentUserCurrentHost }
if ($WhatIf) {
Write-Step "WhatIf: add to profile $profilePath"
}
else {
$profileDir = Split-Path -Parent $profilePath
if (-not (Test-Path -LiteralPath $profileDir)) {
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
}
$profileText = if (Test-Path -LiteralPath $profilePath) {
Get-Content -LiteralPath $profilePath -Raw
} else {
''
}
if ($profileText -notmatch [regex]::Escape($profileHook)) {
if ($profileText -and -not $profileText.EndsWith("`n")) { $profileText += "`n" }
$profileText += $profileHook + "`n"
Set-Content -LiteralPath $profilePath -Value $profileText.TrimEnd() -Encoding UTF8
Write-Ok "Profile updated: $profilePath"
}
else {
Write-Ok 'init-cursor already in profile'
}
}
}
Write-Host ''
Write-Ok 'Bootstrap complete. Open a new shell, then in a project: init-cursor'