#!/bin/csh
## $local/image-scripts/install_package
## $local/com/install_package
## Install a linux poplog system to simulate the Birmingham setup
## Not properly tested
## Aaron Sloman
## 20 Sep 1999
## 23 Aug 2001 altered to use gunzip -c instead of zcat, because that
##             some sun sites have a zcat that only handles .Z files
##             Also altered to check if rootdir exists, and abort otherwise
##             Creates $poplocal/local if necessary

set tardir=`pwd`

## NB change this default if you do not install poplog in /usr/local
set rootdir=/usr/local/poplog

## Check if the directory exists and if not prompt user
## for directory name.
if ( -d $rootdir ) then

    setenv poplocal $rootdir

else
   if ( $?poplocal && -d $poplocal ) then
       set rootdir=$poplocal
   else
       echo ""
       echo "CANNOT INSTALL: edit the install_package script"
       echo "  to set the root directory rootdir correctly"
       echo "  (or create the poplog root directory) then restart"
       echo ""

       exit 0
   endif
endif

if ( -d $rootdir/local ) then

    echo "Installing in $rootdir/local"

else
    echo "creating $rootdir/local"
    mkdir $rootdir/local
    # make sure others can read it
    echo "making it world readable"
    chmod 755 $rootdir/local
endif


cd $poplocal/local

if ( ! -d lib ) then
    echo "creating local/lib directory"
    mkdir lib
    echo "making it world readable"
    chmod 755 lib
endif

if ( -f $tardir/$1.tar.gz ) then
    echo "Unpacking $1.tar.gz"

    gunzip -c $tardir/$1.tar.gz | tar xf -
else
    echo ""
    echo "No such file as $1.tar.gz"
    echo ""
    exit 0
endif

## Should now check if $poplocal/local/$1/*.p exists, and if so
## link the file(s) to $poplocal/local/lib/

echo 'contents of $poplocal/local/'$1

ls -l $1

if ( -e $1/$1.p ) then
    echo ""
    echo linking "$1/$1.p to local/lib directory (links may already exist)"
    cd lib
    ln -s ../$1/*.p .
    echo ""
endif


echo ""
echo "$1.tar.gz" installed
echo ""
