#!/bin/bash

# Setup default options
default_opts()
{
    PASSWD_ARG=0
    SETUP=0
    DBG=0
}

usage()
{
    echo "Usage: " $(basename $0) " [-u] [-p <password>] [-s <vra_setup>]"
    echo "       -p    password"
    echo "       -s    vra_setup"
    exit 1
}

# Parse commandline options
parse_opts()
{
    default_opts

    while getopts "p:s:h" OPT
    do
        case ${OPT} in
	s)
            SETUP=1
            SETUP_NAME=$OPTARG
            ;;
        p)
            PASSWD_ARG=1
	    PASSWD=$OPTARG
            ;;
        h | \? | *)
	    usage
	    ;;
        esac
    done
}

# main
parse_opts "$@"

if [ ${SETUP} -eq 0 ]; then
    usage
fi

if [ ${PASSWD_ARG} -eq 0 ]; then
    usage
fi

curdir=$(pwd)

if [ ${DBG} -eq 1 ]; then
    echo "Passwd: " ${PASSWD}
    echo "Setup : " ${SETUP_NAME}
fi

echo "Copying APIC scripts 'rmapic', 'restart', 'get_logs.sh' to vra: ${SETUP_NAME}"
sshpass -p ${PASSWD} scp rmapic restart get_logs.sh root@${SETUP_NAME}:~/

# make the scripts executable
sshpass -p ${PASSWD} ssh root@${SETUP_NAME} "chmod a+x ~/rmapic ~/restart ~/get_logs.sh"
