#!/bin/bash

dotnet_version='net6.0'
salimax_ip="$1"
username='ie-entwicklung'
root_password='Salimax4x25'
set -e

echo -e "\n============================ Build ============================\n" 

dotnet publish  \
       ./SaliMax.csproj \
       -p:PublishTrimmed=false \
       -c Release \
       -r linux-x64 

echo -e "\n============================ Deploy ============================\n" 

rsync -v \
      --exclude '*.pdb' \
      ./bin/Release/$dotnet_version/linux-x64/publish/* \
       $username@"$salimax_ip":~/salimax

echo -e "\n============================ Execute ============================\n" 

sshpass -p "$root_password" ssh -o StrictHostKeyChecking=no -t "$username"@"$salimax_ip" "echo '$root_password' | sudo -S sh -c 'cd salimax && ./restart'" 2>/dev/null