#!/bin/sh
# Installation script for Ishmail, used with "tar" file packages
# Copyright (c) 1994,1995 HaL Computer Systems, Inc.
# All rights reserved

id | grep "^uid=0(" >/dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "
You don't have \"root\" privilege.

This installation program will try to change file ownerships and groups,
and create a symbolic link in /usr/bin. These may fail without root
privilege.

You will still be able to run the program, with some limitations. Instead of
just typing \"ishmail\" to start it, you'll have to type the full path name.
And, you may get a warning about being unable to lock your inbox file - 
which will prevent you from saving changes to it...

Contact your system administrator if you need help.

Continue installation? (y or n, default y)"
	read ans
	if [ "$ans" = "n" -o "$ans" = "N" ]; then
		exit
	fi
fi

# note: the following two lines are updated with the real VER and OS_TYPE
#       during the build process
VER=XXX
OS_TYPE=YYY

if [ "$OS_TYPE" = "sun" ]; then
	GROUP=staff
	SGID=0
else
	GROUP=mail
	SGID=1
fi
DIR=`pwd | sed -e "s|/tmp_mnt||"`

# remove tar file
rm -f $DIR/ishmail-$VER-$OS_TYPE.tar

# if SunOS, prompt for choice of Motif or OpenLook fonts

if [ "$OS_TYPE" = "sun" ]; then
	echo "
There are two versions of font resource files supplied with Ishmail, a
Motif version and an OpenWindows version. Both will be installed, and one
of them will be made the default.

You will be asked to select a default version now. If you change your mind
later, you can easily change the default by editing the \"Ishmail\" resource
files in the \"lib\" subdirectory of where the package is installed.

If you pick the wrong default you may see some warning messages when you
run Ishmail, and the fonts may not look very good, but no harm will be done.
"

	ISHFONTS=""
	while [ "$ISHFONTS" = "" ]; do
		echo "Do you want to use Motif or OpenWindows fonts? (m or o)"
		read ISHFONTS
		if [ "$ISHFONTS" = "m" -o "$ISHFONTS" = "M" ]; then
			ISHFONTS=motif
			continue
		fi
		if [ "$ISHFONTS" = "o" -o "$ISHFONTS" = "O" ]; then
			ISHFONTS=openwin
			continue
		fi
		ISHFONTS=""
	done
	TMP=/tmp/pkg$$
	ISHLIB="$DIR/$VER/lib"
	if [ "$ISHFONTS" = "motif" ]; then
		cp $ISHLIB/Ishmail $TMP
		sed -e '/fonts\.ow"$/ s/^#/!#/' \
	    	-e '/fonts"$/ s/^!//' < $TMP > $ISHLIB/Ishmail
	else
		cp $ISHLIB/Ishmail $TMP
		sed -e '/fonts\.ow"$/ s/^!//' \
	    	-e '/fonts"$/ s/^#/!#/' < $TMP > $ISHLIB/Ishmail
	fi
	rm -f $TMP
fi

# retrieve the existing license file, if it's in an obvious place

OLDDIR=`ls -l /usr/bin/ishmail | sed \
	-e "s/.*->[ 	]*//" \
	-e "s|/ishmail||"`

if [ -s "$OLDDIR/license" ]; then
	cp $OLDDIR/license $DIR/license
fi

# fix up permissions and ownerships

find $DIR/$VER -print |xargs chgrp $GROUP
find $DIR/$VER -print |xargs chown bin
if [ $SGID -eq 1 ]; then
	chmod 2755 $DIR/$VER/bin/ishmail.real
fi
rm -f /usr/bin/ishmail
ln -s $DIR/$VER/bin/ishmail /usr/bin/ishmail
if [ -d /usr/man/man1 ]; then
	rm -f /usr/man/man1/ishmail.1
	ln -s $DIR/$VER/man/man1/ishmail.1 /usr/man/man1/ishmail.1
fi
if [ -d /usr/man/cat1 ]; then
	rm -f /usr/man/cat1/ishmail.1
	ln -s $DIR/$VER/man/cat1/ishmail.1 /usr/man/cat1/ishmail.1
fi

echo "#### Installation complete - type \"ishmail\" to use it."
exit 0
