Scripts for ssh
This commit is contained in:
24
scripts/SCRIPTS.md
Normal file
24
scripts/SCRIPTS.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
## Download SSH Setup Scripts
|
||||||
|
|
||||||
|
Choose the appropriate script for your operating system:
|
||||||
|
|
||||||
|
- 🐧 **Linux / macOS / Git Bash**: [setup-git-ssh.sh](https://git.etoth.dev/setup-git-ssh.sh)
|
||||||
|
- 🪟 **Windows PowerShell**: [setup-git-ssh.ps1](https://git.etoth.dev/setup-git-ssh.ps1)
|
||||||
|
- 🪟 **Windows CMD**: [setup-git-ssh.bat](https://git.etoth.dev/setup-git-ssh.bat)
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
**Linux/macOS/Git Bash:**
|
||||||
|
```bash
|
||||||
|
chmod +x setup-git-ssh.sh
|
||||||
|
./setup-git-ssh.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
**Windows PowerShell:**
|
||||||
|
```powershell
|
||||||
|
powershell -ExecutionPolicy Bypass -File setup-git-ssh.ps1
|
||||||
|
```
|
||||||
|
Or: Right-click → "Run with PowerShell"
|
||||||
|
|
||||||
|
**Windows CMD:**
|
||||||
|
Double-click `setup-git-ssh.bat`
|
||||||
132
scripts/setup-git-ssh.bat
Normal file
132
scripts/setup-git-ssh.bat
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
@echo off
|
||||||
|
REM SSH Setup for git.etoth.dev
|
||||||
|
REM Usage: Double-click setup-git-ssh.bat
|
||||||
|
|
||||||
|
setlocal enabledelayedexpansion
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ========================================
|
||||||
|
echo SSH Setup for git.etoth.dev
|
||||||
|
echo ========================================
|
||||||
|
echo.
|
||||||
|
|
||||||
|
set "SSH_DIR=%USERPROFILE%\.ssh"
|
||||||
|
set "CONFIG_FILE=%SSH_DIR%\config"
|
||||||
|
|
||||||
|
REM Create SSH directory
|
||||||
|
if not exist "%SSH_DIR%" (
|
||||||
|
echo -^> Creating SSH directory...
|
||||||
|
mkdir "%SSH_DIR%"
|
||||||
|
echo [OK] SSH directory created
|
||||||
|
) else (
|
||||||
|
echo [OK] SSH directory exists
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Create backup
|
||||||
|
if exist "%CONFIG_FILE%" (
|
||||||
|
set "TIMESTAMP=%date:~-4%%date:~-7,2%%date:~-10,2%_%time:~0,2%%time:~3,2%%time:~6,2%"
|
||||||
|
set "TIMESTAMP=!TIMESTAMP: =0!"
|
||||||
|
copy "%CONFIG_FILE%" "%CONFIG_FILE%.backup.!TIMESTAMP!" >nul 2>&1
|
||||||
|
echo [OK] Backup created
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Check if already configured
|
||||||
|
set "CONFIG_EXISTS=0"
|
||||||
|
if exist "%CONFIG_FILE%" (
|
||||||
|
findstr /C:"Host git.etoth.dev" "%CONFIG_FILE%" >nul 2>&1
|
||||||
|
if !errorlevel! equ 0 set "CONFIG_EXISTS=1"
|
||||||
|
)
|
||||||
|
|
||||||
|
if !CONFIG_EXISTS! equ 1 (
|
||||||
|
echo.
|
||||||
|
echo [!] git.etoth.dev is already configured!
|
||||||
|
echo.
|
||||||
|
set /p "OVERWRITE=Do you want to overwrite the configuration? (y/n): "
|
||||||
|
|
||||||
|
if /i not "!OVERWRITE!"=="y" (
|
||||||
|
echo -^> Setup cancelled.
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
|
exit /b
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Remove old configuration (simple method: rewrite entire config without git.etoth.dev)
|
||||||
|
echo [OK] Old configuration will be removed
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Add new configuration
|
||||||
|
echo -^> Adding SSH configuration...
|
||||||
|
|
||||||
|
(
|
||||||
|
echo.
|
||||||
|
echo # Gitea Server git.etoth.dev
|
||||||
|
echo Host git.etoth.dev
|
||||||
|
echo HostName git.etoth.dev
|
||||||
|
echo User git
|
||||||
|
echo Port 222
|
||||||
|
echo StrictHostKeyChecking accept-new
|
||||||
|
echo.
|
||||||
|
) >> "%CONFIG_FILE%"
|
||||||
|
|
||||||
|
echo [OK] SSH configuration added!
|
||||||
|
echo.
|
||||||
|
|
||||||
|
REM Check for SSH key
|
||||||
|
set "KEY_EXISTS=0"
|
||||||
|
if exist "%SSH_DIR%\id_ed25519" set "KEY_EXISTS=1"
|
||||||
|
if exist "%SSH_DIR%\id_rsa" set "KEY_EXISTS=1"
|
||||||
|
|
||||||
|
if !KEY_EXISTS! equ 0 (
|
||||||
|
echo [!] No SSH key found!
|
||||||
|
echo.
|
||||||
|
set /p "CREATE_KEY=Do you want to create a new SSH key? (y/n): "
|
||||||
|
|
||||||
|
if /i "!CREATE_KEY!"=="y" (
|
||||||
|
echo.
|
||||||
|
set /p "EMAIL=Your email address: "
|
||||||
|
|
||||||
|
ssh-keygen -t ed25519 -C "!EMAIL!" -f "%SSH_DIR%\id_ed25519"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo [OK] SSH key created!
|
||||||
|
echo.
|
||||||
|
echo Your public key:
|
||||||
|
echo ----------------------------------------
|
||||||
|
type "%SSH_DIR%\id_ed25519.pub"
|
||||||
|
echo ----------------------------------------
|
||||||
|
echo.
|
||||||
|
echo Add this key to Gitea:
|
||||||
|
echo Settings -^> SSH/GPG Keys -^> Add Key
|
||||||
|
echo.
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Test connection
|
||||||
|
echo.
|
||||||
|
set /p "TEST=Do you want to test the connection? (y/n): "
|
||||||
|
|
||||||
|
if /i "!TEST!"=="y" (
|
||||||
|
echo.
|
||||||
|
echo -^> Testing connection to git.etoth.dev...
|
||||||
|
echo.
|
||||||
|
ssh -T git@git.etoth.dev 2>&1
|
||||||
|
echo.
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ========================================
|
||||||
|
echo Setup completed successfully!
|
||||||
|
echo ========================================
|
||||||
|
echo.
|
||||||
|
echo You can now use Git:
|
||||||
|
echo.
|
||||||
|
echo git clone git@git.etoth.dev:user/repo.git
|
||||||
|
echo git push
|
||||||
|
echo git pull
|
||||||
|
echo.
|
||||||
|
echo More information:
|
||||||
|
echo Show SSH config: type %%USERPROFILE%%\.ssh\config
|
||||||
|
echo Edit SSH config: notepad %%USERPROFILE%%\.ssh\config
|
||||||
|
echo.
|
||||||
|
|
||||||
|
pause
|
||||||
155
scripts/setup-git-ssh.ps1
Normal file
155
scripts/setup-git-ssh.ps1
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
# 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
|
||||||
126
scripts/setup-git-ssh.sh
Normal file
126
scripts/setup-git-ssh.sh
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# SSH Setup for git.etoth.dev
|
||||||
|
# Usage: bash setup-git-ssh.sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "========================================"
|
||||||
|
echo " SSH Setup for git.etoth.dev"
|
||||||
|
echo "========================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Create SSH directory
|
||||||
|
SSH_DIR="$HOME/.ssh"
|
||||||
|
SSH_CONFIG="$SSH_DIR/config"
|
||||||
|
|
||||||
|
if [ ! -d "$SSH_DIR" ]; then
|
||||||
|
echo -e "${BLUE}→ Creating SSH directory...${NC}"
|
||||||
|
mkdir -p "$SSH_DIR"
|
||||||
|
chmod 700 "$SSH_DIR"
|
||||||
|
echo -e "${GREEN}✓ SSH directory created${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}✓ SSH directory exists${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create backup
|
||||||
|
if [ -f "$SSH_CONFIG" ]; then
|
||||||
|
BACKUP_FILE="$SSH_CONFIG.backup.$(date +%Y%m%d_%H%M%S)"
|
||||||
|
cp "$SSH_CONFIG" "$BACKUP_FILE"
|
||||||
|
echo -e "${GREEN}✓ Backup created: $BACKUP_FILE${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if already configured
|
||||||
|
if grep -q "^Host git.etoth.dev" "$SSH_CONFIG" 2>/dev/null; then
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}⚠ git.etoth.dev is already configured!${NC}"
|
||||||
|
echo ""
|
||||||
|
read -p "Do you want to overwrite the configuration? (y/n): " OVERWRITE
|
||||||
|
|
||||||
|
if [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "Y" ]; then
|
||||||
|
echo -e "${BLUE}→ Setup cancelled.${NC}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove old configuration
|
||||||
|
sed -i.bak '/^# Gitea Server git.etoth.dev/,/^$/d' "$SSH_CONFIG" 2>/dev/null || \
|
||||||
|
sed -i '' '/^# Gitea Server git.etoth.dev/,/^$/d' "$SSH_CONFIG" 2>/dev/null || true
|
||||||
|
echo -e "${GREEN}✓ Old configuration removed${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add new configuration
|
||||||
|
echo -e "${BLUE}→ Adding SSH configuration...${NC}"
|
||||||
|
|
||||||
|
cat >> "$SSH_CONFIG" << 'EOF'
|
||||||
|
|
||||||
|
# Gitea Server git.etoth.dev
|
||||||
|
Host git.etoth.dev
|
||||||
|
HostName git.etoth.dev
|
||||||
|
User git
|
||||||
|
Port 222
|
||||||
|
StrictHostKeyChecking accept-new
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod 600 "$SSH_CONFIG"
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ SSH configuration added!${NC}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check for SSH key
|
||||||
|
if [ ! -f "$SSH_DIR/id_ed25519" ] && [ ! -f "$SSH_DIR/id_rsa" ]; then
|
||||||
|
echo -e "${YELLOW}⚠ No SSH key found!${NC}"
|
||||||
|
echo ""
|
||||||
|
read -p "Do you want to create a new SSH key? (y/n): " CREATE_KEY
|
||||||
|
|
||||||
|
if [ "$CREATE_KEY" == "y" ] || [ "$CREATE_KEY" == "Y" ]; then
|
||||||
|
echo ""
|
||||||
|
read -p "Your email address: " EMAIL
|
||||||
|
ssh-keygen -t ed25519 -C "$EMAIL" -f "$SSH_DIR/id_ed25519"
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}✓ SSH key created!${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}Your public key:${NC}"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
cat "$SSH_DIR/id_ed25519.pub"
|
||||||
|
echo "----------------------------------------"
|
||||||
|
echo ""
|
||||||
|
echo "Add this key to Gitea:"
|
||||||
|
echo " Settings → SSH/GPG Keys → Add Key"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Test connection
|
||||||
|
echo ""
|
||||||
|
read -p "Do you want to test the connection? (y/n): " TEST
|
||||||
|
|
||||||
|
if [ "$TEST" == "y" ] || [ "$TEST" == "Y" ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}→ Testing connection to git.etoth.dev...${NC}"
|
||||||
|
echo ""
|
||||||
|
ssh -T git@git.etoth.dev 2>&1 || true
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}========================================"
|
||||||
|
echo " Setup completed successfully!"
|
||||||
|
echo "========================================${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "You can now use Git:"
|
||||||
|
echo ""
|
||||||
|
echo " git clone git@git.etoth.dev:user/repo.git"
|
||||||
|
echo " git push"
|
||||||
|
echo " git pull"
|
||||||
|
echo ""
|
||||||
|
echo "More information:"
|
||||||
|
echo " Show SSH config: cat ~/.ssh/config"
|
||||||
|
echo " Edit SSH config: nano ~/.ssh/config"
|
||||||
|
echo ""
|
||||||
Reference in New Issue
Block a user