-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_gh.sh
More file actions
executable file
Β·156 lines (130 loc) Β· 5.52 KB
/
install_gh.sh
File metadata and controls
executable file
Β·156 lines (130 loc) Β· 5.52 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
set -e
echo "π GitHub CLI (gh) Installation Script"
echo "======================================"
OS="$(uname -s)"
# Function to check if gh is already installed
check_existing_installation() {
if command -v gh &> /dev/null; then
echo "β
GitHub CLI is already installed!"
echo "π Current version: $(gh --version)"
read -p "π€ Do you want to continue with the installation/upgrade? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "π Installation cancelled."
exit 0
fi
fi
}
# Function to verify installation
verify_installation() {
echo "π Verifying installation..."
if command -v gh &> /dev/null; then
echo "β
GitHub CLI successfully installed!"
echo "π Version: $(gh --version)"
echo ""
echo "π Next steps:"
echo "1. Run 'gh auth login' to authenticate with GitHub"
echo "2. Run 'gh --help' to see available commands"
echo "3. Run 'gh repo view' in a GitHub repository to test"
echo ""
echo "π Documentation: https://cli.github.com/manual/"
else
echo "β Installation failed. GitHub CLI not found in PATH."
exit 1
fi
}
check_existing_installation
case "$OS" in
Linux*)
echo "π§ Detected Linux system"
# Function to detect Linux distribution
if [[ -f /etc/os-release ]]; then
. /etc/os-release
DISTRO=$ID
elif type lsb_release >/dev/null 2>&1; then
DISTRO=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
else
echo "β Cannot detect Linux distribution"
exit 1
fi
echo "π Distribution: $DISTRO"
case $DISTRO in
ubuntu|debian|pop|linuxmint|elementary)
echo "π¦ Installing GitHub CLI on Ubuntu/Debian..."
# Install wget if not present
if ! command -v wget &> /dev/null; then
echo "π₯ Installing wget..."
sudo apt update
sudo apt install wget -y
fi
# Add GitHub CLI repository
echo "π Adding GitHub CLI repository..."
sudo mkdir -p -m 755 /etc/apt/keyrings
wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
# Update and install
echo "π Updating package list..."
sudo apt update
echo "π¦ Installing GitHub CLI..."
sudo apt install gh -y
;;
rhel|centos|fedora|rocky|almalinux)
echo "π¦ Installing GitHub CLI on RHEL/CentOS/Fedora..."
if command -v dnf &> /dev/null; then
sudo dnf install 'dnf-command(config-manager)' -y
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh --repo gh-cli -y
elif command -v yum &> /dev/null; then
sudo yum install yum-utils -y
sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo yum install gh -y
fi
;;
arch|manjaro|endeavouros)
echo "π¦ Installing GitHub CLI on Arch Linux..."
sudo pacman -Sy github-cli --noconfirm
;;
alpine)
echo "π¦ Installing GitHub CLI on Alpine Linux..."
sudo apk add github-cli
;;
*)
echo "β οΈ Distribution not directly supported, installing via binary..."
# Detect architecture
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
*) echo "β Unsupported architecture: $ARCH"; exit 1 ;;
esac
# Get latest version
LATEST_VERSION=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | grep -o '"tag_name": "v[^"]*' | grep -o 'v[^"]*')
echo "π₯ Downloading GitHub CLI $LATEST_VERSION..."
cd /tmp
wget -O gh.tar.gz "https://github.com/cli/cli/releases/download/${LATEST_VERSION}/gh_${LATEST_VERSION#v}_linux_${ARCH}.tar.gz"
tar -xzf gh.tar.gz
sudo mv gh_${LATEST_VERSION#v}_linux_${ARCH}/bin/gh /usr/local/bin/
sudo chmod +x /usr/local/bin/gh
rm -rf gh.tar.gz gh_${LATEST_VERSION#v}_linux_${ARCH}
;;
esac
;;
Darwin*)
echo "π Detected macOS system"
# Check if Homebrew is installed
if ! command -v brew &> /dev/null; then
echo "β Homebrew is required but not installed."
echo "Install it from https://brew.sh/"
exit 1
fi
echo "π¦ Installing GitHub CLI via Homebrew..."
brew install gh
;;
*)
echo "β Unsupported operating system: $OS"
exit 1
;;
esac
verify_installation