#!/bin/bash

echo
echo "-----------------------------------------"
echo "-----FireMon AWS Backup Prep Utility-----"
echo "-----------------------------------------"
echo

# Get AWS Transfer Server
read -p "Enter AWS Destination (IP/FQDN): " destination

echo
echo "Creating remote-sftp.sh in /etc/firemon/postbackup.d ..."
echo

# Generates first half of post backup script with user input being assigned to the variables.
cat > remote-sftp.sh.example << EOF1
#!/bin/sh

# Variables here are assigned via user input
destination=$destination


EOF1

# Appends second half of post backup script with user input being escaped.
# The code block will be appended exactly as it appears below.
cat >> remote-sftp.sh.example << 'EOF2'

# Transfer backup to destination server

echo
echo "***Please wait.  The prompt will return when the transfer is complete.***"
echo
echo put ${BACKUP} | sftp -o StrictHostKeyChecking=no fmbackup@${destination}
echo

echo
echo "-------------------------"
echo "-----Backup Complete-----"
echo "-------------------------"
echo

EOF2


# Installs script to /etc/firemon/postbackup.d and removes remote-sftp.sh.example from ~/
install remote-sftp.sh.example /etc/firemon/postbackup.d/remote-sftp.sh
rm remote-sftp.sh.example

echo
echo "------------------------------------------------------"
echo "----- Create AWS Accounts and upload public keys -----"
echo "------------------------------------------------------"
echo


echo
echo "Create user account called \"fmbackup\" on your AWS transfer server and add the following public key:"
echo
cat /etc/firemon/fmbackup.ssh-pubkey
echo



