sudo rm -f ant-telematics.deb
sudo rm -f microsoft.asc
sudo rm -f microsoft.asc.gpg
sudo rm -f packages-microsoft-prod.deb

echo
echo
echo ============================= Version os detect
if [ -f /etc/lsb-release ]; then
    # For some versions of Debian/Ubuntu without lsb_release command
    . /etc/lsb-release
    OS=$DISTRIB_ID
    VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
    # Older Debian/Ubuntu/etc.
    OS=Debian
    VER=$(cat /etc/debian_version)
else
    # Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
    OS=$(uname -s)
    VER=$(uname -r)
fi

echo
echo ============================= Version is $OS - $VER
echo

#delete lock file for apt
sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a
 
if [ $OS == "Ubuntu" ] && [ $VER == "18.04" ]; then
echo ============================= Install .Net Core for Ubuntu 18.04
sudo wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo add-apt-repository universe

sudo apt-get -y install apt-transport-https
sudo apt-get update
sudo apt-get -y install aspnetcore-runtime-2.2

elif [ $OS == "Ubuntu" ] && [ $VER == "16.04" ]; then
echo ============================= Install .Net Core for Ubuntu 16.04
sudo wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

sudo apt-get -y install apt-transport-https
sudo apt-get update
sudo apt-get -y install aspnetcore-runtime-2.2

elif [ $OS == "Ubuntu" ] && [ $VER == "14.04" ]; then
echo ============================= Install .Net Core for Ubuntu 14.04
sudo wget -q https://packages.microsoft.com/config/ubuntu/14.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

sudo apt-get -y install apt-transport-https
sudo apt-get update
sudo apt-get -y install aspnetcore-runtime-2.2

elif [ $OS == "Debian" ] && [[ $VER == 9.* ]]; then
echo ============================= Install .Net Core for Debian 9
sudo apt-get -y install apt-transport-https

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

sudo apt-get update
sudo apt-get -y install aspnetcore-runtime-2.2

else
echo ============================= Install .Net Core as for Ubuntu 18.04 - unknow version package
sudo wget -q 	https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo add-apt-repository universe

sudo apt-get -y install apt-transport-https
sudo apt-get update
sudo apt-get -y install aspnetcore-runtime-2.2
fi

sudo rm -f microsoft.asc
sudo rm -f microsoft.asc.gpg
sudo rm -f packages-microsoft-prod.deb



echo
echo ============================= Install PostgreSQL
#if (systemctl -q is-active postgresql.service)
#then
   while true; do
         read -p "Do you want to install PostgreSQL (y/n)? " yn
         case $yn in
              [Yy]* ) sudo apt-get -y install postgresql; sudo -u postgres bash -c "psql -c \"ALTER USER postgres WITH PASSWORD 'password';\"";echo Password changed to default!;break;;
              [Nn]* ) break;;
              * ) echo "Please answer y(yes) or n(no).";;
         esac
   done
#fi




echo
echo ============================= Install Ant Telematics
sudo wget https://www.iscv.ru/wp-content/uploads/files/ant-telematics.deb --no-check-certificate
sudo dpkg -i ant-telematics.deb
sudo rm -f ant-telematics.deb

echo
echo
echo --------------------------------------------------------------------------
echo --                                                  
echo -- For GUI OS: open browser on this PC and type: localhost
echo -- For Server OS: open browser on other PC and type IP address this PC
echo -- Use login: admin                                       
echo -- Password not present for user admin 
echo -- For controllers-devices use TCP port 7708        
echo --                                                  
echo --------------------------------------------------------------------------
echo
