#!/bin/sh
#*******************************************************************************
#                                                                              *
#                                   Viewmol                                    *
#                                                                              *
#                                I N S T A L L                                 *
#                                                                              *
#                 Copyright (c) Joerg-R. Hill, October 2003                    *
#                                                                              *
#*******************************************************************************
#
# $Id: install,v 1.2 2004/08/29 14:53:37 jrh Exp $
# $Log: install,v $
# Revision 1.2  2004/08/29 14:53:37  jrh
# Release 2.4.1
#
# Revision 1.1  2003/11/07 13:05:40  jrh
# Initial revision
#

if [ "$1" = "" ]
then
  prgname=`basename $0`
  echo "${prgname}: ERROR: Usage: $prgname <directory>."
  exit 1
fi
ROOT=$1

# find name of directory for execuatable
os=`uname -s`
case $os in
  AIX)     if [ `uname -m | cut -c9-10` = "70" ]
           then
             dir="${os}_POWER2"
           else
             dir="${os}_POWER"
           fi
           dirorig="AIX_POWER2"
           ;;
  IRIX*)   dir="${os}_`hinv | awk '/CPU:/ {print $3}' | cut -d/ -f2`"
           dirorig="IRIX_R5000"
           ;;
  *)       dir="$os"
           dirorig="$os"
           ;;
esac

# install executable in $ROOT/bin
if [ ! -d $ROOT/bin ]
then
  mkdir -p $ROOT/bin
  chmod 755 $ROOT/bin
fi
cp $dirorig/viewmol $ROOT/bin
chmod 711 $ROOT/bin/viewmol

# install other files needed in $ROOT/lib/viewmol
if [ ! -d $ROOT/lib/viewmol/$dir ]
then
  mkdir -p $ROOT/lib/viewmol/$dir
  chmod 755 $ROOT/lib/viewmol/$dir
fi
cd $dirorig
cp tm bio readgamess readgauss readmopac readpdb $ROOT/lib/viewmol/$dir
chmod 711 $ROOT/lib/viewmol/$dir/*
cd ../..
cp readdmol readdmol.awk readgulp readpqs writecar writegauss.py writemol writetm $ROOT/lib/viewmol
chmod 755 $ROOT/lib/viewmol/*
cp -r doc examples locale scripts tests $ROOT/lib/viewmol
find $ROOT/lib/viewmol -type f -exec chmod a+r {} \;
find $ROOT/lib/viewmol -type d -exec chmod a+rx {} \;
sed 's/\/source//g' viewmolrc > $ROOT/lib/viewmol/viewmolrc
chmod -R 644 $ROOT/lib/viewmol/viewmolrc
if [ -d /usr/X11R6/lib/X11/app-defaults ]
then
  locale=`echo $LANG | cut -c1-2`
  if [ "$locale" = "en" ]
  then
    locale="${locale}_US"
  elif [ "$locale" = "C" ]
  then
    # The C locale is defined by default for rpm builds, overwrite it
    locale="en_US"
  fi
  cp locale/${locale}/Viewmol /usr/X11R6/lib/X11/app-defaults
  chmod a+r /usr/X11R6/lib/X11/app-defaults/Viewmol
fi
