#!/bin/bash
#

while true; do
	echo -n "Please enter your name: "
	read name

	echo -n "Please enter your e-mail address: "
	read email

	echo "If you continue, git will be downloaded and installed."
	echo "The git user name will be set to $name, using"
	echo "$email as the email address."
	echo ""
	echo -n "Do you wish to continue (y/n)"

	read confirm
	case $confirm in
		y|Y|YES|yes|Yes) break;;
		n|N|NO|no|No)
			echo "Aborting"
			exit
			;;
		*) echo "Please enter only y or n"
	esac
done
	
# Create a temporary source folder
mkdir -p ~/Downloads/Source
pushd ~/Downloads/Source

# Set some environment variables
export TCL_PATH=`which tclsh`
export NO_MSGFMT=1
export GIT_VERSION='1.5.6.4'

# Download and untar the source
curl -O "http://kernel.org/pub/software/scm/git/git-$GIT_VERSION.tar.bz2"
tar xjvf "git-$GIT_VERSION.tar.bz2"
cd "git-$GIT_VERSION/"

# Build git
./configure
make
sudo make install

# Install man pages
cd ..
curl -O "http://kernel.org/pub/software/scm/git/git-manpages-$GIT_VERSION.tar.bz2"
sudo tar xjv -C /usr/local/share/man        -f "git-manpages-$GIT_VERSION.tar.bz2"

# Use Mac's opendiff utility
git config --global merge.tool opendiff

# Ignore some file types
git config --global core.excludesfile ~/.gitignore
touch "$HOME/.gitignore"
echo '.DS_Store' >> "$HOME/.gitignore"
echo '._*' >> "$HOME/.gitignore"
echo '.svn' >> "$HOME/.gitignore"
echo '.hg' >> "$HOME/.gitignore"

# Create some shortcuts
git config --global alias.st status
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch

git config --global color.ui.auto

# Set some user details
git config --global user.name "$name"
git config --global user.email "$email"

# Restore working directory
popd
