Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·65 lines (61 loc) · 2.2 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·65 lines (61 loc) · 2.2 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
#!/bin/bash
# set smart sudo
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
# Get auth token
export GITHUB_TOKEN=${!PARAM_GH_TOKEN}
[ -z "$GITHUB_TOKEN" ] && echo "A GitHub token must be supplied. Check the \"token\" parameter." && exit 1
echo "export GITHUB_TOKEN=\"${GITHUB_TOKEN}\"" >> "$BASH_ENV"
# Define current platform
if [[ "$(uname -s)" == "Darwin" && "$(uname -m)" == "x86_64" ]]; then
export SYS_ENV_PLATFORM=macos
elif [[ "$(uname -s)" == "Linux" && "$(uname -m)" == "x86_64" ]]; then
export SYS_ENV_PLATFORM=linux_x86
elif [[ "$(uname -s)" == "Linux" && "$(uname -m)" == "aarch64" ]]; then
export SYS_ENV_PLATFORM=linux_arm
else
echo "This platform appears to be unsupported."
uname -a
exit 1
fi
# If not installed
if ! command -v gh >/dev/null 2>&1; then
echo "Installing the GitHub CLI"
case $SYS_ENV_PLATFORM in
linux_x86)
curl -sSL "https://github.com/cli/cli/releases/download/v${PARAM_GH_CLI_VERSION}/gh_${PARAM_GH_CLI_VERSION}_linux_amd64.deb" -o "gh-cli.deb"
$SUDO apt install ./gh-cli.deb
rm gh-cli.deb
;;
macos)
curl -sSL "https://github.com/cli/cli/releases/download/v${PARAM_GH_CLI_VERSION}/gh_${PARAM_GH_CLI_VERSION}_macOS_amd64.tar.gz" -o "gh-cli.tar.gz"
$SUDO tar -xf ./gh-cli.tar.gz -C /usr/local/ --strip-components=1
rm gh-cli.tar.gz
;;
linux_arm)
curl -sSL "https://github.com/cli/cli/releases/download/v${PARAM_GH_CLI_VERSION}/gh_${PARAM_GH_CLI_VERSION}_linux_arm64.tar.gz" -o "gh-cli.tar.gz"
$SUDO tar -xf ./gh-cli.tar.gz -C /usr/local/ --strip-components=1
rm gh-cli.tar.gz
;;
*)
echo "This orb does not currently support your platform. If you believe it should, please consider opening an issue on the GitHub repository:"
echo "https://github.com/CircleCI-Public/github-cli-orb"
exit 1
;;
esac
# Validate install.
echo
echo "GH CLI installed"
command -v gh
else
echo "GH CLI is already installed."
fi
# Authenticate
echo
echo "Authenticating GH CLI"
git config --global credential.https://github.com.helper ''
git config --global --add credential.https://github.com.helper '!'"$(which gh) auth git-credential"
gh auth status
# Configure
echo
echo "Disabling interactive prompts for GH CLI"
gh config set prompt disabled