#!/bin/sh
printf "Checking for source   "
if [ -e sins.c ] &&
   [ -e menu.c ] &&
   [ -e speedcalib.c ] 
then
   printf "YES\n"
else
   printf " NO you have'n got source, or you are running this from bad directory.\n                          go to the sins source directory - aborting\n"
   exit 0
fi
printf "Checking for bitmaps "
if [ -e bmp/0.bmp ] &&
   [ -e bmp/1.bmp ] &&
   [ -e bmp/2.bmp ] &&
   [ -e bmp/3.bmp ] &&
   [ -e bmp/4.bmp ] &&
   [ -e bmp/5.bmp ] &&
   [ -e bmp/6.bmp ] &&
   [ -e bmp/7.bmp ] &&
   [ -e bmp/8.bmp ] &&
   [ -e bmp/9.bmp ] &&
   [ -e bmp/had.bmp ] &&
   [ -e bmp/pozadi.bmp ] &&
   [ -e bmp/abc.bmp ] &&
   [ -e bmp/co.bmp ] &&
   [ -e bmp/yes.bmp ] &&
   [ -e bmp/no.bmp ] &&
   [ -e bmp/about.bmp ] &&
   [ -e bmp/gameover.bmp ] &&
   [ -e bmp/menu.bmp ] &&
   [ -e bmp/options.bmp ] &&
   [ -e bmp/black.bmp ] &&
   [ -e bmp/default.skin ] &&
   [ -e bmp/left.bmp ]
then
   printf " YES\n"
else
   printf " NO\n You haven't got bitmaps - aborting\n"
   exit 0
fi
printf "Checking for SDL      "
if sdl-config --version
then
   : 
else
   printf " NO\n You have'n got SDL - aborting\n"
   exit 0
fi
printf "Checking for gcc      "
if gcc --version
then
   printf "\n NOW BUILDING \n"
   
else
   printf " NO \n You have'n got gcc - aborting\n"
   exit 0
fi

if gcc -o sins -O3 sins.c `sdl-config --libs`
then
	printf "SINS compiled OK\n"
else
	printf "Error while building\n"
	exit 0
fi
printf "Shell I install the game? "
read yesorno
case "$yesorno" in
	"yes" | "Yes" | "YES" |"y" | "Y" ) :;;
	"no" | "No" | "NO" | "n" | "N" ) printf "\n Good Bye\n"
	    exit 0;;
	* ) printf "\n Unrecognized answer - aborting\n"
	    exit 0;;
esac


	printf "\n INSTALLING \n"
	printf "Enter path to instal into or <Enter> for /usr/local/share? "
	read PathToInstall
	case "$PathToInstall" in
		"" ) printf "\nInstaling to /usr/local/share\n"
		PathToInstall="/usr/local/share";;
		* ) if [ -d $PathToInstall ] 
		      then
		              :
		      else
			      printf "\n Directory $PathToInstall does'n exist\n"
			      exit 0
		      fi;;
	esac
	mkdir $PathToInstall/sins/
	if [ -d $PathToInstall/sins/ ]
	then
	mkdir $PathToInstall/sins/default/
	cp bmp/* $PathToInstall/sins/default/
	cp -R skins/* $PathToInstall/sins/
	cp sins $PathToInstall/sins/
	else 
		printf "You can't write to $PathToInstall\n Try run this as root\n"
		exit 0
	fi

	printf "Enter path for binaries or pres <Enter> for /usr/local/bin? "
	read PathForBin
	case "$PathForBin" in
		"" ) printf "\nInstaling to /usr/local/bin\n"
		PathForBin="/usr/local/bin";;
		* ) if [ -d $PathForBin ] 
		      then
		              :
		      else
			      printf "\n Directory $PathForBin does'n exist\n"
			      exit 0
		      fi;;
	esac
	echo "#!/bin/sh" > $PathForBin/sins
        echo "cd $PathToInstall/sins/ ; ./sins" >> $PathForBin/sins
	chmod +x $PathForBin/sins

