#!/bin/bash
#
if [ $# -ne 6 ]; then
   echo "$(tput bold)$(tput setaf 9)Incorrect use of the HgClone script. Please use it thusly: $(tput sgr 0)"
   echo "$(tput bold)hgclone $(tput setaf 10)archive_name $(tput setaf 11)archive_key $(tput setaf 12)archive_server $(tput setaf 13)server_port $(tput setaf 14)\"user name\" $(tput setaf 15)user@email_address$(tput sgr 0)"
   echo ""
else
   echo "$(tput bold)$(tput setaf 14)HgClone Custom Script v2$(tput sgr 0)"
   echo "$(tput bold)$(tput setaf 10)Running clone command$(tput sgr 0)"
   cmd="hg clone -v -e 'ssh -p $4 -i ~/.ssh/keys/$2' ssh://hg@$3/$1 $1"
   eval $cmd
   echo "$(tput bold)$(tput setaf 2)Modifying mercurial local configuration file$(tput sgr 0)"
   cmd="echo -e '\n[ui]\nssh = ssh -p $4 -i ~/.ssh/keys/$2\nusername = $5 <$6>' >> $1/.hg/hgrc"
   eval $cmd
   echo "$(tput bold)$(tput setaf 2)Done$(tput sgr 0)"
   echo ""
fi