Remotes: kalinamall, home, github по SSH (.ru); origin убран.
Set-GitRemotes переименует origin по хосту; SSH config для .ru через LAN IP.
This commit is contained in:
@@ -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 { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user