#!/bin/bash
# This file install Propo in Unix/Linux.
# Copyright (C) 2002  Gunner Poulsen gunner@gnuskole.dk

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


# The Script must be executet as root from the directory you put the files in.
# Use the command:
# su -c './install'

if [ ! -d /usr/local/ ] ; then
	mkdir /usr/local
	if [ ${LANG:0:2} = da ] ; then
		echo "Mappen /usr/local oprettet fordi den ikke fandtes."
	else
		echo "The directory /usr/local was created"
	fi
fi

if [ ! -d /usr/local/propo ] ; then
	mkdir /usr/local/propo
	if [ ${LANG:0:2} = da ] ; then
		echo "Mappen /usr/local/propo oprettet fordi den ikke fandtes."
	else
		echo "The directory /usr/local/propo was created"
	fi
fi
if [ -f /usr/local/propo/propo.highscores ] ; then
	midlertidig=`echo $RANDOM`
	mkdir /tmp/$midlertidig
	cp /usr/local/propo/propo.highscores /tmp/$midlertidig/

fi
if [ -d /usr/local/propo -a -f Propo.jar ] ; then
	cp -Rf . /usr/local/propo/
	chmod 755 /usr/local/propo/Propo.jar
	chmod 666 /usr/local/propo/propo.highscores
	if [ ${LANG:0:2} = da ] ; then
		echo "Filerne er kopieret til /usr/local/propo/."
	else
		echo "The files copyed to /usr/local/propo/."
	fi
else
	if [ ${LANG:0:2} = da ] ; then
		echo "Der er noget galt."
		echo "Str du i den mappe du pakkede filerne ud til?"
		echo "Har du root-rettigheder?"
	else
		echo "Somthing is wrong"
		echo "Are you standing in the right directory?"
		echo "Do you have root rights?"
	fi
fi
if [ -f /tmp/$midlertidig/propo.highscores ] ; then
	cp -f /tmp/$midlertidig/propo.highscores /usr/local/propo/propo.highscores
	chmod 666 /usr/local/propo/propo.highscores
	rm -Rf /tmp/$midlertidig
	unset midlertidig
fi
if [ ! -f /bin/propo ] ; then
	if [ -d /usr/local/bin ] ; then
		if [ ! -f /usr/bin/propo ] ; then
			if [ -f propo ] ; then
				cp propo /usr/local/bin/
				chmod 755 /usr/local/bin/propo
				if [ ${LANG:0:2} = da ] ; then
					echo "propo kopieret til /usr/local/bin/"
				else
					echo "propo copyed to /usr/local/bin/"
				fi
			fi
		else
			if [ -f /usr/bin/propo ] ; then
				if [ ${LANG:0:2} = da ] ; then
					echo "FEJL"
					echo "Der findes en fil med navnet /usr/bin/propo"
					echo "Den vil blive eksekveret i stedet for den fil du er i gang med at installere."
					echo "Undersg hvilket program der bruger den og slet den hvis den kan undvres."
					echo "Slet den med su -c 'rm /usr/bin/propo'"
					echo "Propo kan ikke kres nr denne fil ligger i /usr/bin/"
				else
					echo "ERROR"
					echo "The file /usr/bin/propo exists"
					echo "That file will be executed instead of the one you install now"
					echo "Check which program it belongs to and delete it if it isen't used."
					echo "Delete it with su -c 'rm /usr/bin/propo'"
					echo "Propo won't work if this file is in /usr/bin/"
				fi
			fi
		fi
	else
		if [ -f propo ] ; then
			cp propo /usr/bin/
			chmod 755 /usr/bin/propo
			if [ ${LANG:0:2} = da ] ; then
				echo "propo kopieret til /usr/bin/"
			else
				echo "propo copyed to /usr/bin/"
			fi
		fi

	fi
else
	if [ -f /bin/propo ] ; then
		if [ ${LANG:0:2} = da ] ; then
			echo "FEJL"
			echo "Der findes en fil med navnet /bin/propo"
			echo "Den vil blive eksekveret i stedet for den fil du er i gang med at installere."
			echo "Undersg hvilket program der bruger den og slet den hvis den kan undvres."
			echo "Slet den med su -c 'rm /bin/propo'"
			echo "Propo kan ikke kres nr denne fil ligger i /bin/"
		else
			echo "ERROR"
			echo "The file /bin/propo exists"
			echo "That file will be executed instead of the one you install now"
			echo "Check which program it belongs to and delete it if it isen't used."
			echo "Delete it with su -c 'rm /bin/propo'"
			echo "Propo won't work if this file is in /bin/"
		fi
	fi
fi
# For Red Hat 7.1 - 8.0
if [ -f /etc/redhat-release -a ! -f /etc/mandrake-release ] ; then
	udgave=`cat /etc/redhat-release`
	if [ -f /usr/local/propo/Propo.jar -a "${udgave:22:3}" = "8.0" -o "${udgave:22:3}" = "7.3" -o "${udgave:22:3}" = "7.2" -o "${udgave:22:3}" = "7.1" ] ; then
		if [ -d /usr/share/pixmaps -a ! -d /usr/share/pixmaps/propo ] ; then
		mkdir /usr/share/pixmaps/propo
		fi
		if [ -d /usr/share/pixmaps/propo -a -f icon_64x64.png ] ; then
			cp icon*png /usr/share/pixmaps/propo/
			chmod 644 /usr/share/pixmaps/propo/icon*png
			if [ ${LANG:0:2} = da ] ; then
				echo "ikonerne kopieret til /usr/share/pixmaps/propo"
				echo
			else
				echo "icons copyed to /usr/share/pixmaps/propo"
				echo
			fi
		fi

		if [ -d /usr/share/applnk/ -a ! -d /usr/share/applnk/Applications ] ; then
			mkdir /usr/share/applnk/Applications
			chmod 755 /usr/share/applnk/Applications
			
			if [ ${LANG:0:2} = da ] ; then
				echo "/usr/share/applnk/Applications oprettet."
				echo
			else
				echo "/usr/share/applnk/Applications created."
				echo
			fi
		fi
		if [ -d /usr/share/applnk/Applications -a -f propo.desktop ] ; then
			cp propo.desktop /usr/share/applnk/Applications/
			chmod 644 /usr/share/applnk/Applications/propo.desktop
						
			if [ ${LANG:0:2} = da ] ; then
				echo "Menuindgangen propo.desktop kopieret til /usr/share/applnk/Applications/"
				echo
			else
				echo "Menuitem propo.desktop copyed to /usr/share/applnk/Applications/"
				echo
			fi
		fi
	else
		if [ ${LANG:0:2} = da ] ; then
			echo "Du bruger en ldre udgave af Red Hat end 7.1 eller du har ndret i filen /etc/redhat-release"
			echo "Du bliver ndt til at lave installationen i hnden"
		else
			echo "You are using Red Hat previus to 7.1 or you have changed the file /etc/redhat-release"
			echo "So you have to make the installation by hand"
		fi
	fi
	unset udgave
fi

# For Mandrake 8 og 9
if [ -f /etc/mandrake-release ] ; then
	udgave=`cat /etc/mandrake-release`
	if [ -f /usr/local/propo/Propo.jar -a "${udgave:23:1}" = "9" -o "${udgave:23:1}" = "8" ] ; then
		if [ -d /usr/share/pixmaps -a ! -d /usr/share/pixmaps/propo ] ; then
		mkdir /usr/share/pixmaps/propo
		fi
		if [ -d /usr/share/pixmaps/propo -a -f icon_64x64.png ] ; then
			cp icon*png /usr/share/pixmaps/propo
			chmod 644 /usr/share/pixmaps/propo/icon*png
			echo "icons copyed to /usr/share/pixmaps/propo"
			echo
		fi

		if [ -d /usr/share/applnk/ -a ! -d /usr/share/applnk/Applications ] ; then
			mkdir /usr/share/applnk/Applications
			chmod 755 /usr/share/applnk/Applications
			echo "made /usr/share/applnk/Applications ."
			echo
		fi
		if [ -d /usr/share/applnk/Applications -a -f propo.desktop ] ; then
			cp propo.desktop /usr/share/applnk/Applications/
			chmod 644 /usr/share/applnk/Applications/propo.desktop
			echo "Menuindgangen propo.desktop kopieret til /usr/share/applnk/Applications/"
			echo
			if [ -f /usr/share/applnk/Applications/propo.desktop -a -d /usr/share/applnk-mdk/Applications/ ] ; then
				ln -sf /usr/share/applnk/Applications/propo.desktop /usr/share/applnk-mdk/Applications/propo.desktop
				echo "Lavede et symbolsk link i /usr/share/applnk-mdk/Applications/"
				echo
			fi
		fi
	else
		if [ ${LANG:0:2} = da ] ; then
			echo "Du bruger en ldre udgave af Mandrake end 8.x eller du har ndret i filen /etc/mandrake-release"
			echo "Du bliver ndt til at lave installationen i hnden"
		else
			echo "You are using Mandrake previus to 8.x or you have changed the file /etc/mandrake-release"
			echo "So you have to make the installation by hand"
		fi
	fi
	unset udgave
fi
if [ ! -f /etc/redhat-release -a ! -f /etc/mandrake-release ] ; then
	if [ ${LANG:0:2} = da ] ; then
		echo "Du bruger hverken Red Hat eller Mandrake."
		echo "derfor er der ikke oprettet en genvej i menuen"
		echo "Du kan starte Propo ved at skrive propo i en terminal."
	else
		echo "You are not using Red Hat or Mandrake."
		echo "so there was not created a shortcut in the menu."
		echo "You can start Propo by typing propo in a terminal."
	fi
fi
