#!/bin/bash

############################################
### Check main installation requirements ###
############################################

set -e

BINARY="/usr/bin/dotnet"
DOTNET_TOP="/usr/lib/dotnet"
BINARY_IN_DOTNET_TOP="${DOTNET_TOP}/dotnet"

cd "$AUTOPKGTEST_TMP"


# Binary
echo "Checking binary is present in proper place and its usefulness"
test -e "${BINARY}"
test -e "${BINARY_IN_DOTNET_TOP}"
dotnet --info

echo "Checking dotnet version"
test "$(dotnet --version)" = "7.0.105"

echo "Checking path is found correctly"
#The path for the dotnet suite must to appear 5 times
num_path=$(dotnet --info | grep "${DOTNET_TOP}" -nc)
test "${num_path}" -eq "5"

# Config file
echo "Checking config file present"
test -e "/etc/dotnet/install_location"
test -e "/etc/profile.d/dotnet.sh"
echo "Checking environment"
dotnet_path=$(env | grep DOTNET_ROOT | cut -d'=' -f2)
test "${dotnet_path}" = "${DOTNET_TOP}"
