Scripts for ssh
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user