#!/bin/sh

echo "Starting setup..."
echo "Extracting first archive"
mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-2.1.806-linux-arm.tar.gz -C $HOME/dotnet
echo "Extracting second archive"
mkdir -p $HOME/dotnet5_0 && tar zxf dotnet-sdk-5.0.103-linux-arm.tar.gz -C $HOME/dotnet5_0

echo "Copying the different versions into one folder"
cp -r $HOME/dotnet5_0/shared/Microsoft.AspNetCore.App/5.0.3 $HOME/dotnet/shared/Microsoft.AspNetCore.App
cp -r $HOME/dotnet5_0/shared/Microsoft.NETCore.App/5.0.3 $HOME/dotnet/shared/Microsoft.NETCore.App
cp -r $HOME/dotnet5_0/host/fxr/5.0.3 $HOME/dotnet/host/fxr/
cp -r $HOME/dotnet5_0/sdk/5.0.103 $HOME/dotnet/sdk/

echo "Removing temporaneous files"
rm -r $HOME/dotnet5_0

echo "Creating link to dotnet"
sudo rm /usr/local/bin/dotnet
sudo ln -s $HOME/dotnet/dotnet /usr/local/bin

echo "Creating HTTPS certificate"
dotnet dev-certs https

echo "Setup finished"
