Created
October 31, 2021 06:32
-
-
Save maxdevjs/26d550e1edd8751243f028c99327b172 to your computer and use it in GitHub Desktop.
Possible cheap alternative to check if on non FHS compliant systems. Based on https://github.com/samcoe/gh-repo-explore
This file contains hidden or 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
#!/usr/bin/env bash | |
set -e | |
tag="v0.0.4" | |
repo="samcoe/gh-repo-explore" | |
extension_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | |
tag_path="${extension_path}/dist/${tag}" | |
exe="gh-repo-explore" | |
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" | |
elif [ "$arch" == "i686" ]; then | |
platform="windows_386" | |
elif [ "$arch" == "i386" ]; then | |
platform="windows_386" | |
fi | |
elif uname -a | grep Darwin > /dev/null; then | |
if [ "$arch" == "x86_64" ]; then | |
platform="darwin_amd64" | |
fi | |
elif uname -a | grep Linux > /dev/null; then | |
if [ "$arch" == "x86_64" ]; then | |
platform="linux_amd64" | |
elif [ "$arch" == "i686" ]; then | |
platform="linux_386" | |
elif [ "$arch" == "i386" ]; then | |
platform="linux_386" | |
fi | |
fi | |
} | |
download_latest_release() { | |
mkdir -p "${tag_path}" | |
gh release -R"${repo}" download "${tag}" --pattern "*${platform}*" --dir="${tag_path}" | |
mv "${tag_path}/${exe}_${tag}_${platform}${extension}" "${tag_path}/${exe}" | |
chmod +x "${tag_path}/${exe}" | |
} | |
build() { | |
mkdir -p "${tag_path}" | |
pushd "${extension_path}" > /dev/null | |
go build -o "${tag_path}/${exe}" | |
popd > /dev/null | |
} | |
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 | |
build | |
# elif [[ `uname -a` =~ 'NixOS' ]]; then | |
elif [[ `command -v /bin/bash` == "" ]]; then | |
build | |
else | |
if [ ! -d "${tag_path}" ]; then | |
download_latest_release | |
fi | |
fi | |
fi | |
exec "${tag_path}/${exe}" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment