#!/bin/sh
# Copyright (c) 1994 by Adobe Systems Incorporated.
#
# Shell script for integrating Acrobat Reader with Indigo Magic desktop.
#
###################################################################

# Make sure Berkeley stuff is on user's path so hostname can be found.
PATH=$PATH:/usr/ucb:/usr/bsd:/usr/bin/X11
WHOAMI=`/usr/bin/id | sed 's/^[^(]*.\([^)]*\).*/\1/'`
MKDIR="/usr/bin/mkdir -p"
RM="/usr/bin/rm -f"
CP="/usr/bin/cp"

# Abort installation if user not superuser
if [ "$WHOAMI" != root ] ; then
   echo ""
   echo "You must be logged in as root to install"
   echo 'Type "su root" and enter the password to become root.'
   exit 1
fi

# Try to determine the parent directory to this launch script.
thisscriptname=$0

# Follow any symbolic links in thisscriptname.
while : ; do
	lsresult=`ls -l $thisscriptname`
	symlink=`expr "$lsresult" : '.*>'.*`

	if [ "$symlink" -gt 0 ] ; then
		oldscriptname="$thisscriptname"
		thisscriptname=`echo $lsresult|sed -e 's/^.*-> *\(.*\) *$/\1/g'`
		abspath_new=`expr "$thisscriptname" : '^/'`
		if [ $abspath_new != 1 ] ; then
			abspath_old=`expr "$oldscriptname" : '^/'`
			if [ $abspath_old != 1 ] ; then
				olddir=`pwd`
			else
				olddir=`expr "$oldscriptname" : '\(.*\)/'`
			fi
			thisscriptname="$olddir/$thisscriptname"
		fi
	else
		break
	fi
done

# Determine directory containing this shell script.
scriptdir=`expr $thisscriptname : '\(.*\)/'` 
if [ "$scriptdir" = "" -o "$scriptdir" = "." ] ; then
	scriptdir=`pwd`
fi

# Determine root directory for installation ($scriptdir/..).
parentdir=`expr $scriptdir : '\(.*\)/'` 
if [ "$parentdir" = "" ] ; then
	tempdir=`pwd`
	parentdir=`expr $tempdir : '\(.*\)/'`
fi

if [ ! -x "$parentdir/bin/acroread" ] ; then
	xconfirm -t "Unable to find desktop directory" -B OK
	exit 1
fi

# Integrate into Indigo Magic Desktop
echo ""
echo "Installing icon files and file type rules."
if [ ! -d /usr/lib/filetype/install/iconlib ] ; then
   ${MKDIR}  /usr/lib/filetype/install/iconlib
fi
${RM} /usr/lib/filetype/install/acroread.ftr
${RM} /usr/lib/filetype/install/acroread.*.fti
${CP} $scriptdir/acroread.ftr /usr/lib/filetype/install
${CP} $scriptdir/acroread.*.fti /usr/lib/filetype/install/iconlib

(cd /usr/lib/filetype; make)

echo ""
echo "Integrating Acrobat Reader into the Applications catalog."
iconbookedit -add "Category:File Name:$parentdir/bin/acroread" -syspage Applications

exit 0
