#!/bin/sh ARCH=$(uname) check_curl(){ which curl &> /dev/null if [[ $? -ne 0 ]] ; then echo '"curl" binary not found, please install and retry' exit 1 fi } check_os() { if [ "$ARCH" = "Linux" ] ; then TARGET="linux-amd64" elif [ "$ARCH" = "Darwin" ] ; then TARGET="darwin-amd64" else echo "Unknown operating system." exit 1 fi } generate_url(){ RELASE_URL="https://api.codenotary.io/foundation/v1/version/vcn/latest" curl --connect-timeout 100 -L $RELASE_URL >> release.json VERSION=$(grep -o '"release": *"[^"]*"' release.json | grep -o '"[^"]*"$' | tr -d '"') URL="https://github.com/codenotary/vcn/releases/download/$VERSION/vcn-$VERSION-$TARGET" echo "$URL - $VERSION" } install() { curl --connect-timeout 100 -L $URL >> vcn sudo cp $TMPDIR/vcn /usr/local/bin && sudo chmod +x /usr/local/bin/vcn } cleanup() { rm $TMPDIR/* rmdir $TMPDIR } do_install() { TMPDIR=$(mktemp -d) && cd $TMPDIR check_curl check_os echo ""; echo "CodeNotary vcn CLI - Install" echo "----------------------------" echo "- Checking for latest release.." generate_url echo "- Downloading and installing vcn $VERSION for you..." install cleanup echo ""; echo "🎉 Done." echo "You can run now: $ vcn" } # wrapped up in a function so that we have some protection against only getting # half the file during "curl | sh" do_install