156 lines
4.5 KiB
PowerShell
156 lines
4.5 KiB
PowerShell
# SSH Setup for git.etoth.dev
|
|
# Usage: powershell -ExecutionPolicy Bypass -File setup-git-ssh.ps1
|
|
# Or: Right-click → "Run with PowerShell"
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host " SSH Setup for git.etoth.dev" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Create SSH directory
|
|
$sshDir = "$env:USERPROFILE\.ssh"
|
|
$configFile = "$sshDir\config"
|
|
|
|
if (-not (Test-Path $sshDir)) {
|
|
Write-Host "→ Creating SSH directory..." -ForegroundColor Blue
|
|
New-Item -ItemType Directory -Path $sshDir -Force | Out-Null
|
|
Write-Host "✓ SSH directory created" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "✓ SSH directory exists" -ForegroundColor Green
|
|
}
|
|
|
|
# Create backup
|
|
if (Test-Path $configFile) {
|
|
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
|
|
$backupFile = "$configFile.backup.$timestamp"
|
|
Copy-Item $configFile $backupFile
|
|
Write-Host "✓ Backup created: $backupFile" -ForegroundColor Green
|
|
}
|
|
|
|
# Check if already configured
|
|
$configExists = $false
|
|
if (Test-Path $configFile) {
|
|
$content = Get-Content $configFile -Raw
|
|
if ($content -match "Host git\.etoth\.dev") {
|
|
$configExists = $true
|
|
}
|
|
}
|
|
|
|
if ($configExists) {
|
|
Write-Host ""
|
|
Write-Host "⚠ git.etoth.dev is already configured!" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
$overwrite = Read-Host "Do you want to overwrite the configuration? (y/n)"
|
|
|
|
if ($overwrite -ne "y" -and $overwrite -ne "Y") {
|
|
Write-Host "→ Setup cancelled." -ForegroundColor Blue
|
|
Write-Host ""
|
|
pause
|
|
exit
|
|
}
|
|
|
|
# Remove old configuration (simplified version)
|
|
$content = Get-Content $configFile
|
|
$newContent = @()
|
|
$skip = $false
|
|
|
|
foreach ($line in $content) {
|
|
if ($line -match "# Gitea Server git\.etoth\.dev") {
|
|
$skip = $true
|
|
}
|
|
if (-not $skip) {
|
|
$newContent += $line
|
|
}
|
|
if ($skip -and $line -match "^\s*$") {
|
|
$skip = $false
|
|
}
|
|
}
|
|
|
|
$newContent | Set-Content $configFile
|
|
Write-Host "✓ Old configuration removed" -ForegroundColor Green
|
|
}
|
|
|
|
# Add new configuration
|
|
Write-Host "→ Adding SSH configuration..." -ForegroundColor Blue
|
|
|
|
$sshConfig = @"
|
|
|
|
# Gitea Server git.etoth.dev
|
|
Host git.etoth.dev
|
|
HostName git.etoth.dev
|
|
User git
|
|
Port 222
|
|
StrictHostKeyChecking accept-new
|
|
|
|
"@
|
|
|
|
Add-Content -Path $configFile -Value $sshConfig
|
|
|
|
Write-Host "✓ SSH configuration added!" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Check for SSH key
|
|
$keyExists = (Test-Path "$sshDir\id_ed25519") -or (Test-Path "$sshDir\id_rsa")
|
|
|
|
if (-not $keyExists) {
|
|
Write-Host "⚠ No SSH key found!" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
$createKey = Read-Host "Do you want to create a new SSH key? (y/n)"
|
|
|
|
if ($createKey -eq "y" -or $createKey -eq "Y") {
|
|
Write-Host ""
|
|
$email = Read-Host "Your email address"
|
|
|
|
ssh-keygen -t ed25519 -C "$email" -f "$sshDir\id_ed25519"
|
|
|
|
Write-Host ""
|
|
Write-Host "✓ SSH key created!" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "Your public key:" -ForegroundColor Blue
|
|
Write-Host "----------------------------------------"
|
|
Get-Content "$sshDir\id_ed25519.pub"
|
|
Write-Host "----------------------------------------"
|
|
Write-Host ""
|
|
Write-Host "Add this key to Gitea:"
|
|
Write-Host " Settings → SSH/GPG Keys → Add Key"
|
|
Write-Host ""
|
|
}
|
|
}
|
|
|
|
# Test connection
|
|
Write-Host ""
|
|
$test = Read-Host "Do you want to test the connection? (y/n)"
|
|
|
|
if ($test -eq "y" -or $test -eq "Y") {
|
|
Write-Host ""
|
|
Write-Host "→ Testing connection to git.etoth.dev..." -ForegroundColor Blue
|
|
Write-Host ""
|
|
|
|
try {
|
|
ssh -T git@git.etoth.dev 2>&1
|
|
} catch {
|
|
# Ignore errors as ssh -T returns non-zero exit code
|
|
}
|
|
|
|
Write-Host ""
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host " Setup completed successfully!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "You can now use Git:"
|
|
Write-Host ""
|
|
Write-Host " git clone git@git.etoth.dev:user/repo.git"
|
|
Write-Host " git push"
|
|
Write-Host " git pull"
|
|
Write-Host ""
|
|
Write-Host "More information:"
|
|
Write-Host " Show SSH config: Get-Content `$env:USERPROFILE\.ssh\config"
|
|
Write-Host " Edit SSH config: notepad `$env:USERPROFILE\.ssh\config"
|
|
Write-Host ""
|
|
|
|
pause
|