#!/bin/sh
#
# $Id: doinstall,v 1.9.2.12 1999/10/03 06:52:36 dorothyr Exp $
#

#
# Some rational and reasonable defaults.
#
INSTALLROOT=/usr/local
#INSTALLROOT=$HOME

BINDIR=$INSTALLROOT/bin
MANDIR=$INSTALLROOT/man/mann

INSTALL_PROG=./install-sh

#
# Find out where we want the system installed.
#
if [ ! -d "$INSTALLROOT" ]; then
  echo "Enter the top level installation directory:"
  read INSTALLROOT
  mkdir -p $INSTALLROOT
  if [ ! -d $INSTALLROOT ]; then
    echo "I cant create that directory"
    exit 1
  fi
  if [ ! -w $INSTALLROOT ]; then
    echo "I cant write to that directory"
    exit 1
  fi
fi

#
# Some directories we have to create.
#
INSTALLDIR=$INSTALLROOT/lib
LDIR=${INSTALLDIR}/bitmaps
TCDIR=${INSTALLDIR}/tkcvs
mkdir -p $LDIR $TCDIR $MANDIR
for dir in $LDIR $TCDIR $MANDIR
do
  if [ ! -d $dir ]; then
    echo "I cant create the directory $dir"
    exit 1
  fi
done

if [ ! -d "$BINDIR" ]; then
  echo "Enter the directory where you want the programs to be stored:"
  read BINDIR
  if [ ! -d "$BINDIR" ]; then
    echo "I cant find that directory"
    exit 1
  fi
  if [ ! -w "$BINDIR" ]; then
    echo "I cant write to that directory" 
    exit 1 
  fi
fi

if [ -r tkcvs.blank ]; then
  echo "tkcvs.blank => tkcvs"
  sed -e "/LDIR/ s;;$LDIR;g" \
      -e "/TCDIR/ s;;$TCDIR;g" tkcvs.blank > tkcvs
fi

for f in tkcvs ../tkdiff/tkdiff
do
  echo "Installing $f in $BINDIR"
  $INSTALL_PROG -m 755 $f $BINDIR
done

for f in *.n
do
  echo "Installing $f in $MANDIR"
  $INSTALL_PROG -m 644 $f $MANDIR
done

echo "Populating $TCDIR"
for f in *.tcl
do
  echo "  $f"
  $INSTALL_PROG -m 644 $f $TCDIR
done

echo "Installing icons in $LDIR"
for f in ../bitmaps/*.gif ../bitmaps/*.xbm
do
  $INSTALL_PROG -m 644 $f $LDIR
done

echo "Installing tclIndex"
$INSTALL_PROG -m 644 tclIndex $TCDIR
