Innovenergy_trunk/csharp/App/SaliMax/deploy.sh

61 lines
2.2 KiB
Bash
Raw Normal View History

2023-07-13 07:42:50 +00:00
#!/bin/bash
dotnet_version='net6.0'
salimax_ip="$1"
2023-07-13 07:42:50 +00:00
username='ie-entwicklung'
2024-03-20 13:53:36 +00:00
root_password='Salimax4x25'
2023-07-13 07:42:50 +00:00
set -e
# Define directories
DEST_DIR="/home/$username/salimax/SaliMax" # Path to the specific file
BACKUP_DIR="/home/$username/salimax/salimax_backup/$(date +'%Y%m%d_%H%M%S')" # Backup folder with timestamp
MAX_BACKUPS=10 # Limit to 10 backups
2023-07-13 07:42:50 +00:00
echo -e "\n============================ Build ============================\n"
# Build the project
2023-07-13 07:42:50 +00:00
dotnet publish \
./SaliMax.csproj \
-p:PublishTrimmed=false \
-c Release \
-r linux-x64
echo -e "\n============================ Backup Old SaliMax File ============================\n"
# SSH into the remote machine and create the backup directory
ssh $username@$salimax_ip "mkdir -p $BACKUP_DIR"
# Move the 'SaliMax' file to the backup folder on the remote machine
ssh $username@$salimax_ip "rsync -av --exclude='$BACKUP_DIR/*' --exclude='salimax_backup/*' $DEST_DIR $BACKUP_DIR/"
echo -e "\n============================ Cleanup Old Backups ============================\n"
# Cleanup old backups if the total number exceeds the maximum allowed
# List all backups and remove the oldest if the number exceeds MAX_BACKUPS
BACKUP_COUNT=$(ssh $username@$salimax_ip "ls -1 /home/$username/salimax/salimax_backup | wc -l")
if [ $BACKUP_COUNT -gt $MAX_BACKUPS ]; then
# Find and delete the oldest backup
OLD_BACKUP=$(ssh $username@$salimax_ip "ls -1 /home/$username/salimax/salimax_backup | head -n 1")
echo "Backup limit reached. Deleting old backup: $OLD_BACKUP"
ssh $username@$salimax_ip "rm -rf /home/$username//salimax/salimax_backup/$OLD_BACKUP"
else
echo "Backup limit not reached. Current number of backups: $BACKUP_COUNT"
fi
2023-07-13 07:42:50 +00:00
echo -e "\n============================ Deploy ============================\n"
# Deploy new files to the remote destination
2023-07-13 07:42:50 +00:00
rsync -v \
2023-08-23 14:11:50 +00:00
--exclude '*.pdb' \
2023-07-13 07:42:50 +00:00
./bin/Release/$dotnet_version/linux-x64/publish/* \
$username@"$salimax_ip":~/salimax
echo -e "\nDeployment complete!\n"
2024-03-20 13:53:36 +00:00
#echo -e "\n============================ Execute ============================\n"
2024-03-20 13:53:36 +00:00
#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