#!/bin/bash

#
# install-dependencies-debian
#
# Copyright (C) 2009-17 by RStudio, Inc.
#
# 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

# build/development tools
sudo apt-get -y install build-essential
sudo apt-get -y install pkg-config
sudo apt-get -y install fakeroot
sudo apt-get -y install cmake

# core system libraries
sudo apt-get -y install uuid-dev

# for libssl, we want to make sure we get 1.0.2
# version 1.1.0+ is not compatible with our source code
which apt-cache > /dev/null
if [ $? == 0 ]; then
  apt-cache show libssl1.0-dev > /dev/null
  if [ $? == 0 ]; then
    sudo apt-get -y install libssl1.0-dev
  else
    sudo apt-get -y install libssl-dev
  fi
else
   sudo apt-get -y install libssl-dev
fi

sudo apt-get -y install libbz2-dev
sudo apt-get -y install zlib1g-dev
sudo apt-get -y install libpam-dev

# needed for QtWebKit >= 5
sudo apt-get -y install libxslt1-dev

# app armor dependencies no longer included in ubuntu >= 11.10
sudo apt-get -y install libapparmor1 
sudo apt-get -y install apparmor-utils

# boost
## This version of libboost-all-dev is now 1.55.0.2 in the current stable version of debian (jessie) [2015-12-04].
## This is further along than the version installed by the install-boost script also run by install-dependencies-debian.
## So comment this out to ensure only one version of boost is installed here and it is supported by rstudio.
#sudo apt-get -y install libboost-all-dev

# pango cairo
sudo apt-get -y install libpango1.0-dev

# gwt prereqs
## openjdk-6-jdk is no longer available in the current stable version of debian [2015-12-04]
## Also, ant no longer depends on openjdk-6-jdk
# sudo apt-get -y install openjdk-6-jdk 
sudo apt-get -y install ant

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

# common
sudo apt-get -y install unzip
cd ../common
./install-common
cd ../linux

# desktop dependencies (qt)
if [ "$1" != "--exclude-qt-sdk" ]
then
   # ubuntu server doesn't include gstreamer by default so ensure that these
   # libs are always available for desktop builds (required by QtWebKit 2.2)
   sudo apt-get -y install libgstreamer0.10-0
   sudo apt-get -y install libgstreamer-plugins-base0.10-0

   # Ubuntu 12.04 doesn't include libjpeg62 (and it's required by Qt 4.8)
   sudo apt-get -y install libjpeg62

   # Need the OpenGL development libraries to build QtGui
   sudo apt-get -y install libgl1-mesa-dev

   # install Qt 4.8 SDK (into a private /opt/RStudio-QtSDK directory so as to 
   # not conflict with any other installed versions of Qt on the system)
   ./install-qt-sdk
fi






