#!/bin/bash

# VARIABLES
#
VAR_OS=`uname`
VAR_PATH="will_be_defined_later_in_script"
VAR_NODE_TYPE="basic"
VAR_FILE_HEADER="# ABBEOO MODIFIED AT `date '+ %Y-%m-%d %H:%M:%S'`\n#"


mountrw;


rm -f /etc/abbeoo/abo.global.parameters.sh;
cd /etc/abbeoo/;
wget http://soul.abbeoo.net/pub/install/linux/debian/stretch/abo.global.parameters.sh;
source /etc/abbeoo/abo.global.parameters.sh;


# UPDATE SYSTEM PRE TASKS
DEBIAN_FRONTEND=noninteractive aptitude -y update
DEBIAN_FRONTEND=noninteractive aptitude -y upgrade


# UPDATE SYSTEM POST TASKS
VAR_PATH="/etc/abbeoo/abo.system.update.log"
rm -r           $VAR_PATH
touch           $VAR_PATH
echo -e         $VAR_FILE_HEADER>>$VAR_PATH


abo_system.aptitude "expect" "dotnet-sdk-2.1.200 dotnet-runtime-2.0.7 aspnetcore-runtime-2.1 dotnet-host dotnet-hostfxr-2.1 dotnet-runtime-2.1 dotnet-runtime-deps-2.1 aspnetcore-runtime-2.2 dotnet-hostfxr-2.2 dotnet-runtime-2.2 dotnet-runtime-deps-2.2";
rm -f /etc/apt/sources.list.d/microsoft-prod.list;
rm -f /etc/apt/trusted.gpg.d/microsoft.asc.gpg;

# CLEAR ALL EXISTING LOG FILES
#cd /var/log
#for i in *
#  do test -f $i -a -s $i && > $i
#done

aptitude purge -y dotnet-host dotnet-hostfxr-3.0 dotnet-runtime-3.0 dotnet-runtime-deps-3.0 dotnet-hostfxr-2.1 dotnet-runtime-2.1 dotnet-runtime-deps-2.1 aspnetcore-runtime-2.2 dotnet-hostfxr-2.2 dotnet-runtime-2.2 dotnet-runtime-deps-2.2

DEBIAN_FRONTEND=noninteractive aptitude -y clean
DEBIAN_FRONTEND=noninteractive apt-get -y clean

wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget -q https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list

aptitude update -y
aptitude install -y apt-transport-https
aptitude update -y
aptitude install -y aspnetcore-runtime-3.1 dotnet-runtime-3.1 dotnet-sdk-3.1


# CLEAR APTITUDE CACHE
DEBIAN_FRONTEND=noninteractive aptitude -y clean
DEBIAN_FRONTEND=noninteractive apt-get -y clean


fh-sync;


exit 0;
