#!/usr/bin/env bash

#
# install-dependencies-osx-jenkins
#
# 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"

# if we're called with no arguments, then re-invoke the script
# with the architecture(s) we're installing for
if [ "$#" = "0" ]; then

   if [ "$(arch)" = "arm64" ]; then
      # recursively invoke self with different architecture on arm64
      arch -arm64  "${BASH_SOURCE[0]}" "arm64"
      arch -x86_64 "${BASH_SOURCE[0]}" "x86_64"
   else
      # assume x86_64 otherwise and run as normal
      "${BASH_SOURCE[0]}" "x86_64"
   fi

   exit 0

fi

ARCH="$1"

# This script used to install homebrew into a location under $HOME, but we now have
# homebrew pre-installed in the standard locations (for x86 and arm) in the base AMI.
#
# Leaving this script in place in case we discover another use for it.
