#!/bin/bash 
if [[ -d /usr/local/afribin/.git ]] ; then
        echo "Afribin already converted to git"
        exit 0
fi

if [[ -z "${LAMENT_USERNAME}" ]]; then
        echo "Missing lament username"
        exit 1
fi

if [[ -z "${LAMENT_PASSWORD}" ]]; then
        echo "Missing lament password"
        exit 1
fi


if ! grep -q lament.ifarhost.co.za /root/.ssh/config ; then 
        curl -u ${LAMENT_USERNAME}:${LAMENT_PASSWORD} https://lament.ifarhost.co.za/Afrihost/afribin-ssh-key/raw/branch/master/config_c6 >> /root/.ssh/config
fi

if ! [ -f /root/.ssh/id_afribin_c6 ] ; then
        curl -s -o /root/.ssh/id_afribin_c6 -u ${LAMENT_USERNAME}:${LAMENT_PASSWORD} https://lament.ifarhost.co.za/Afrihost/afribin-ssh-key/raw/branch/master/id_afribin_c6
        chmod 600 /root/.ssh/id_afribin_c6
fi

mv /usr/local/afribin/ /usr/local/afribin.svn
git clone ssh://git@lament.ifarhost.co.za:4000/Afrihost/afribin.git /usr/local/afribin
