#!/bin/sh

install () {

set -eu

UNAME=$(uname)
if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] ; then
  echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/prism/releases"
  exit 1
fi

if [ "$UNAME" = "Darwin" ] ; then
  PLATFORM="macos"
elif [ "$UNAME" = "Linux" ] ; then
  PLATFORM="linux"
fi

URL="https://github.com/stoplightio/prism/releases/latest/download/prism-cli-$PLATFORM"
SRC=$(pwd)/prism-$PLATFORM
DEST=/usr/local/bin/prism

STATUS=$(curl -sL -w %{http_code} -o $SRC $URL)
if [ $STATUS -ge 200 ] & [ $STATUS -le 308 ]; then
  mv $SRC $DEST
  chmod +x $DEST
  echo "Prism installation was successful"
else
  rm $SRC
  echo "Error requesting. Download binary from ${URL}"
  exit 1
fi
}

install
