#!/bin/bash -e
# Reference:
#   https://github.com/musescore/MuseScore/blob/master/build/travis/job_macos/install.sh

QT_VERSION=${1:-5.12.0}

QT_MAJOR_VERSION=$(echo ${QT_VERSION} | cut -d "." -f 1)
QT_MINOR_VERSION=$(echo ${QT_VERSION} | cut -d "." -f 2)
if [ "$(uname)" = "Darwin" ]; then
  if { [ "${QT_MAJOR_VERSION}" -eq 5 ] && [ "${QT_MINOR_VERSION}" -ge 9 ]; } || [ "${QT_MAJOR_VERSION}" -ge 6 ]; then
    # this was good from 5.9.0 through at least 5.12.0
    DOWNLOAD_URL=https://download.qt.io/archive/qt/${QT_MAJOR_VERSION}.${QT_MINOR_VERSION}/${QT_VERSION}/qt-opensource-mac-x64-${QT_VERSION}.dmg
  else
    # this was good from 5.2.1 through 5.8.0
    DOWNLOAD_URL=https://download.qt.io/archive/qt/${QT_MAJOR_VERSION}.${QT_MINOR_VERSION}/${QT_VERSION}/qt-opensource-mac-x64-clang-${QT_VERSION}.dmg
  fi
elif [ "$(uname)" = "Linux" ]; then
  # this was good from 5.2.1 through at least 5.12.0
  DOWNLOAD_URL=https://download.qt.io/archive/qt/${QT_MAJOR_VERSION}.${QT_MINOR_VERSION}/${QT_VERSION}/qt-opensource-linux-x64-${QT_VERSION}.run
else
  echo "Unsupported system." >&2
  exit 1
fi
echo $DOWNLOAD_URL
