-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.sh
More file actions
93 lines (85 loc) · 3.03 KB
/
Copy pathgit.sh
File metadata and controls
93 lines (85 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
# Git bootstrapper
# https://git-scm.com/
APP_NAME="Git"
OS=$(uname -s)
ARCH=$(uname -m)
# --- Detect distro (Linux only) ---
detect_distro() {
DISTRO=""
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID $ID_LIKE" in
*arch*) DISTRO="arch" ;;
*debian*|*ubuntu*) DISTRO="debian" ;;
*fedora*|*rhel*|*centos*) DISTRO="fedora" ;;
esac
fi
if [ -z "$DISTRO" ]; then
command -v pacman >/dev/null 2>&1 && DISTRO="arch"
command -v dpkg >/dev/null 2>&1 && DISTRO="debian"
command -v rpm >/dev/null 2>&1 && DISTRO="fedora"
fi
}
set -e
case "$OS" in
Darwin)
if command -v brew >/dev/null 2>&1; then
echo "Installing ${APP_NAME} via Homebrew..."
brew install git
elif command -v port >/dev/null 2>&1; then
echo "Installing ${APP_NAME} via MacPorts..."
sudo port install git
else
# Xcode Command Line Tools include git — no package manager needed
echo "Installing ${APP_NAME} via Xcode Command Line Tools..."
xcode-select --install
echo "Follow the prompt to complete installation."
exit 0
fi
echo "Done! $(git --version)"
;;
Linux)
detect_distro
case "$DISTRO" in
debian) sudo apt-get install -y git ;;
fedora) sudo dnf install -y git ;;
arch) sudo pacman -Syu --noconfirm git ;;
*)
echo "Error: unsupported distro. Install git manually from https://git-scm.com/" >&2
exit 1
;;
esac
echo "Done! $(git --version)"
;;
MINGW*|CYGWIN*|MSYS*)
if command -v winget.exe >/dev/null 2>&1; then
echo "Installing ${APP_NAME} via winget..."
set +e
winget.exe install --id Git.Git -e --source winget
EC=$?
set -e
[ "$EC" = "0" ] || [ "$EC" = "43" ] || exit "$EC"
echo "Done! Restart your terminal for PATH changes to apply."
else
echo "Fetching latest Git for Windows release..."
API_JSON=$(curl -fsSL "https://api.github.com/repos/git-for-windows/git/releases/latest")
TAG=$(echo "$API_JSON" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')
VERSION=$(echo "$TAG" | sed 's/^v//;s/\.windows\.[0-9]*//')
case "$ARCH" in
arm64) FILENAME="Git-${VERSION}-arm64.exe" ;;
*) FILENAME="Git-${VERSION}-64-bit.exe" ;;
esac
DOWNLOAD_URL="https://github.com/git-for-windows/git/releases/download/${TAG}/${FILENAME}"
echo "Downloading: ${DOWNLOAD_URL}"
DEST="${TEMP}/GitInstaller.exe"
curl -fSL -o "$DEST" "$DOWNLOAD_URL"
echo "Launching installer..."
cmd.exe /c start "" "$DEST"
fi
;;
*)
echo "Error: unsupported OS: $OS" >&2
exit 1
;;
esac