#!/bin/sh
#
# doinstall,v 1.7 1995/11/15 09:26:47 del Exp
#

# Some rational and reasonable defaults.

INSTALLDIR=/usr/local/lib
BINDIR=/usr/local/bin
MANDIR=/usr/local/man/mann

INSTALL_PROG=./install-sh

# This must be an X based editor -- do NOT use vi except via an xterm
# or shelltool.

EDITOR=nedit

# Find a Tk interpreter.
 
WISH=`which wish4.0`
if [ ! -x $WISH ]; then
  echo "I cant find a Tk interpreter on your system"
  exit 1
fi

# Find where the global bitmaps are.

for GDIR in /usr/include/X11/bitmaps /usr/openwin/include/X11/bitmaps /usr/X11/include/bitmaps /usr/include/bitmaps /usr/local/include/bitmaps
do
  if [ -d $GDIR ]; then
    break
  fi
done
if [ ! -d ${GDIR:-null} ]; then
  echo "Enter the directory where your X11 bitmaps are stored:"
  GDIR=`line`
  if [ ! -d $GDIR ]; then
    echo "I cant find that directory"
    exit 1
  fi
fi

# Find out where we want the system installed.

if [ ! -d ${INSTALLDIR:-null} ]; then
  echo "Enter the top level installation directory:"
  INSTALLDIR=`line`
  mkdir -p $INSTALLDIR
  if [ ! -d $INSTALLDIR ]; then
    echo "I cant create that directory"
    exit 1
  fi
  if [ ! -w $INSTALLDIR ]; then
    echo "I cant write to that directory"
    exit 1
  fi
fi

# Some directories we have to create.

LDIR=${INSTALLDIR}/bitmaps
TCDIR=${INSTALLDIR}/tkcvs
mkdir -p $LDIR $TCDIR
for dir in $LDIR $TCDIR
do
  if [ ! -d $dir ]; then
    echo "I cant create the directory $dir"
    exit 1
  fi
done

if [ ! -d ${BINDIR:-null} ]; then
  echo "Enter the directory where you want the programs to be stored:"
  BINDIR=`line`
  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

for file in tkcvs cvscheck ../tkdiff/tkdiff
do
  if [ -r $file.blank ]; then
    sed -e "/WISH/ s;;$WISH;g" \
      -e "/LDIR/ s;;$LDIR;g" \
      -e "/GDIR/ s;;$GDIR;g" \
      -e "/EDITOR/ s;;$EDITOR;g" \
      -e "/TCDIR/ s;;$TCDIR;g" ${file}.blank >$file
    $INSTALL_PROG -m 555 $file $BINDIR
    rm -f $file
  fi
done

for f in *.n ../tkdiff/*.n
do
        $INSTALL_PROG -m 444 $f $MANDIR
done
for f in *.tcl
do
        $INSTALL_PROG -m 444 $f $TCDIR
done
for f in ../bitmaps/*.xbm
do
        $INSTALL_PROG -m 444 $f $LDIR
done
install -m 444 tclIndex $TCDIR
