#!/bin/bash

# This file is part of libbot2.
#
# libbot2 is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# libbot2 is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with libbot2. If not, see <https://www.gnu.org/licenses/>.

set -euo pipefail

if [[ "${EUID}" -ne 0 ]]; then
  echo 'This script must be run as root' >&2
  exit 1
fi

export DEBIAN_FRONTEND=noninteractive

apt-get -qq update || (sleep 15; apt-get -qq update)
apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends install \
  lsb-release

if [[ "$(lsb_release -cs)" != 'bionic' ]]; then
  echo 'This script requires Ubuntu 18.04 (Bionic)' >&2
  exit 2
fi

apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends install \
  build-essential \
  ca-certificates \
  default-jdk \
  doxygen \
  file \
  freeglut3-dev \
  git \
  gnupg \
  libglib2.0-dev \
  libgtk-3-dev \
  libjpeg8-dev \
  libpng-dev \
  libxmu-dev \
  pkg-config \
  python3-dev \
  python3-gi \
  python3-numpy \
  python3-scipy \
  wget \
  zlib1g-dev

wget -qO- https://apt.kitware.com/keys/kitware-archive-latest.asc \
  | gpg --dearmor > /etc/apt/trusted.gpg.d/kitware.gpg

echo 'deb https://apt.kitware.com/ubuntu/ bionic main' \
  > /etc/apt/sources.list.d/kitware.list

apt-get -qq update || (sleep 15; apt-get -qq update)
apt-get -o Acquire::Retries=4 -o Dpkg::Use-Pty=0 -qy --no-install-recommends install \
  cmake

# TODO: Install a compatible version of LCM.
