Skip to content

Commit

Permalink
Fix extension setup script
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jul 11, 2023
1 parent cd3921a commit a2d0f87
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
bin/
coverage.out
ghsetup
68 changes: 42 additions & 26 deletions gh-setup
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}" "$@"

0 comments on commit a2d0f87

Please sign in to comment.