#!/bin/bash

# Verify Ubuntu version
ubuntu_version=$(lsb_release -rs | cut -d '.' -f 1)

if [[ ${ubuntu_version} -lt '20' || ${ubuntu_version} -gt '22' ]]
then 
	echo "Unsupported Ubuntu version. This script supports Ubuntu 20.04 or 22.04."
fi

# Download the GPG key, which then we'll add to download the packages of the Service Desk repository
wget https://download.invgate.net/servicedesk/packages/debian/php70/binary/keyFile

# Add the GPG key to the Service Desk repository
sudo apt-key add keyFile


echo "deb https://download.invgate.net/servicedesk/packages/debian/LTS/stable /" | sudo tee -a /etc/apt/sources.list


sudo apt-get update
sudo apt-get install -y unixodbc-dev unixodbc

#Add repositories with dependencies
curl -s https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
if [[ $ubuntu_version == "22" ]]; then
  sudo bash -c "curl -s https://packages.microsoft.com/config/ubuntu/22.04/prod.list > /etc/apt/sources.list.d/mssql-release.list"
else
  sudo bash -c "curl -s https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list"
fi
sudo add-apt-repository ppa:ondrej/php -y


sudo apt-get update
sudo apt-get install -y ca-certificates


sudo ACCEPT_EULA=Y apt-get -y install msodbcsql17 mssql-tools

#Install InvGate Service Desk
sudo apt-get install -y invgate-service-desk

# Modify PHP memory limit
sudo sed -i 's/memory_limit = 128M/memory_limit = 1024M/g' /etc/php/8.1/apache2/php.ini

sudo service apache2 restart
