Skip to content

Instantly share code, notes, and snippets.

@vladinator1000
Last active August 24, 2021 23:41
Show Gist options
  • Save vladinator1000/5e4b80a6be3da767f8f892e326c9c65c to your computer and use it in GitHub Desktop.
Save vladinator1000/5e4b80a6be3da767f8f892e326c9c65c to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [[ -z $GITHUB_API_TOKEN ]]; then
echo "The \"\$GITHUB_API_TOKEN\" environment variable is undefined. Please generate a new token from https://github.com/settings/tokens, copy the token, paste it here and press enter:"
read GITHUB_API_TOKEN
fi
function installDependencies() {
echo "Updating Homebrew, this might take a while."
brew update
brew upgrade
echo "Installing dependencies..."
DEPENDENCIES=("jq" "openssl")
for DEPENDENCY in "${DEPENDENCIES[@]}"; do
if ! command -v ${DEPENDENCY} &>/dev/null; then
echo "\"${DEPENDENCY}\" is not installed, installing..."
brew install $DEPENDENCY
fi
done
}
installDependencies
function getAssetName() {
if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo "yup-ubuntu-latest"
elif [[ "$OSTYPE" == "darwin" ]]; then
echo "yup-macos-latest"
else
echo "Operating system "$OSTYPE" is not supported."
exit 1
fi
}
GITHUB_USER_NAME="yupty"
GITHUB_REPO_NAME="yup"
ASSET_NAME=$(getAssetName)
GITHUB_ASSET_URL=$(curl -s -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/${GITHUB_USER_NAME}/${GITHUB_REPO_NAME}/releases/latest | jq -r ".assets[] | select(.name == \"$ASSET_NAME\") | .url")
curl -H "Authorization: token ${GITHUB_API_TOKEN}" ${GITHUB_ASSET_URL} -LJOH 'Accept: application/octet-stream'
mv $ASSET_NAME yup
chmod u+x ./yup
MIME_ENCODING=$(file --mime-encoding yup)
if [[ $MIME_ENCODING == "yup: binary" ]]; then
echo "Installation successful. You can now run ./yup"
else
echo "Something went wrong. Please send any errors you see to engineering chat in Slack."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment