-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-bootstrap-repository
executable file
·58 lines (53 loc) · 1.46 KB
/
gh-bootstrap-repository
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
#!/bin/bash
repo="DoodleScheduling/gh-bootstrap-repository"
extension_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
tag_path="${extension_path}/dist"
exe="gh-bootstrap-repository"
platform=""
extension=""
determine_platform() {
local arch
arch="$(uname -m)"
if uname -a | grep Msys > /dev/null; then
extension=".exe"
if [ $arch = "x86_64" ]; then
platform="windows_amd64"
fi
elif uname -a | grep Darwin > /dev/null; then
if [ $arch = "x86_64" ]; then
platform="darwin_amd64"
elif [ $arch = "arm64" ]; then
platform="darwin_arm64"
fi
elif uname -a | grep Linux > /dev/null; then
if [ $arch = "x86_64" ]; then
platform="linux_amd64"
elif [ $arch = "arm64" ]; then
platform="linux_arm64"
fi
fi
}
download_latest_release() {
mkdir -p "${tag_path}"
gh release -R "${repo}" download --pattern "*${platform}*" --dir="${tag_path}"
tar=$(ls ${tag_path}/${exe}_*_${platform}.tar.gz)
tar -xzf $tar -C "${tag_path}"
}
if [ ! -e "${tag_path}/${exe}" ]; then
determine_platform
if [ "${platform}" == "" ]; then
if [ "$(which go)" == "" ]; then
echo "go must be installed to use this gh extension on this platform"
exit 1
fi
mkdir -p "${tag_path}"
pushd "${extension_path}" > /dev/null
go build -o "${tag_path}/${exe}"
popd > /dev/null
else
if [ ! -d "${tag_path}" ]; then
download_latest_release
fi
fi
fi
exec "${tag_path}/${exe}" "$@"