#!/usr/bin/env bash

#
# install-sentry-cli
#
# Copyright (C) 2022 by Posit Software, PBC
#
# Unless you have received this program directly from Posit Software pursuant
# to the terms of a commercial license agreement with Posit Software, then
# this program is licensed to you under the terms of version 3 of the
# GNU Affero General Public License. This program is distributed WITHOUT
# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
#
#

set -e

source "$(dirname "${BASH_SOURCE[0]}")/../tools/rstudio-tools.sh"
section "Installing Sentry CLI"

# set INSTALL_DIR if /usr/local/bin is not writable
if ! [ -w /usr/local/bin ]; then
	INSTALL_DIR="${HOME}/opt/bin"
	mkdir -p "${INSTALL_DIR}"
	export INSTALL_DIR
fi

# specify a version
export SENTRY_CLI_VERSION=2.9.0

curl -sL https://sentry.io/get-cli/ | bash || true
SENTRY_PATH="sentry-cli"
if [[ -n "${INSTALL_DIR}" ]]; then
	SENTRY_PATH="${INSTALL_DIR}/${SENTRY_PATH}"
fi

info "Installed Sentry CLI version: `${SENTRY_PATH} --version`"
