#!/bin/bash
##
if [ $# -lt 1 ]
then
    echo "Usage: runSetupMySQL.sh <Pulbic IP>"
    exit 1
fi
PUBLIC_IP=$1
#
echo "************************************************"
echo "* Copy over needed files ...."
echo "************************************************"
scp -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key ./software/mysql* opc@${PUBLIC_IP}:/home/opc/.
scp -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key installMySQL.sh opc@${PUBLIC_IP}:/home/opc/.
scp -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key setupAlphaUser.sh opc@${PUBLIC_IP}:/home/opc/.
scp -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key *.sql opc@${PUBLIC_IP}:/home/opc/.
echo "************************************************"
echo "* Install MySQL ...."
echo "************************************************"
ssh -t -t -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key opc@${PUBLIC_IP} "sh /home/opc/installMySQL.sh"
#
echo "************************************************"
echo "* Setup Alpha User ...."
echo "************************************************"
ssh -t -t -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key opc@${PUBLIC_IP} "sh /home/opc/setupAlphaUser.sh"
#
echo "************************************************"
echo "* Open firewall for Port 3306 ...."
echo "************************************************"
ssh -t -t -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key opc@${PUBLIC_IP} "sudo firewall-cmd --permanent --add-port=3306/tcp"
ssh -t -t -o "ServerAliveInterval 60" -o "StrictHostKeyChecking no" -i ../Keys/oci_instance_key opc@${PUBLIC_IP} "sudo firewall-cmd --reload"
#
echo "**********************************************"
echo "* MySQL Setup is Complete ...."
echo "**********************************************"
