#!/bin/bash
#
# make sure we keep a copy of stdout and stderr
exec > >(tee /tmp/logfile.txt)
exec 2>&1

# tell the user what we are doing and execute the steps
echo "first install the missing packages"
echo "this will prompt you for your admin password"
echo "in order to install them to your system"
su -c "apt-get install -y autoconf automake cmake libtool gcc-c++ git \
lib64zip-devel lib64qt5webkitwidgets-devel qttools5 \
qttranslations5 lib64qt5xml-devel lib64qt5test-devel lib64qtscript-devel \
lib64qt5svg-devel lib64qt5concurrent-devel"

if [ ! -d ~/src ] ; then
	echo "create the ~/src directory which didn't exist"
	mkdir -p ~/src
fi

cd ~/src

echo "downloading the Subsurface sources"
git clone -b v4.4.1 git://subsurface-divelog.org/subsurface

echo "executing the build script which downloads more source"
echo "builds all the components and finally Subsurface"
echo "this could take a while"
./subsurface/scripts/build.sh

echo "now you can run Subsurface using"
echo "~/src/subsurface/subsurface"
