#!/bin/csh -f
#
# This file is part of the Maxwell Word Processor application.
# Copyright (C) 1996, 1997, 1998 Andrew Haisley, David Miller, Tom Newton
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Description:
#
# Take a built maxwell and put all the bits into the specified installation
# directory.
#
# The directory structure is:
#
#$target/
#	bin
#	bitmaps
#	fonts
#	help
#	template
#	text
#	resource	
#

set dollar='$'
set scriptName=`basename $0`

if($#argv != 2) then
  echo "Usage $scriptName <source directory> <target installation directory>"
  exit 1
endif

umask 022
set source = $1
set target = $2

#
# Make directories in the target area 
#

mkdir $target

set fullpathtarget = `(cd $target;pwd)`

foreach dir ( bin bitmaps fonts help template text resource )
	mkdir $target/$dir
end
mkdir $target/fonts/Type1

#
# Find fonts and put the symbolic links in
#

set fontdir = /usr/lib/X11/fonts/Type1

if ( ! -d $fontdir ) then
  echo "Cannot find any Postscript Type 1 fonts on your system.  You need"
  echo "these to use Maxwell WP.  They should come included with your Linux"
  echo "distribution.  If you do have them but they are not in $fontdir"
  echo "then edit this script to point at the right place."
  exit -1
endif

if ( ! -f $fontdir/UTRG____.pf* || \
     ! -f $fontdir/UTB_____.pf* || \
     ! -f $fontdir/UTI_____.pf* || \
     ! -f $fontdir/UTBI____.pf* ) then
  echo "Cannot find the Utopia Postscript Type 1 fontset which is required by"
  echo "Maxwell WP.  Please install the four font files in $fontdir ."
  exit -1
endif

ln -s $fontdir/* $target/fonts/Type1

#
# Copy and strip maxwell executable
#

cp $source/exe/maxwell $target/bin/maxwell-0.5.3
ln -s maxwell-0.5.3 $target/bin/maxwell
#strip $target/bin/maxwell
#ln -s $source/exe/maxwell $target/bin

#
# Link up the executables and other stuff that maxwell needs
#
ln -s /usr/bin/{file,ispell,lpr} $target/bin
ln -s /usr/lib/ispell $target/dict

#
# Copy bitmaps
#
cp `find $source -name '*.xpm' -print` $target/bitmaps
chmod 644 $target/bitmaps/*

echo $source

#
# Copy resource file
#
cp $source/edit/app/maxwell.rsc $target/resource

#
# Copy help files
#
cp $source/help/help/{*.rtf,*.ps,*.map} $target/help

#
# Copy default maxwellrc file
#
cp $source/edit/app/maxwellrc $target/.maxwellrc

#
# Copy text
#
cp `find $source -name '*.txt' -print` $target/text

#
# make sure permissions are correct
#
chmod -R uga-w $target
chmod 777 $target/fonts/Type1 $target/template

echo
echo "Installation complete."

set defaultlocation=/usr/local/maxwell

if ($target == $defaultlocation) then
  cat <<EOF
To run maxwell add $defaultlocation/bin to your path and type maxwell
at the command prompt or just type $defualtlocation/bin/maxwell.
--
EOF
else
  cat <<EOF

You did not install Maxwell in the default location $defaultlocation .
This is OK, but in order to run Maxwell, you need to set the MAXHOME
environment variable to $target and add 
$defaultlocation/bin to your
path before you run maxwell.  To do this add the following lines to
your ~/.cshrc file if you use the C shell:

setenv MAXHOME $fullpathtarget
setenv PATH ${dollar}MAXHOME/bin:${dollar}PATH

Or if you use the bourne shell add the following to your ~/.profile file:

export MAXHOME=$fullpathtarget
export PATH=${dollar}MAXHOME/bin:${dollar}PATH

bug reports to maxwell@eeyore-mule.demon.co.uk
--
EOF
endif
