#!/usr/bin/env bash
#
# install-dependencies-stretch
#
# Copyright (C) 2022 by RStudio, PBC
#
# Unless you have received this program directly from RStudio pursuant
# to the terms of a commercial license agreement with RStudio, 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

platform_codename=$(lsb_release -sc)
if [ $platform_codename != "stretch" ] ; then
    echo Error: This script is only for use on Debian Stretch
    exit 1
fi

echo Installing RStudio dependencies for Debian Stretch

sudo apt-get update

sudo apt-get -y install \
  ant \
  bzip2 \
  clang \
  clang-4.0 \
  cmake \
  curl \
  debsigs \
  dpkg-sig \
  expect \
  fakeroot \
  gcc \
  git \
  gnupg1 \
  libacl1-dev \
  libacl1-dev \
  libattr1-dev \
  libboost-all-dev \
  libcap-dev \
  libcap-dev \
  libcurl4-openssl-dev \
  libffi-dev \
  libglib2.0-dev \
  libpam0g-dev \
  libpango-1.0-0 \
  libpq-dev \
  libsqlite-dev \
  libssl1.0-dev \
  libuser1-dev \
  libxml-commons-external-java \
  lsof \
  make \
  mesa-common-dev \
  openjdk-8-jdk  \
  p7zip-full \
  patchelf \
  python \
  python3 \
  python3-venv \
  r-base \
  rrdtool \
  uuid-dev \
  wget \
  zlib1g

sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-4.0 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-4.0 100

# overlay
if [ -e install-overlay-common ]
then
  ./install-overlay-common
fi

# common
cd ../common
./install-common debian9
cd ../linux

# Python packages for i18n
if [ -x "$(command -v python3)" ]; then
  pushd ../../src/gwt/tools/i18n-helpers
  python3 -m venv VENV
  ./VENV/bin/pip install --disable-pip-version-check -r commands.cmd.xml/requirements.txt
  popd
fi 
