unameval="$(uname -s)"
case "${unameval}" in
    Linux*)     os=Linux;;
    Darwin*)    os=Mac;;
    CYGWIN*)    os=Cygwin;;
    MINGW*)     os=MinGw;;
    *)          os="UNKNOWN:${unameval}"
esac
echo "Setup for ${os}"



if [ -z "$IBMLONGHOST" ] ; then
    echo "Enter system name of your IBM i:"
    read IBMLONGHOST
    IBMIHOST="${IBMLONGHOST%%.*}"
    IBMIHOST="${IBMLONGHOST}"
fi

if [ -z "$IBMIUSER" ]; then
    echo "Enter your IBM i user profile on ${IBMIHOST}:"
    read IBMIUSER
fi

keyfile=~/.ssh/${IBMIHOST}
#configexists=$(cat ~/.ssh/config | grep ${IBMIHOST}$)
#
#if [  -z "${configexists}" ]; then
#    mkdir -pv ~/.ssh/controlmasters/
#    echo "Setting up host alias"
#    echo "host ${IBMIHOST}"  >> ~/.ssh/config
#    echo "    hostname ${IBMLONGHOST}" >> ~/.ssh/config
#    echo "    user ${IBMIUSER}" >> ~/.ssh/config
#    echo "    IdentityFile ${keyfile}" >> ~/.ssh/config
#    #echo "    ControlPath ~/.ssh/controlmasters/%r@%h:%p" >> ~/.ssh/config
#    #echo "    ControlMaster auto" >> ~/.ssh/config
#    #echo "    ControlPersist yes" >> ~/.ssh/config
#    echo " " >> ~/.ssh/config
#fi
#
#if [ ! -f "${keyfile}" ] ; then
#    echo "Running ssh key generator for ${IBMIHOST} : Press enter to all to get defaults"
#    ssh-keygen -f ${keyfile} -t rsa
#    chmod 600 ${keyfile}
ssh-copy-id -i ${keyfile} ${IBMIHOST}

echo "done!!"