-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist/ | ||
bin/ | ||
coverage.out | ||
ghsetup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,69 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
repo="github.com/k1LoW/gh-setup" | ||
# Get extension repository path | ||
extPath="$(dirname "$0")" | ||
|
||
extensionPath="$(dirname "$0")" | ||
cd "${extensionPath}" > /dev/null | ||
tag="$(git tag | tail -1)" | ||
# Get latest version | ||
cd "${extPath}" > /dev/null | ||
ver="$(git tag | grep ^v | sort --version-sort | tail -1)" | ||
if [ "${ver}" = "" ]; then | ||
git fetch --tags > /dev/null 2>&1 | ||
ver="$(git tag | grep ^v | sort --version-sort | tail -1)" | ||
fi | ||
cd - > /dev/null | ||
|
||
# Get arch | ||
arch="$(uname -m)" | ||
|
||
exe="" | ||
|
||
# Get binary file name | ||
exe="gh-setup" # default | ||
if uname -a | grep Msys > /dev/null; then | ||
if [ $arch = "x86_64" ]; then | ||
exe="gh-setup_${tag}_windows_amd64.exe" | ||
if [ "${arch}" = "x86_64" ]; then | ||
exe="gh-setup_${ver}_windows_amd64.exe" | ||
fi | ||
elif uname -a | grep Darwin > /dev/null; then | ||
if [ $arch = "x86_64" ]; then | ||
exe="gh-setup_${tag}_darwin_amd64" | ||
elif [ $arch = "arm64" ]; then | ||
exe="gh-setup_${tag}_darwin_arm64" | ||
if [ "${arch}" = "x86_64" ]; then | ||
exe="gh-setup_${ver}_darwin_amd64" | ||
elif [ "${arch}" = "arm64" ]; then | ||
exe="gh-setup_${ver}_darwin_arm64" | ||
fi | ||
elif uname -a | grep Linux > /dev/null; then | ||
if [ $arch = "x86_64" ]; then | ||
exe="gh-setup_${tag}_linux_amd64" | ||
if [ "${arch}" = "x86_64" ]; then | ||
exe="gh-setup_${ver}_linux_amd64" | ||
elif [ "${arch}" = "arm64" ] || [ "${arch}" = "aarch64" ]; then | ||
exe="gh-setup_${ver}_linux_arm64" | ||
fi | ||
fi | ||
|
||
if [ "${exe}" == "" ]; then | ||
# Cleanup bin/ dir | ||
rm -f "${extPath}/bin/*" | ||
mkdir -p "${extPath}/bin" | ||
|
||
binPath="${extPath}/bin/${exe}" | ||
|
||
if [ "${exe}" == "gh-setup" ]; then | ||
# Build binary | ||
if [ "$(which go)" = "" ]; then | ||
echo "go must be installed to use this gh extension on this platform" | ||
exit 1 | ||
fi | ||
|
||
exe="cmd.out" | ||
|
||
cd "${extensionPath}" > /dev/null | ||
go build -o "${exe}" cmd/gh-setup/main.go | ||
cd "${extPath}" > /dev/null | ||
go build -o "${binPath}" | ||
cd - > /dev/null | ||
mv "${exe}" "${extensionPath}/bin/${exe}" | ||
chmod +x "${extensionPath}/bin/${exe}" | ||
else | ||
if [[ ! -x "${extensionPath}/bin/${exe}" ]]; then | ||
mkdir -p "${extensionPath}/bin" | ||
rm -f ${extensionPath}/bin/gh-setup* | ||
gh release -R "${repo}" download "${tag}" -p "${exe}" --dir="${extensionPath}/bin" | ||
chmod +x "${extensionPath}/bin/${exe}" | ||
# Download release binary | ||
if [[ ! -x "${binPath}" ]]; then | ||
if [ "$(which curl)" = "" ]; then | ||
echo "curl must be installed to use this gh extension on this platform" | ||
exit 1 | ||
fi | ||
curl -sL -o "${binPath}" "https://github.com/k1LoW/gh-setup/releases/download/${ver}/${exe}" | ||
fi | ||
fi | ||
chmod +x "${binPath}" | ||
|
||
exec "${extensionPath}/bin/${exe}" "$@" | ||
exec "${binPath}" "$@" |