#!/bin/sh

#set default options
CHECK="--check"
PYTHON="--python"

USR_BIN_FILES="backintime-gnome"

#get commandline arguments
for arg in $*; do
	case $arg in
		--check | --no-check) CHECK=$arg;;
		--python | --python2) PYTHON=$arg;;
	esac
done

#patch python command
#use 'python' or 'python2' to start Python Version 2.x
case $PYTHON in
	--python)   sed -e "s/^python2\? /python /g" \
			-e "s/^ssh-agent python2\? /ssh-agent python /g" \
			-i $USR_BIN_FILES
			;;
	--python2)  sed -e "s/^python2\? /python2 /g" \
			-e "s/^ssh-agent python2\? /ssh-agent python2 /g" \
			-i $USR_BIN_FILES
			;;
esac

if [ -e Makefile ]; then
	rm Makefile;
fi

#check GNOME
if [ $CHECK = "--check" ]; then
	if [ -z `which gnome-session` ]; then
		printf "ERROR: Can't find GNOME !\n"
		exit 1
	fi
fi

cp Makefile.template Makefile

printf "All OK. Now run:\n"
printf "    make\n"
printf "    sudo make install\n"

