-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrun_once_220_install_github_cli.sh.tmpl
More file actions
executable file
·59 lines (48 loc) · 1.48 KB
/
run_once_220_install_github_cli.sh.tmpl
File metadata and controls
executable file
·59 lines (48 loc) · 1.48 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
#!/bin/bash -e
# From: https://krew.sigs.k8s.io/docs/user-guide/setup/install/
echo "Installing https://cli.github.com/"
version="2.68.1"
unamestr=$(uname)
# Use mktemp in a way that works on both macOS and Linux
if [[ "$unamestr" == 'Darwin' ]]; then
tmp_dir=$(mktemp -d -t github-cli.XXX)
else
tmp_dir=$(mktemp --directory --tmpdir=/tmp github-cli.XXX)
fi
# Set OS architecture and file extension appropriately
if [[ "$unamestr" == 'Darwin' ]]; then
os_arch="macOS_amd64"
file_ext="zip"
elif [[ "$unamestr" == 'Linux' ]]; then
os_arch="linux_amd64"
file_ext="tar.gz"
else
echo "I don't support installing in this OS yet!"
exit 1
fi
url="https://github.com/cli/cli/releases/download/v${version}/gh_${version}_${os_arch}.${file_ext}"
archive_path="${tmp_dir}/archive.${file_ext}"
echo "Downloading from: $url"
curl -L "$url" -o "$archive_path"
cd "$tmp_dir"
pwd
ls -l
# Extract based on the file extension
if [[ "$file_ext" == "zip" ]]; then
unzip "$archive_path"
# Find the directory that was created after extraction
extracted_dir=$(find . -type d -name "gh_*" | head -1)
if [[ -n "$extracted_dir" ]]; then
cd "$extracted_dir"
fi
else
tar --strip-components=1 -xzvf "$archive_path"
fi
rm -f "$archive_path"
ls -l
# Create destination directory if it doesn't exist
mkdir -p ~/.local/opt/github-cli
rm -rf ~/.local/opt/github-cli/*
mv ./* ~/.local/opt/github-cli/
echo "GitHub CLI installed successfully to ~/.local/opt/github-cli/"
exit 0