#!/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 >> /root/.ssh/config
fi

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

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


