#!/bin/bash

#
# install-qt-sdk
#
# Copyright (C) 2009-11 by RStudio, Inc.
#
# 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.
#
#

# define QT archive to download
SYSTEM_ARCH=`getconf LONG_BIT`
if [ "$SYSTEM_ARCH" == "64" ]
then
  QT_ARCH=x86_64
else
  QT_ARCH=x86
fi
QT_VERSION=2010.05
QT_SDK_BINARY=qt-sdk-linux-$QT_ARCH-opensource-$QT_VERSION.1.bin
QT_SDK_URL=https://s3.amazonaws.com/rstudio-buildtools/$QT_SDK_BINARY
QT_SDK_DIR=/opt/qtsdk-$QT_VERSION

if ! test -e $QT_SDK_DIR
then
   # download and install
   wget $QT_SDK_URL -O $QT_SDK_BINARY
   chmod +x $QT_SDK_BINARY
   sudo ./$QT_SDK_BINARY
   rm $QT_SDK_BINARY

   # link to qmake so cmake can find the install
   sudo ln -f $QT_SDK_DIR/qt/bin/qmake /usr/bin/qmake
else
   echo "Qt SDK already installed at $QT_SDK_DIR"
fi

