#!/bin/sh
# Platform Detector for HomepageSearchEngine v3.42 (Updated on 2003 04 13) (c) 2003, ANET.at
# This shell script may be used on Unix to determine the platform
# Freeware. Written by Robert.Allerstorfer@anet.at
# Just upload it, chmod it to 755 and call its URL with your webbrowser, e.g. http://www.yourdomain.tld/cgi-bin/platform/platform.cgi

VER="3.42"
URL="http://www.homepagesearchengine.com/_download"
echo "Content-Type: text/html"
echo ""
echo "<html><head><title>Platform Detector</title></head><pre>"
echo "<a href=\"http://www.anet.at/\">ANET.at</a> Platform Detector for <a href=\"http://www.homepagesearchengine.com/\">HomepageSearchEngine</a> $VER"
echo ""

if [ "`uname -a`" = "" ]; then
	echo "Sorry, your platform could not be detected with this shell script."
	PERL=`which perl`
	if [ ! "$PERL" = "" -o -x /usr/bin/perl ]; then
		echo ""
		echo "Please use the Perl script <a href=\"./platform.pl\"><b>platform.pl</b></a> instead "
		if [ ! "$PERL" = "" ]; then
			echo "(Perl is available at '<b>$PERL</b>')"
			if [ ! "$PERL" = "/usr/bin/perl" ]; then
				echo "But, be sure to change its first line to point to Perl's location as printed above!"
			fi
		else
			echo "(Perl is available at '<b>/usr/bin/perl</b>')"
		fi
	fi
	exit 1
fi

OS=""
echo "Your platform is:"

if [ "`uname -s`" = "Linux" ]; then
	BIN=`which perl`
	if [ "$BIN" = "" ]; then
		BIN="/bin/ls"
	fi
	LIB=`ldd $BIN | grep libc.so.`
	if [ "`uname -m`" = "i586" ] || [ "`uname -m`" = "i686" ]; then
		OS="GNU/Linux"
		echo "<b>${OS}</b> (Version `uname -r`)"
		echo ""
		echo "Library Information: ($BIN)"
		echo "$LIB"
		echo ""
		echo "	`iconv --version | grep iconv`"
		echo ""
		echo "The HomepageSearchEngine package you need is <a href=\"${URL}/Linux/HSE-${VER}_Linux.tgz\">HSE-${VER}_Linux.tgz</a>"
		TMPFILE="/tmp/LIB_temp.txt"
		echo $LIB > $TMPFILE
		LIBC5=`sed -n -e '/libc\.so\.5/p' $TMPFILE`
		if [ -n "$LIBC5" ]; then
			echo "Additionally, you need <a href=\"${URL}/Linux/HSE-${VER}_Linux-old.tgz\">HSE-${VER}_Linux-old.tgz</a>"
		fi
		rm $TMPFILE
#	elif [ "`uname -m`" = "mips" ]; then
#		OS="GNU/Linux"
#		CPU="mips"
#		echo "<b>${OS}-${CPU}</b> (Version `uname -r`)"
#		echo ""
#		echo "Library Information:"
#		echo "$LIB"
#		echo ""
#		echo "The HomepageSearchEngine package you need is <a href=\"${URL}/Linux/HSE-${VER}_Linux-mips.tgz\">HSE-${VER}_Linux-mips.tgz</a>"
	fi
fi

if [ "`uname -s`" = "FreeBSD" ] && [ "`uname -m`" = "i386" ]; then
	OS="FreeBSD"
	OSVER=`uname -r`
	echo "<b>${OS}</b> (Version ${OSVER})"
	TMPFILE="/tmp/OSVER_temp.txt"
	echo $OSVER > $TMPFILE
	OSNR=`sed -n -e 's/\(^[0-9]\).*/\1/p' $TMPFILE`
	if [ $OSNR -gt "2" ]; then
		echo "The HomepageSearchEngine package you need is <a href=\"${URL}/FreeBSD/HSE-${VER}_FreeBSD.tgz\">HSE-${VER}_FreeBSD.tgz</a>"
		if [ $OSNR -gt "3" ]; then
			LIB=`ldconfig -r`
			ADDLIB=0
			echo ""
			echo "Library Information:"
			echo "$LIB" | grep search
			echo "$LIB" | grep libc.so.3
			if [ $? -gt "0" ]; then
				echo "	No libc.so.3 available."
				ADDLIB=1
			fi
			echo "$LIB" | grep libutil.so.2
			if [ $? -gt "0" ]; then
				echo "	No libutil.so.2 available."
				ADDLIB=1
			fi
			if [ $ADDLIB -gt "0" ]; then
				echo "Additionally, you may need <a href=\"${URL}/FreeBSD/libs-FreeBSD.tgz\">libs-FreeBSD.tgz</a>"
			fi
		fi
	else
		echo "Sorry, FreeBSD version ${OSNR}.x is not supported anymore. Please ask your ISP to upgrade to version 3 or higher."
	fi
	rm $TMPFILE
fi

#if [ "`uname -s`" = "OpenBSD" ] && [ "`uname -m`" = "i386" ]; then
#	OS="OpenBSD"
#	echo "<b>${OS}</b> (Version `uname -r`)"
#	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/OpenBSD/HSE-${VER}_OpenBSD.tgz\">HSE-${VER}_OpenBSD.tgz</a>"
#fi

#if [ "`uname -s`" = "NetBSD" ] && [ "`uname -m`" = "i386" ]; then
#	OS="NetBSD"
#	echo "<b>${OS}</b> (Version `uname -r`)"
#	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/NetBSD/HSE-${VER}_NetBSD.tgz\">HSE-${VER}_NetBSD.tgz</a>"
#fi

if [ "`uname -s`" = "BSD/OS" ] && [ "`uname -m`" = "i386" ]; then
	OS="WindRiver BSD/OS"
	echo "<b>${OS}</b> (Version `uname -r`)"
	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/BSD-OS/HSE-${VER}_BSD-OS.tgz\">HSE-${VER}_BSD-OS.tgz</a>"
fi

if [ "`uname -s`" = "AIX" ]; then
	OS="IBM AIX"
	echo "<b>${OS}</b> (Version `uname -v`.`uname -r`)"
	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/AIX/HSE-${VER}_AIX.tgz\">HSE-${VER}_AIX.tgz</a>"
fi

if [ "`uname -s`" = "OSF1" ]; then
	OS="HP Tru64 Unix"
	echo "<b>${OS}</b> (Version `uname -r`)"
	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/Tru64/HSE-${VER}_Tru64.tgz\">HSE-${VER}_Tru64.tgz</a>"
fi

if [ "`uname -s`" = "HP-UX" ]; then
	OS="HP HP-UX"
	echo "<b>${OS}</b> (Version `uname -r`)"
	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/HP-UX/HSE-${VER}_HP-UX.tgz\">HSE-${VER}_HP-UX.tgz</a>"
fi

if [ "`uname -s`" = "IRIX64" ]; then
	OS="SGI IRIX64"
	echo "<b>${OS}</b> (Version `uname -r`)"
	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/IRIX/HSE-${VER}_IRIX.tgz\">HSE-${VER}_IRIX.tgz</a>"
fi

if [ "`uname -s`" = "Darwin" ]; then
	OS="Apple MacOS X"
	echo "<b>${OS}</b> (Darwin Kernel Version `uname -r`)"
	echo "The HomepageSearchEngine package you need is <a href=\"${URL}/MacOSX/HSE-${VER}_MacOSX.tgz\">HSE-${VER}_MacOSX.tgz</a>"
fi

if [ "`uname -s`" = "SunOS" ]; then
	PLATFORM="`uname -m | cut -c-3`"
	if [ $PLATFORM = "sun" ]; then
		OS="Sun Solaris"
		echo "<b>${OS}</b> (SunOS Version `uname -r` / `uname -m`)"
		echo ""
		echo "	`iconv --version | grep iconv`"
		echo ""
		echo "The HomepageSearchEngine package you need is <a href=\"${URL}/Solaris/HSE-${VER}_Solaris.tgz\">HSE-${VER}_Solaris.tgz</a>"
	fi
fi

if [ -z "$OS" ]; then
	echo "<b>`uname -s` / `uname -m`</b> Release `uname -r`"
	echo "(Version `uname -v`)"
	echo ""
	echo "This platform is currently unsupported. Please contact us at <a href=\"mailto:info@anet.at\">info@anet.at</a>. Thank you."
	exit 1
fi

echo ""
echo ""
DIR=`pwd`
if [ -n "$DIR" ]; then
	echo "Once you have downloaded the package you may want to install it. At this stage, you will need to set a proper 'basepath' value."
	echo "If you want to set this absolutely instead of relatively for some reasons, this information might be useful:"
	echo "This directory's absolute path is <b>$DIR</b>"
fi

exit 0