#!/bin/bash
# License Validator update script
# Author: [Your Name]
# Date: $(date +%Y-%m-%d)

set -e  # stop the script if any command fails

# === Ask for input variables ===
read -p "Enter SSH port: " ssh_port
read -p "Enter SSH username: " ssh_user
read -p "Enter SSH IP address: " ssh_ip
read -p "Enter remote folder path: " ssh_folder

echo "[INFO] Removing unpatched files..."
rm -f /usr/local/avenda/platform/lib/activation-client/license-validator.jar
rm -f /var/avenda/tomcat/frontend/webapps/tips/WEB-INF/lib/license-validator.jar

echo "[INFO] Copying patch from $ssh_ip..."
scp -P "$ssh_port" "$ssh_user@$ssh_ip:/$ssh_folder/license-validator.jar" \
    /var/avenda/tomcat/frontend/webapps/tips/WEB-INF/lib/license-validator.jar

scp -P "$ssh_port" "$ssh_user@$ssh_ip:/$ssh_folder/license-validator.jar" \
    /usr/local/avenda/platform/lib/activation-client/license-validator.jar

echo "[INFO] Setting permissions and ownership..."
chown 10100:10000 /var/avenda/tomcat/frontend/webapps/tips/WEB-INF/lib/license-validator.jar
chmod 644 /var/avenda/tomcat/frontend/webapps/tips/WEB-INF/lib/license-validator.jar

echo "[OK] Patch completed successfully."
