#!/usr/bin/env bash

#
# install-dependencies-bionic
#
# Copyright (C) 2009-20 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 != "bionic" ] ; then
    echo Error: This script is only for use on Ubuntu Bionic
    exit 1
fi

echo Installing RStudio dependencies for Ubuntu Bionic

sudo apt-get update

sudo apt-get -y install \
  ant \
  build-essential \
  clang \
  cmake \
  debsigs \
  dpkg-sig \
  expect \
  fakeroot \
  gnupg1 \
  libacl1-dev \
  libattr1-dev \
  libbz2-dev \
  libcap-dev \
  libclang-6.0-dev \
  libclang-dev \
  libcurl4-openssl-dev \
  libegl1-mesa \
  libfuse2 \
  libgl1-mesa-dev \
  libgtk-3-0 \
  libpam-dev \
  libpango1.0-dev \
  libssl-dev \
  libuser1-dev \
  libxslt1-dev \
  lsof \
  patchelf \
  pkg-config \
  python \
  rrdtool \
  software-properties-common \
  unzip \
  uuid-dev \
  wget \
  zlib1g-dev

# Java 8 (not in official repo for bionic)
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get -y install openjdk-8-jdk
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

# R
if ! [ -x "$(command -v R)" ]; then
  sudo apt-get -y  install apt-transport-https software-properties-common
  sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
  sudo add-apt-repository -y 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
  sudo apt update
  sudo apt-get -y install r-base
fi

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

# common
cd ../common
./install-common --install-crashpad-sudo
cd ../linux

