#!/bin/bash

# Prompt for the host tag
read -p "Please enter the host tag (e.g., DBMP-AX05-18): " HOST_TAG

# Step 1: Download the script
echo "Logging in and downloading the deployment script..."
wget https://download.cloudclusters.io/deploy_vps_agent.sh

# Step 2: Change script permissions
echo "Changing script permissions..."
chmod +x deploy_vps_agent.sh

# Step 3: Execute the script with the provided host tag
echo "Executing the deployment script..."
./deploy_vps_agent.sh "$HOST_TAG"

# Step 4: Disable UFW
echo "Disabling UFW..."
ufw disable

# Step 5: Add certificate
echo "Adding certificate..."
certbot --nginx -d "${HOST_TAG}.cloudclusters.io"
echo "Please provide your email for Let's Encrypt notifications."
echo "Email: support@cloudclusters.io"

# Step 6: Enable UFW and add rules
echo "Enabling UFW and adding rules..."
ufw enable
ufw allow from 173.208.142.9   # Panel IP
#ufw allow from 69.30.237.33     # CCS Panel IP
#ufw allow from 108.181.202.146   # HWY Panel IP
#ufw allow from 173.208.142.9    # DBM Panel IP

# Step 7: Confirm UFW status
echo "Confirming UFW status..."
ufw status

# Step 8: Restart Nginx
echo "Restarting Nginx..."
systemctl restart nginx.service

wget https://download.cloudclusters.io/ipmi-install-exporter.sh
bash ipmi-install-exporter.sh

echo "All operations completed!"
