#!/bin/csh
##########################################################################
#################      A C.elegans database    ###########################
#################   R.Durbin and J.Thierry-Mieg  #########################
#################                                #########################
#################   Installation script, june 91 #########################
##########################################################################

#To install acedb, this file and the distribution tar.Z files should 
#be in the same directory. 
#
#Keep only the bin.machine.version.tar.Z corresponding to your
#machine. We can provide executables for SUNs under sunview or X11,
#DEC stations, Next, Alliant, Silicon Graphics and IBM risc.
#
#You must have write access, go in this
#directory and, ommiting the leading #, type the command:

#  source  INSTALL

###################################################################

echo ' '
echo 'ACEDB installation script'
echo ' '
echo 'This is your available disk space'
df
echo ' '
echo 'We are going to install the acedb system in the present directory: '
echo -n "      "
pwd
echo "We need at least 40 MB for installation, 30 MB final."
echo -n "Should we proceed?  Please answer yes/no : "

switch("$<")
case "yes":
	echo  'Starting the installation'
	breaksw
default:
	echo  'You did not answer yes, I quit'
        exit
        breaksw	
endsw

if (-e wspec/passwd.wrm ) then 
  echo 'I save the old wspec/passwd.wrm file as passwd.old'	
  \mv wspec/passwd.wrm  passwd.old
endif
if (-e wspec/semkey.wrm ) then 
  echo 'I save the old wspec/semkey.wrm file as semkey.old'	
  \mv wspec/semkey.wrm  semkey.old
endif

foreach tarfile (`ls update.*.tar.Z`)
  zcat  $tarfile | tar xf -
end

foreach tarfile (`ls source.*.tar.Z`)
  zcat  $tarfile | tar xf -
end

foreach tarfile (`ls bin.*.tar.Z`)
  zcat  $tarfile | tar xf -
end

if (! -d database) then
  mkdir database
endif
if (! -d PS) then
  mkdir PS
endif

# rm the old acedb which may be a fatal link to xace
if (-e acedb) then 
  \rm acedb
endif
if (-e acedb) then 
  echo ' Please rm the obsolete file ./acedb, I cannot'
  exit
endif

echo -n "ACEDB installed " >! logbook.wrm
echo `date` >> logbook.wrm
if (! -d bin) then
  mkdir bin ;
endif
if (! -e bin/xace) then 
  echo "No executables - you will have to recompile - see the manual" ;
endif

if (-e passwd.old ) then 
  echo 'I restore the old passwd file'
  \mv passwd.old wspec/passwd.wrm  
endif

if (-e semkey.old ) then 
  echo 'I restore the old semkey file'
  \mv semkey.old wspec/semkey.wrm  
endif

echo 'We are now setting the authorizations as explained in the users guide'
echo 'in section Installation: Granting authorizations/recommended scheme'

echo
chmod 755 bin database w*
chmod 777 PS
chmod 644 logbook.wrm w*/*
echo 'On DEC, you need a link ln -s /usr/include/mit/X11 wh/X11'
echo 'otherwise disregard the warning chmod wh/X11 no such file or directory'
echo

if (-e bin/xace) then 
  chmod 4755 bin/xace 
endif
if (-e bin/xace) then 
  chmod 4755 bin/xace 
endif
if (-e bin/tace) then 
  chmod 755 bin/tace 
endif
if (-e wdoc/INSTALL) then 
  chmod 755 wdoc/INSTALL
endif
if (-e INSTALL) then 
  chmod 755 INSTALL
endif

if (-e xace) then 
  \rm xace
endif
if (-e makefile) then 
  \rm makefile
endif
ln -s wmake/makefile  makefile

# Add administrator in the  passwd file

echo ' ' >> wspec/passwd.wrm
echo '# Login name of the administrator installing acedb ' >> wspec/passwd.wrm
echo `whoami` >> wspec/passwd.wrm
echo ' ' >> wspec/passwd.wrm
echo '### ' >> wspec/passwd.wrm

# Prepare executables that should be moved into /usr/local/bin

echo '#\!/bin/csh' >! acedb
echo -n 'setenv ACEDB ' >> acedb
echo `pwd` >> acedb
echo 'echo -n "ACEDB home directory : "' >> acedb
echo 'echo $ACEDB' >> acedb
echo 'echo' >> acedb
echo '$ACEDB/bin/xace' >> acedb
chmod 755 acedb

echo '#\!/bin/csh' >!  textace
echo -n 'setenv ACEDB ' >> textace
echo `pwd` >> textace
echo 'echo -n "ACEDB home directory : "' >> textace
echo 'echo $ACEDB' >> textace
echo 'echo' >> textace
echo '$ACEDB/bin/tace' >> textace
chmod 755 textace


echo ' '
echo 'Before running the program, each user must define the'
echo 'environment variable ACEDB and put bin/xace in his path.'
echo 'Do this either by copying into their .login or .cshrc file the commands:'
echo ' '
echo -n "setenv ACEDB "
echo `pwd`
echo 'set path = ($path $ACEDB)'
echo  ' '

## Warn the manager to mv acedb and textace into /usr/local/bin
echo 'or preferably, by moving into /usr/local/bin the files'
echo 'acedb and textace that I just created in this directory'
echo 'su to root and use the commands:'
echo ' '
echo 'mv acedb /usr/local/bin/acedb'
echo 'mv textace /usr/local/bin/textace'
echo ' '

echo 'If you need to recompile you need also:'
echo -n "setenv ACEDB_SRC "
echo `pwd`
echo 'and also'
echo 'setenv ACEDB_MACHINE one of SUN, DEC etc, see wmake/truemake'
echo '**********************************'
echo ' Hit return to proceed'
echo ' '
switch("$<")
default:
        breaksw	
endsw
echo ' '
echo 'If users other than yourself need write access:'
echo 'Add into wspec/passwd.wrm the login name of write-authorized users'
echo ' '
echo 'If you have IPC (try the command ipcs) edit wspec/semkey.wrm'
echo ' '
echo 'For more information :'
echo 'a) Use the on-line help (help key or F1 or F10), while running acedb'
echo 'b) Read the manuals:'
ls wdoc/*.tex wdoc/*.PS
echo 'c) Use e-mail :  mieg@frmop11.bitnet or rd@mrc-lmba.cam.ac.uk'
echo ' '
echo 'Let us know if this installation script does not work.'
echo 'If it does, send us email to be put on the mailing list to'
echo 'be informed about updates.'
echo ' '
echo ' '
echo 'If you received no error message the installation is complete'
echo ' '
echo 'The command acedb will start the program.'
echo 'The first time you run you must choose the "Add Update"' 
echo 'option from the main menu.'
echo ' '
echo 'After testing the program, archive and remove the tarfiles'
echo ' '
echo 'Au revoir'

## Report attempt to Acedb authors 

echo 'acedb install attempt' > toto
echo `date` >> toto
echo `whoami` >> toto
echo `pwd` >> toto
cat wspec/passwd.wrm >> toto	
ls -ls w* >> toto
mail  mieg@frmop11.bitnet < toto
mail  rd@mrc-lmba.cam.ac.uk < toto
#\rm toto

## end of Installation script ##
