forked from MunifTanjim/scripts.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-gh
executable file
·49 lines (38 loc) · 953 Bytes
/
setup-gh
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
#!/usr/bin/env bash
set -euo pipefail
ensure_tool() {
local -r tool="${1}"
if ! type "${tool}" >/dev/null 2>&1; then
echo "missing required tool: ${tool}"
exit 1
fi
}
setup_for_darwin() {
ensure_tool brew
brew install gh
}
setup_for_debian() {
ensure_tool curl
ensure_tool dpkg
ensure_tool jq
ensure_tool wget
local -r repo="cli/cli"
local -r url_pattern="linux_amd64.deb"
local -r url=$(curl -s "https://api.github.com/repos/${repo}/releases/latest" | jq -r --arg pattern "${url_pattern}" '.assets | map(.browser_download_url) | map(select(. | test($pattern)))[0]')
local -r filename=$(basename "${url}")
cd /tmp
wget --continue --quiet --show-progress --timestamping "${url}" -O "${filename}"
sudo dpkg --install "${filename}"
}
setup_gh() {
case $OSTYPE in
darwin*)
setup_for_darwin;;
linux*)
setup_for_debian;;
*)
echo "Unknown OS!"
exit 1;;
esac
}
setup_gh