#!/bin/bash

# ------------------------------------------------------------------------------------------
#
# Internet Radio Automation & Encoding Toolkit
# 
# kc.okane@gmail.com
# okane@cs.uni.edu
# https://www.cs.uni.edu/~okane
# http://threadsafebooks.com/
# 
# Copyright (C) 2019 by Kevin C. O'Kane
# 
# This program described herein is free software; you can redistribute it 
# and/or modify it under the terms of the GNU General Public License as 
# published by the Free Software Foundation; either version 2 of the 
# License, or (at your option) any later version.
# 
# This program 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 General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with 
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple 
# Place, Suite 330, Boston, MA  02111-1307  USA.
# 
# ------------------------------------------------------------------------------------------

# June 27, 2019

# This script is for Debian related systems that use the apt (formerlly, apt-get)
# package for system updates. It will not work on system that do not use apt.

# This script can be used to install most of the software needed for the different
# configurations found here. Much of this software may already be installed.
# If a package is already installed, this script will not change it.
# All packages are downloaded for your system's standard repositories.
# 
#
# to run:
#
#	sudo ./install.script
#
# This will take some time to run and you will see many messages scroll by.
# When it finishes, it will compile the code and run it.
#

        if [ `whoami` != "root" ]; then
                echo
                echo -------------------------------------------
                echo "**** you must be root to run this script"
                echo -------------------------------------------
                echo
                exit
                fi

        if [ -z `which apt-get` ]; then
                echo "apt-get not found"
                echo "apt-get is required"
                echo "The installation will only work on systems that use apt-get"
                echo "halting ........"
                echo
                fi

        echo
        echo "apt-get found"

# temporary PATH modification 

PATH=$PATH:$HOME/bin:.:/bin:/sbin:

apt-get update

apt-get --yes install ffmpeg

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install libgtk-3-dev

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install mpv

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install vlc

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install pulseaudio

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install gcc

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install g++

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install libpulse-dev

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

# we want gtkmm-2.4 as well

apt-get --yes install libgtkmm-2.4-dev

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install libgtkmm-3.0-dev

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install libgtk-3-0 

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install wmctrl

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install pulseaudio-utils

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install glade

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install pkg-config

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install x11-xserver-utils

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install fftw3-dev

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install autoconf

if [ $? -ne 0 ]; then
	echo "apt-get did not return 0 - probable error"
	exit
	fi

apt-get --yes install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc \
gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 \
gstreamer1.0-qt5 gstreamer1.0-pulseaudio

echo "********** done ***************"
echo
