Remotes: kalinamall, home, github по SSH (.ru); origin убран.
Set-GitRemotes переименует origin по хосту; SSH config для .ru через LAN IP.
This commit is contained in:
@@ -50,7 +50,15 @@ init-cursor --update
|
||||
3. Копирует `.cursorignore`, `.cursor/rules/*.mdc`, дополняет `.gitignore`
|
||||
4. `Set-GitRemotes*` + `Ensure-GiteaHomeRepo.ps1` для текущего репозитория
|
||||
|
||||
`bootstrap.ps1` / `bootstrap.sh` оставлены для ручного запуска без проекта.
|
||||
## Git remotes
|
||||
|
||||
| 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` |
|
||||
|
||||
`origin` не используется. `Set-GitRemotes` переименует старый `origin` по хосту. Push/pull Rules: `git push kalinamall`.
|
||||
|
||||
## Конфиги (local/)
|
||||
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ $ErrorActionPreference = 'Stop'
|
||||
|
||||
$rulesDest = Join-Path $HOME 'CursorRules'
|
||||
$httpsUrl = 'https://git.kalinamall.ru/PapaTramp/Rules.git'
|
||||
$sshUrl = 'ssh://git@git.kalinamall.lan:2222/PapaTramp/Rules.git'
|
||||
$sshUrl = 'ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git'
|
||||
|
||||
if (-not (Test-Path (Join-Path $rulesDest '.git'))) {
|
||||
Write-Host '[*] Cloning Rules from Gitea (HTTPS, login once if asked)...' -ForegroundColor Cyan
|
||||
|
||||
@@ -6,7 +6,7 @@ KeyComment=papatramp@kalinamall
|
||||
GiteaConfig=kalinamall-gitea.conf
|
||||
|
||||
[host:git.kalinamall.ru]
|
||||
HostName=git.kalinamall.ru
|
||||
HostName=192.168.160.129
|
||||
Port=2222
|
||||
User=git
|
||||
Profile=kalinamall-git
|
||||
@@ -23,7 +23,7 @@ KeyComment=papatramp@papatramp.ru
|
||||
GiteaConfig=papatramp-gitea.conf
|
||||
|
||||
[host:git.papatramp.ru]
|
||||
HostName=git.papatramp.ru
|
||||
HostName=192.168.128.48
|
||||
Port=2222
|
||||
User=git
|
||||
Profile=papatramp-git
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$Root,
|
||||
[string]$RulesDest = '',
|
||||
[string]$CloneUrl = 'ssh://git@git.kalinamall.lan:2222/PapaTramp/Rules.git',
|
||||
[string]$CloneUrl = 'ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git',
|
||||
[string]$HttpsCloneUrl = 'https://git.kalinamall.ru/PapaTramp/Rules.git',
|
||||
[switch]$SkipClone,
|
||||
[switch]$SkipProfile,
|
||||
@@ -66,7 +66,7 @@ function Test-MachineGitReady {
|
||||
if (-not (Test-Path -LiteralPath $keyPath)) { return $false }
|
||||
}
|
||||
|
||||
if ($sshText -notmatch '(?m)^Host\s+git\.kalinamall\.lan\s*$') { return $false }
|
||||
if ($sshText -notmatch '(?m)^Host\s+git\.kalinamall\.ru\s*$') { return $false }
|
||||
return $true
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ $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 $_ }
|
||||
Write-Step 'Testing git@git.kalinamall.ru'
|
||||
ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.ru 2>&1 | ForEach-Object { Write-Host $_ }
|
||||
}
|
||||
}
|
||||
elseif ($gitReady) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#Requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Стандартные git remote: home, kalinamall, github.
|
||||
Стандартные git remote: home (papatramp), kalinamall, github (PTah).
|
||||
|
||||
.EXAMPLE
|
||||
cd C:\Users\papat\Projects\MyRepo
|
||||
@@ -35,13 +35,23 @@ function Get-RepoName {
|
||||
return (Split-Path -Leaf (git rev-parse --show-toplevel))
|
||||
}
|
||||
|
||||
function Get-OriginRemoteTarget {
|
||||
$url = (git remote get-url origin 2>$null)
|
||||
if (-not $url) { return $null }
|
||||
$lower = $url.ToLower()
|
||||
if ($lower -match 'kalinamall') { return 'kalinamall' }
|
||||
if ($lower -match 'papatramp') { return 'home' }
|
||||
if ($lower -match 'github\.com') { return 'github' }
|
||||
return $null
|
||||
}
|
||||
|
||||
function Set-Remote {
|
||||
param(
|
||||
[string]$Name,
|
||||
[string]$Url
|
||||
)
|
||||
|
||||
$existing = git remote 2>$null
|
||||
$existing = @(git remote 2>$null)
|
||||
$has = $existing -contains $Name
|
||||
|
||||
if ($WhatIf) {
|
||||
@@ -60,9 +70,19 @@ function Set-Remote {
|
||||
return
|
||||
}
|
||||
|
||||
if ($existing -contains 'origin') {
|
||||
$originTarget = Get-OriginRemoteTarget
|
||||
if ($originTarget -eq $Name) {
|
||||
git remote rename origin $Name
|
||||
git remote set-url $Name $Url
|
||||
Write-Ok "remote origin renamed to $Name -> $Url"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
$legacy = @{
|
||||
home = @('gitea', 'papatramp', 'origin-home')
|
||||
github = @('origin')
|
||||
github = @()
|
||||
kalinamall = @('gitea-kalinamall', 'kalina')
|
||||
}
|
||||
foreach ($old in $legacy[$Name]) {
|
||||
@@ -81,16 +101,14 @@ function Set-Remote {
|
||||
Test-GitRepo
|
||||
$repoName = Get-RepoName -Name $Repo
|
||||
|
||||
$homeUrl = "ssh://git@git.papatramp.lan:2222/${Owner}/${repoName}.git"
|
||||
$kalinamallUrl = "ssh://git@git.kalinamall.lan:2222/${Owner}/${repoName}.git"
|
||||
$homeUrl = "ssh://git@git.papatramp.ru:2222/${Owner}/${repoName}.git"
|
||||
$kalinamallUrl = "ssh://git@git.kalinamall.ru:2222/${Owner}/${repoName}.git"
|
||||
$githubUrl = "git@github.com:${GithubOrg}/${repoName}.git"
|
||||
|
||||
Write-Step "Repo: $repoName"
|
||||
Set-Remote -Name 'home' -Url $homeUrl
|
||||
Set-Remote -Name 'kalinamall' -Url $kalinamallUrl
|
||||
Set-Remote -Name 'github' -Url $githubUrl
|
||||
if (-not $SkipKalinamall) {
|
||||
Set-Remote -Name 'kalinamall' -Url $kalinamallUrl
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Host 'Remotes:' -ForegroundColor Magenta
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# Стандартные git remote: home, kalinamall, github.
|
||||
# Стандартные git remote: home (papatramp), kalinamall, github (PTah).
|
||||
set -euo pipefail
|
||||
|
||||
OWNER="${OWNER:-PapaTramp}"
|
||||
GITHUB_ORG="${GITHUB_ORG:-PTah}"
|
||||
REPO="${REPO:-}"
|
||||
SKIP_KALINAMALL="${SKIP_KALINAMALL:-0}"
|
||||
WHAT_IF="${WHAT_IF:-0}"
|
||||
|
||||
log_step() { printf '[*] %s\n' "$1"; }
|
||||
@@ -17,14 +16,23 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
repo_name="${REPO:-$(basename "$(git rev-parse --show-toplevel)")}"
|
||||
home_url="ssh://git@git.papatramp.lan:2222/${OWNER}/${repo_name}.git"
|
||||
kalinamall_url="ssh://git@git.kalinamall.lan:2222/${OWNER}/${repo_name}.git"
|
||||
home_url="ssh://git@git.papatramp.ru:2222/${OWNER}/${repo_name}.git"
|
||||
kalinamall_url="ssh://git@git.kalinamall.ru:2222/${OWNER}/${repo_name}.git"
|
||||
github_url="git@github.com:${GITHUB_ORG}/${repo_name}.git"
|
||||
|
||||
origin_remote_target() {
|
||||
local url
|
||||
url="$(git remote get-url origin 2>/dev/null | tr '[:upper:]' '[:lower:]' || true)"
|
||||
[[ -z "$url" ]] && return 0
|
||||
if [[ "$url" == *kalinamall* ]]; then echo kalinamall; return 0; fi
|
||||
if [[ "$url" == *papatramp* ]]; then echo home; return 0; fi
|
||||
if [[ "$url" == *github.com* ]]; then echo github; return 0; fi
|
||||
}
|
||||
|
||||
set_remote() {
|
||||
local name="$1"
|
||||
local url="$2"
|
||||
local existing current old
|
||||
local existing current old origin_target
|
||||
|
||||
if [[ "$WHAT_IF" == '1' ]]; then
|
||||
log_step "WhatIf: remote $name -> $url"
|
||||
@@ -42,9 +50,19 @@ set_remote() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
if git remote | grep -Fxq origin; then
|
||||
origin_target="$(origin_remote_target || true)"
|
||||
if [[ "$origin_target" == "$name" ]]; then
|
||||
git remote rename origin "$name"
|
||||
git remote set-url "$name" "$url"
|
||||
log_ok "remote origin renamed to $name -> $url"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$name" in
|
||||
home) legacy=(gitea papatramp origin-home) ;;
|
||||
github) legacy=(origin) ;;
|
||||
github) legacy=() ;;
|
||||
kalinamall) legacy=(gitea-kalinamall kalina) ;;
|
||||
*) legacy=() ;;
|
||||
esac
|
||||
@@ -64,10 +82,8 @@ set_remote() {
|
||||
|
||||
log_step "Repo: $repo_name"
|
||||
set_remote home "$home_url"
|
||||
set_remote kalinamall "$kalinamall_url"
|
||||
set_remote github "$github_url"
|
||||
if [[ "$SKIP_KALINAMALL" != '1' ]]; then
|
||||
set_remote kalinamall "$kalinamall_url"
|
||||
fi
|
||||
|
||||
printf '\n'
|
||||
git remote -v
|
||||
|
||||
@@ -85,20 +85,16 @@ function Get-SshConfigBlock {
|
||||
) -join "`n"
|
||||
}
|
||||
|
||||
function Update-SshConfig {
|
||||
function Update-SshConfigText {
|
||||
param(
|
||||
[string]$ConfigPath,
|
||||
[string]$ExistingText,
|
||||
[string]$HostAlias,
|
||||
[string]$Block
|
||||
)
|
||||
|
||||
$begin = "# BEGIN Setup-SshAccess:$HostAlias"
|
||||
$end = "# END Setup-SshAccess:$HostAlias"
|
||||
$existing = if (Test-Path -LiteralPath $ConfigPath) {
|
||||
Get-Content -LiteralPath $ConfigPath -Raw
|
||||
} else {
|
||||
''
|
||||
}
|
||||
$existing = $ExistingText
|
||||
|
||||
$pattern = "(?ms)^$([regex]::Escape($begin)).*?$([regex]::Escape($end))\r?\n?"
|
||||
if ($existing -match $pattern) {
|
||||
@@ -174,7 +170,7 @@ foreach ($hostAlias in ($parsed.Hosts.Keys | Sort-Object)) {
|
||||
continue
|
||||
}
|
||||
|
||||
$configText = Update-SshConfig -ConfigPath $sshConfigPath -HostAlias $hostAlias -Block $block
|
||||
$configText = Update-SshConfigText -ExistingText $configText -HostAlias $hostAlias -Block $block
|
||||
Write-Ok "ssh config: $hostAlias"
|
||||
}
|
||||
|
||||
@@ -183,12 +179,12 @@ if (-not $WhatIf) {
|
||||
Add-Content -LiteralPath $sshConfigPath -Value '' -Encoding UTF8
|
||||
|
||||
Get-Service ssh-agent -ErrorAction SilentlyContinue | Where-Object { $_.Status -ne 'Running' } |
|
||||
ForEach-Object { Start-Service ssh-agent | Out-Null }
|
||||
ForEach-Object { Start-Service ssh-agent -ErrorAction SilentlyContinue | Out-Null }
|
||||
|
||||
foreach ($keyName in $profileKeys.Keys) {
|
||||
$keyPath = Join-Path $sshDir $keyName
|
||||
if (Test-Path -LiteralPath $keyPath) {
|
||||
ssh-add $keyPath 2>$null | Out-Null
|
||||
try { ssh-add $keyPath 2>$null | Out-Null } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ set -euo pipefail
|
||||
|
||||
ROOT="${ROOT:?ROOT is required}"
|
||||
RULES_DEST="${RULES_DEST:-$HOME/CursorRules}"
|
||||
CLONE_URL="${CLONE_URL:-ssh://git@git.kalinamall.lan:2222/PapaTramp/Rules.git}"
|
||||
CLONE_URL="${CLONE_URL:-ssh://git@git.kalinamall.ru:2222/PapaTramp/Rules.git}"
|
||||
HTTPS_CLONE_URL="${HTTPS_CLONE_URL:-https://git.kalinamall.ru/PapaTramp/Rules.git}"
|
||||
SKIP_CLONE="${SKIP_CLONE:-0}"
|
||||
SKIP_PROFILE="${SKIP_PROFILE:-0}"
|
||||
@@ -22,7 +22,7 @@ test_machine_git_ready() {
|
||||
local hosts_config="$CONFIG_DIR/git-ssh-hosts.conf"
|
||||
local ssh_config="$HOME/.ssh/config"
|
||||
[[ -f "$hosts_config" && -f "$ssh_config" ]] || return 1
|
||||
grep -q '^Host git.kalinamall.lan$' "$ssh_config" || return 1
|
||||
grep -q '^Host git.kalinamall.ru$' "$ssh_config" || return 1
|
||||
|
||||
local line current_profile='' key_name
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
@@ -109,8 +109,8 @@ if [[ "$git_ready" -eq 0 && "$SKIP_GIT_SETUP" != '1' ]]; then
|
||||
export CONFIG_DIR WHAT_IF
|
||||
bash "$ROOT/scripts/setup-git-ssh.sh"
|
||||
bash "$ROOT/scripts/register-gitea-ssh-keys.sh"
|
||||
log_step 'Testing git@git.kalinamall.lan'
|
||||
ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.lan || true
|
||||
log_step 'Testing git@git.kalinamall.ru'
|
||||
ssh -T -o BatchMode=yes -o ConnectTimeout=10 git@git.kalinamall.ru || true
|
||||
elif [[ "$git_ready" -eq 1 ]]; then
|
||||
log_ok 'Git SSH already configured'
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user