#! /bin/bash

SCRIPTPATH=`dirname $(readlink -f $0)`
create_symlink() {
	SOURCEFILE=$1
	if [ "${SOURCEFILE:0:1}" != "/" ]; then
		SOURCEFILE=$SCRIPTPATH/$1
	fi
	if [ ! -e $2 ]; then
		ln -s $SOURCEFILE $2
	elif [ "$(readlink $2)" != "$SCRIPTPATH/$1" ]; then
		echo "Unable to link $1 config - $2 already existed" >&2
	fi
	#Else it already existed but was correct
}

add_content() {
	if [ -e $2 ]; then
		grep -F -q "$1" $2 2>&1
	else
		false
	fi
	if [ $? -ne 0 ]; then
		echo "$1" >> $2
	fi
}

create_symlink tmux.conf ~/.tmux.conf
create_symlink hgrc ~/.hgrc
create_symlink bashrc ~/.bashrc
create_symlink /usr/lib/python*/site-packages/hgext/hgview.py ~/.hgview.py
create_symlink gitconfig ~/.gitconfig
create_symlink dircolors ~/.dir_colors
create_symlink nanorc ~/.nanorc
create_symlink XCompose ~/.XCompose
mkdir -p ~/.ssh
add_content "ssh-rsa [payload removed: 372 characters] ssh@ibboard.co.uk" ~/.ssh/authorized_keys
