#!/usr/bin/env bash

#
# install-qt-sdk
#
# 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.
#
#

# This archive includes the files required to build against Qt 5.4.0. It
# was created by installing Qt 5.4.0 via an interactive installer, and 
# manually removing components not needed by RStudio.

# define QT archive to download
SYSTEM_ARCH=`getconf LONG_BIT`
if [ "$SYSTEM_ARCH" == "64" ]
then
  QT_ARCH=x86_64
else
  QT_ARCH=x86
fi

# presume 5.4.0
QT_VERSION=5.4.0

# test for libgstreamer
which apt-cache > /dev/null
if [ $? == 0 ]; then
  # debian (currently no test for CentOS based systems)
  apt-cache show libgstreamer1.0 > /dev/null
  if [ $? == 0 ]; then
    QT_VERSION=5.4.2
  fi
fi

QT_SDK_BINARY=QtSDK-${QT_VERSION}-${QT_ARCH}.tar.gz
QT_SDK_URL=https://s3.amazonaws.com/rstudio-buildtools/$QT_SDK_BINARY

# set Qt SDK dir if not already defined
if [ -z "$QT_SDK_DIR" ]; then
  QT_SDK_DIR=~/Qt${QT_VERSION}
fi

if ! test -e $QT_SDK_DIR
then
   # download and install
   wget $QT_SDK_URL -O /tmp/$QT_SDK_BINARY
   cd `dirname $QT_SDK_DIR`
   tar xzf /tmp/$QT_SDK_BINARY
   rm /tmp/$QT_SDK_BINARY
else
   echo "Qt $QT_VERSION SDK already installed"
fi
