git 이 없으면 설치하는 부분 추가
This commit is contained in:
1 parent
d2eb316853
commit
3e2ac25713
2 files changed
+222
-14
No files matched your search
@@ -48,6 +48,8 @@ $ErrorActionPreference = 'Stop'
|
||||
# ────────────────────────────────────────────
|
||||
$REPO = "jesseduffield/lazygit"
|
||||
$API_URL = "https://api.github.com/repos/$REPO/releases"
|
||||
$GIT_REPO = "git-for-windows/git"
|
||||
$GIT_API_URL = "https://api.github.com/repos/$GIT_REPO/releases"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Utility functions
|
||||
@@ -62,6 +64,156 @@ function Write-Err { param([string]$msg) Write-Host "[ERROR] $msg" -Foregrou
|
||||
# ────────────────────────────────────────────
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Check for git (required by lazygit)
|
||||
# ────────────────────────────────────────────
|
||||
function Install-GitPortable {
|
||||
Write-Info "git is not installed. Installing PortableGit..."
|
||||
|
||||
# Detect architecture
|
||||
$envArch = $env:PROCESSOR_ARCHITEW6432
|
||||
if (-not $envArch) { $envArch = $env:PROCESSOR_ARCHITECTURE }
|
||||
|
||||
$gitArch = ""
|
||||
if ($envArch -eq "AMD64") {
|
||||
$gitArch = "64-bit"
|
||||
} elseif ($envArch -eq "ARM64") {
|
||||
$gitArch = "arm64"
|
||||
} else {
|
||||
Write-Err "Unsupported architecture for PortableGit: $envArch"
|
||||
}
|
||||
|
||||
# Find latest Git for Windows release
|
||||
Write-Info "Fetching latest Git for Windows release..."
|
||||
try {
|
||||
$releases = Invoke-RestMethod -Uri $GIT_API_URL -UseBasicParsing `
|
||||
-Headers @{ 'User-Agent' = 'install-lazygit-ps1' }
|
||||
} catch {
|
||||
Write-Err "Failed to call GitHub API for Git: $_"
|
||||
}
|
||||
|
||||
$latestRelease = $releases | Where-Object { $_.prerelease -eq $false } | Select-Object -First 1
|
||||
if (-not $latestRelease) {
|
||||
Write-Err "Could not find latest Git for Windows release."
|
||||
}
|
||||
|
||||
$tagName = $latestRelease.tag_name
|
||||
# Git for Windows tags look like "v2.54.0.windows.1"
|
||||
$gitVersion = $tagName -replace '^v', '' -replace '\.windows\.\d+$', ''
|
||||
Write-Info "Latest Git for Windows: $tagName (version $gitVersion)"
|
||||
|
||||
# Find the PortableGit asset for our architecture
|
||||
$portablePattern = "PortableGit-${gitVersion}-${gitArch}.7z.exe"
|
||||
$asset = $latestRelease.assets | Where-Object { $_.name -eq $portablePattern } | Select-Object -First 1
|
||||
|
||||
if (-not $asset) {
|
||||
Write-Err "Could not find PortableGit asset matching '$portablePattern' in release $tagName."
|
||||
}
|
||||
|
||||
$downloadUrl = $asset.browser_download_url
|
||||
$installPath = Join-Path $env:USERPROFILE "PortableGit"
|
||||
|
||||
# Download
|
||||
$tmpDir = Join-Path $env:TEMP "git_install_$(Get-Random)"
|
||||
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
|
||||
$zipPath = Join-Path $tmpDir "$portablePattern"
|
||||
|
||||
try {
|
||||
Write-Info "Downloading: $downloadUrl"
|
||||
$ProgressPreference = 'SilentlyContinue'
|
||||
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
|
||||
$ProgressPreference = 'Continue'
|
||||
|
||||
# PortableGit .7z.exe is a self-extracting archive
|
||||
# Run it to extract to the install path
|
||||
Write-Info "Extracting PortableGit to $installPath..."
|
||||
|
||||
# Try 7z first, then fall back to running the .7z.exe self-extractor
|
||||
$extracted = $false
|
||||
if (Get-Command 7z -ErrorAction SilentlyContinue) {
|
||||
& 7z x $zipPath -o"$installPath" -y 2>&1 | Out-Null
|
||||
$extracted = $true
|
||||
} else {
|
||||
# The .7z.exe is a self-extracting archive; run it with -y and -o"path"
|
||||
# It needs to be run as an executable
|
||||
try {
|
||||
& $zipPath -y -o"$installPath" 2>&1 | Out-Null
|
||||
$extracted = $true
|
||||
} catch {
|
||||
Write-Warn "Self-extractor failed, trying PowerShell expansion..."
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $extracted) {
|
||||
Write-Err "Cannot extract PortableGit. Install 7-Zip or install git manually from https://git-scm.com/download/win"
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (Test-Path $tmpDir) {
|
||||
Remove-Item -Path $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# Verify git.exe
|
||||
$gitExe = Join-Path $installPath "cmd\git.exe"
|
||||
if (-not (Test-Path $gitExe)) {
|
||||
# Try bin directory as fallback
|
||||
$gitExe = Join-Path $installPath "bin\git.exe"
|
||||
}
|
||||
if (-not (Test-Path $gitExe)) {
|
||||
# Search recursively
|
||||
$found = Get-ChildItem -Path $installPath -Recurse -Filter "git.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
|
||||
if ($found) { $gitExe = $found.FullName }
|
||||
}
|
||||
|
||||
if (-not (Test-Path $gitExe)) {
|
||||
Write-Err "git.exe not found after extraction. Please install git manually."
|
||||
}
|
||||
|
||||
# Add git's directory to PATH for this session and permanently
|
||||
$gitDir = Split-Path $gitExe
|
||||
if ($env:Path -notlike "*$gitDir*") {
|
||||
$env:Path = "$gitDir;$env:Path"
|
||||
Write-Info "Added $gitDir to PATH for this session"
|
||||
}
|
||||
|
||||
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
if ($userPath -notlike "*$gitDir*") {
|
||||
[System.Environment]::SetEnvironmentVariable('Path', "$gitDir;$userPath", 'User')
|
||||
Write-Success "Added $gitDir to user PATH permanently"
|
||||
} else {
|
||||
Write-Info "$gitDir already in user PATH"
|
||||
}
|
||||
|
||||
# Also add the main bin dir for bash, ssh, etc.
|
||||
$gitBinDir = Join-Path $installPath "bin"
|
||||
if ((Test-Path $gitBinDir) -and ($env:Path -notlike "*$gitBinDir*")) {
|
||||
$env:Path = "$gitBinDir;$env:Path"
|
||||
$userPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
if ($userPath -notlike "*$gitBinDir*") {
|
||||
[System.Environment]::SetEnvironmentVariable('Path', "$gitBinDir;$userPath", 'User')
|
||||
Write-Success "Added $gitBinDir to user PATH permanently"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Success "PortableGit installed to $installPath"
|
||||
}
|
||||
|
||||
# Check if git is available
|
||||
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
|
||||
if (-not $gitCmd) {
|
||||
Install-GitPortable
|
||||
|
||||
# Refresh PATH and re-check
|
||||
$env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'User') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
|
||||
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
|
||||
if (-not $gitCmd) {
|
||||
Write-Err "git installation failed. Please install git manually from https://git-scm.com/download/win and re-run this script."
|
||||
}
|
||||
}
|
||||
|
||||
Write-Success "git is available: $($gitCmd.Source)"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Architecture detection
|
||||
# ────────────────────────────────────────────
|
||||
|
||||
+70
-14
@@ -24,9 +24,59 @@ INSTALL_DIR="${HOME}/.local/bin"
|
||||
# ────────────────────────────────────────────
|
||||
info() { echo "[INFO] $*" >&2; }
|
||||
warn() { echo "[WARN] $*" >&2; }
|
||||
error() { echo "[ERROR] $*" >&2; exit 1; }
|
||||
error() {
|
||||
echo "[ERROR] $*" >&2
|
||||
exit 1
|
||||
}
|
||||
success() { echo "[OK] $*" >&2; }
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Check for git (required by lazygit)
|
||||
# ────────────────────────────────────────────
|
||||
if ! command -v git &>/dev/null; then
|
||||
info "git is not installed. Installing git..."
|
||||
case "$(uname -s)" in
|
||||
Darwin)
|
||||
if command -v brew &>/dev/null; then
|
||||
brew install -y git
|
||||
success "git installed via Homebrew"
|
||||
else
|
||||
error "Homebrew (brew) is required to install git on macOS. Install it from https://brew.sh/"
|
||||
fi
|
||||
;;
|
||||
Linux)
|
||||
if command -v apt-get &>/dev/null; then
|
||||
sudo apt-get update -y && sudo apt-get install -y git
|
||||
success "git installed via apt-get"
|
||||
elif command -v dnf &>/dev/null; then
|
||||
sudo dnf install -y git
|
||||
success "git installed via dnf"
|
||||
elif command -v yum &>/dev/null; then
|
||||
sudo yum install -y git
|
||||
success "git installed via yum"
|
||||
elif command -v zypper &>/dev/null; then
|
||||
sudo zypper -n install git
|
||||
success "git installed via zypper"
|
||||
elif command -v pacman &>/dev/null; then
|
||||
sudo pacman -S --noconfirm git
|
||||
success "git installed via pacman"
|
||||
else
|
||||
error "No supported package manager found. Install git manually."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
error "Cannot auto-install git on this OS. Please install git manually."
|
||||
;;
|
||||
esac
|
||||
|
||||
# Verify git is now available
|
||||
if ! command -v git &>/dev/null; then
|
||||
error "git installation failed. Please install git manually and re-run this script."
|
||||
fi
|
||||
fi
|
||||
|
||||
info "git is available: $(command -v git)"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Check required commands
|
||||
# ────────────────────────────────────────────
|
||||
@@ -78,34 +128,40 @@ detect_platform() {
|
||||
# ── Linux (including Raspberry Pi) ──────────────────
|
||||
Linux)
|
||||
case "$arch" in
|
||||
x86_64|amd64)
|
||||
echo "linux_x86_64:tar.gz" ;;
|
||||
aarch64|arm64)
|
||||
x86_64 | amd64)
|
||||
echo "linux_x86_64:tar.gz"
|
||||
;;
|
||||
aarch64 | arm64)
|
||||
# RPi 4/5, 64bit OS
|
||||
echo "linux_arm64:tar.gz" ;;
|
||||
echo "linux_arm64:tar.gz"
|
||||
;;
|
||||
armv7l)
|
||||
# RPi 2/3, 32bit OS - use armv6 as fallback
|
||||
echo "linux_armv6:tar.gz" ;;
|
||||
echo "linux_armv6:tar.gz"
|
||||
;;
|
||||
armv6l)
|
||||
# RPi Zero / 1
|
||||
echo "linux_armv6:tar.gz" ;;
|
||||
i686|i386)
|
||||
echo "linux_32-bit:tar.gz" ;;
|
||||
echo "linux_armv6:tar.gz"
|
||||
;;
|
||||
i686 | i386)
|
||||
echo "linux_32-bit:tar.gz"
|
||||
;;
|
||||
*)
|
||||
error "Unsupported Linux architecture: $arch" ;;
|
||||
error "Unsupported Linux architecture: $arch"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
# ── FreeBSD ────────────────────────────────────────────
|
||||
FreeBSD)
|
||||
case "$arch" in
|
||||
amd64|x86_64) echo "freebsd_x86_64:tar.gz" ;;
|
||||
amd64 | x86_64) echo "freebsd_x86_64:tar.gz" ;;
|
||||
*) error "FreeBSD x86_64 is only supported (current: $arch)" ;;
|
||||
esac
|
||||
;;
|
||||
|
||||
# ── Windows (Git Bash / MSYS2 / Cygwin) ───────────────
|
||||
MINGW*|MSYS*|CYGWIN*)
|
||||
MINGW* | MSYS* | CYGWIN*)
|
||||
warn "Windows environment (Git Bash/MSYS2/Cygwin) detected."
|
||||
warn "Native .exe will be installed."
|
||||
case "$arch" in
|
||||
@@ -166,8 +222,8 @@ download_and_install() {
|
||||
filename="${url##*/}"
|
||||
|
||||
info "Downloading: $url"
|
||||
curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$url" \
|
||||
|| error "Download failed: $url"
|
||||
curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$url" ||
|
||||
error "Download failed: $url"
|
||||
|
||||
info "Extracting..."
|
||||
case "$ext" in
|
||||
|
||||
Reference in new issue
Block a user