#!/bin/sh
# Scriptname: gempackdm-1.0.1-8 installation script

abort () {
  echo
  echo "The installation of GEMPACK-$PACKAGE_VERSION-$PACKAGE_RELEASE Demonstration-Version has been aborted."
  exit 1
}       

answer_is_yes() {
  read answer
  case "$answer" in
  n* | N*)
    return 1;;
  q* | Q*)
    abort;;
  *)          
    return 0;;
  esac 
} 

write_uninstall_script() { 

echo "#!/bin/sh" > $1/${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.uninstall.sh
echo "rm -rf $1/gp80" >> $1/${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.uninstall.sh

if [ "$2" ] 
then
  cat >> $1/${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.uninstall.sh << EOF 

if [ -f $2 ]   
then  
#  if grep '^$BASHRC_LD_LIBRARY_PATH$' $2 > /dev/null 2>&1
#  then 
#    cp -f $2 $2.${PACKAGE_NAME}_uninstall.01.bak
#    if [ -f $2.${PACKAGE_NAME}_uninstall.01.bak ]
#    then   
#      echo 'Removing "$BASHRC_LD_LIBRARY_PATH" from $2'
#      echo $GEMPACK_LOG_TAG' Removing "$BASHRC_LD_LIBRARY_PATH" from $2' >> $1/logs/errors.log
#      sed s#'^$BASHRC_LD_LIBRARY_PATH$'## $2.${PACKAGE_NAME}_uninstall.01.bak > $2
#    else
#      echo "file $2.${PACKAGE_NAME}_uninstall.01.bak does not exist." >> $1/logs/errors.log
#      exit 1     
#    fi         
#  fi
  if grep '^$BASHRC_GEMPACK_PATH$' $2 > /dev/null 2>&1  
  then 
    cp -f $2 $2.${PACKAGE_NAME}_uninstall.02.bak
    if [ -f $2.${PACKAGE_NAME}_uninstall.02.bak ]
    then    
      echo 'Removing "$BASHRC_GEMPACK_PATH" from $2'
      echo $GEMPACK_LOG_TAG' Removing "$BASHRC_GEMPACK_PATH" from $2' >> $1/logs/errors.log
      sed s#'^$BASHRC_GEMPACK_PATH$'## $2.${PACKAGE_NAME}_uninstall.02.bak > $2
    else
      echo "file $2.${PACKAGE_NAME}_uninstall.02.bak does not exist." >> $1/logs/errors.log
      exit 1
    fi
  fi          
  if grep '^$BASHRC_GPDIR$' $2 > /dev/null 2>&1
  then
    cp -f $2 $2.${PACKAGE_NAME}_uninstall.03.bak
    if [ -f $2.${PACKAGE_NAME}_uninstall.03.bak ]
    then
      echo 'Removing "$BASHRC_GPDIR" from $2'
      echo $GEMPACK_LOG_TAG' Removing "$BASHRC_GPDIR" from $2' >> $1/logs/errors.log
      sed s#'^$BASHRC_GPDIR$'## $2.${PACKAGE_NAME}_uninstall.03.bak > $2
    else
      echo "file $2.${PACKAGE_NAME}_uninstall.03.bak does not exist." >> $1/logs/errors.log
      exit 1
    fi
  fi
fi
EOF
fi     

if [ "$3" ] 
then
  cat >> $1/${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.uninstall.sh << EOF 

if [ -f $3 ] 
then
  if grep '^$CSH_CSHRC_GEMPACK_PATH$' $3 > /dev/null 2>&1
  then
    cp -f $3 $3.${PACKAGE_NAME}_uninstall.01.bak
    if [ -f $3.${PACKAGE_NAME}_uninstall.01.bak ]
    then
      echo 'Removing "$CSH_CSHRC_GEMPACK_PATH" from $3'
      echo $GEMPACK_LOG_TAG' Removing "$CSH_CSHRC_GEMPACK_PATH" from $3' >> $1/logs/errors.log
      sed s#'^$CSH_CSHRC_GEMPACK_PATH$'## $3.${PACKAGE_NAME}_uninstall.01.bak > $3
    else
      echo "file $3.${PACKAGE_NAME}_uninstall.01.bak does not exist." >> $1/logs/errors.log
      exit 1
    fi
  fi
#  if grep '^$CSH_CSHRC_LD_LIBRARY_PATH$' $3 > /dev/null 2>&1    
#  then
#    cp -f $3 $3.${PACKAGE_NAME}_uninstall.02.bak
#    if [ -f $3.${PACKAGE_NAME}_uninstall.02.bak ]
#    then
#      echo 'Removing "$CSH_CSHRC_LD_LIBRARY_PATH" from $3'
#      echo $GEMPACK_LOG_TAG' Removing "$CSH_CSHRC_LD_LIBRARY_PATH" from $3' >> $1/logs/errors.log
#      sed s#'^$CSH_CSHRC_LD_LIBRARY_PATH$'## $3.${PACKAGE_NAME}_uninstall.02.bak > $3
#    else
#      echo "file $3.${PACKAGE_NAME}_uninstall.02.bak does not exist." >> $1/logs/errors.log
#      exit 1
#    fi
#  fi
  if grep '^$CSH_CSHRC_GPDIR$' $3 > /dev/null 2>&1
  then
    cp -f $3 $3.${PACKAGE_NAME}_uninstall.03.bak 
    if [ -f $3.${PACKAGE_NAME}_uninstall.03.bak ]
    then
      echo 'Removing "$CSH_CSHRC_GPDIR" $3'
      echo $GEMPACK_LOG_TAG' Removing "$CSH_CSHRC_GPDIR" from $3' >> $1/logs/errors.log
      sed s#'^$CSH_CSHRC_GPDIR$'## $3.${PACKAGE_NAME}_uninstall.03.bak > $3
    else
      echo "file $3.${PACKAGE_NAME}_uninstall.03.bak does not exist." >> $1/logs/errors.log
      exit 1
    fi
  fi
fi       
EOF
fi
echo "echo \"${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE} was successfully removed from your system.\"" >> $1/${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.uninstall.sh
echo "echo \"$1 was not removed from your system for security reasons.\"" >> $1/${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.uninstall.sh
chmod +x $1/${PACKAGE_NAME}-${PACKAGE_VERSION}-${PACKAGE_RELEASE}.uninstall.sh
}

make_changes_to_bashrc() 
{ 
echo "$GEMPACK_LOG_TAG Applying $1 changes" >> $installation_directory/logs/errors.log 
if [ -f $1 ] 
then
#  if grep ^$BASHRC_LD_LIBRARY_PATH$ $1 > /dev/null 2>&1
#  then :
#  else
#    echo -n "Adding \"$BASHRC_LD_LIBRARY_PATH\" to $1"
#    cp -f $1 $1.${PACKAGE_NAME}_install.bak
#    if [ -f $1.${PACKAGE_NAME}_install.bak ]
#    then
#      echo "$GEMPACK_LOG_TAG Adding \"$BASHRC_LD_LIBRARY_PATH\" to $1" >> $installation_directory/logs/errors.log
#      echo "$BASHRC_LD_LIBRARY_PATH" >> $1
#      if $status
#      then
#        echo " [OK]"
#      else
#        echo " [FAILED]"
#        echo "Could not add $BASHRC_LD_LIBRARY_PATH to $1." >> $installation_directory/logs/errors.log
#        echo "Please inspect $installation_directory/logs/errors.log"; exit 1
#      fi
#    else
#      echo " [FAILED]"
#      echo "file $1.${PACKAGE_NAME}_install.bak does not exist." >> $installation_directory/logs/errors.log
#      echo "Could not add $BASHRC_LD_LIBRARY_PATH to $1." >> $installation_directory/logs/errors.log        
#      echo "Please inspect $installation_directory/logs/errors.log"; exit 1
#    fi
#  fi
  if grep ^$BASHRC_GEMPACK_PATH$ $1 > /dev/null 2>&1
  then :
  else
    echo -n "Adding \"$BASHRC_GEMPACK_PATH\" to $1"
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then :
    else
      cp -f $1 $1.${PACKAGE_NAME}_install.bak
    fi
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then
      echo "$GEMPACK_LOG_TAG Adding \"$BASHRC_GEMPACK_PATH\" to $1" >> $installation_directory/logs/errors.log
      echo "$BASHRC_GEMPACK_PATH" >> $1
      if $status
      then
        echo " [OK]"
      else
        echo " [FAILED]"
        echo "Could not add $BASHRC_GEMPACK_PATH to $1." >> $installation_directory/logs/errors.log
        echo "Please inspect $installation_directory/logs/errors.log"; exit 1
      fi
    else
      echo " [FAILED]"
      echo "file $1.${PACKAGE_NAME}_install.bak does not exist." >> $installation_directory/logs/errors.log
      echo "Could not add $BASHRC_GEMPACK_PATH to $1." >> $installation_directory/logs/errors.log
      echo "Please inspect $installation_directory/logs/errors.log"; exit 1
    fi
  fi
 
  if grep ^$BASHRC_GPDIR$ $1 > /dev/null 2>&1 
  then :
  else
    echo -n "Adding \"$BASHRC_GPDIR\" to $1"
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then :
    else
      cp -f $1 $1.${PACKAGE_NAME}_install.bak
    fi
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then
      echo "$GEMPACK_LOG_TAG Adding \"$BASHRC_GPDIR\" to $1" >> $installation_directory/logs/errors.log
      echo "$BASHRC_GPDIR" >> $1
      if $status
      then
        echo " [OK]"
      else
        echo " [FAILED]"
        echo "Could not add $BASHRC_GPDIR to $1." >> $installation_directory/logs/errors.log
        echo "Please inspect $installation_directory/logs/errors.log"; exit 1
      fi
    else
      echo " [FAILED]"
      echo "file $1.${PACKAGE_NAME}_install.bak does not exist." >> $installation_directory/logs/errors.log
      echo "Could not add $BASHRC_GPDIR to $1." >> $installation_directory/logs/errors.log
      echo "Please inspect $installation_directory/logs/errors.log"; exit 1
    fi
  fi 
else
  echo "Creating $1"
#  echo "Adding \"$BASHRC_LD_LIBRARY_PATH\" to $1"
  echo "$GEMPACK_LOG_TAG Adding \"$BASHRC_LD_LIBRARY_PATH\" to $1" >> $installation_directory/logs/errors.log
#  echo "$BASHRC_LD_LIBRARY_PATH" >> $1
  echo "Adding \"$BASHRC_GEMPACK_PATH\" to $1"
  echo "$GEMPACK_LOG_TAG Adding \"$BASHRC_GEMPACK_PATH\" to $1" >> $installation_directory/logs/errors.log
  echo "$BASHRC_GEMPACK_PATH" >> $1
  echo "Adding \"$BASHRC_GPDIR\" to $1"
  echo "$GEMPACK_LOG_TAG Adding \"$BASHRC_GPDIR\" to $1" >> $installation_directory/logs/errors.log
  echo "$BASHRC_GPDIR" >> $1 
fi 
echo "$GEMPACK_LOG_TAG APPLIED $1 changes" >> $installation_directory/logs/errors.log
}             

make_changes_to_cshrc() 
{ 
echo "$GEMPACK_LOG_TAG Applying $1 changes" >> $installation_directory/logs/errors.log 
if [ -f $1 ] 
then
#  if grep ^$CSH_CSHRC_LD_LIBRARY_PATH$ $1 > /dev/null 2>&1
#  then :
#  else
#    echo -n "Adding \"$CSH_CSHRC_LD_LIBRARY_PATH\" to $1"
#    cp -f $1 $1.${PACKAGE_NAME}_install.bak
#    if [ -f $1.${PACKAGE_NAME}_install.bak ]
#    then
#      echo "$GEMPACK_LOG_TAG Adding \"$CSH_CSHRC_LD_LIBRARY_PATH\" to $1" >> $installation_directory/logs/errors.log  
#      echo "$CSH_CSHRC_LD_LIBRARY_PATH" >> $1
#      if $status
#      then
#        echo " [OK]"
#      else
#        echo " [FAILED]"
#        echo "Could not add $CSH_CSHRC_LD_LIBRARY_PATH to $1." >> $installation_directory/logs/errors.log
#        echo "Please inspect $installation_directory/logs/errors.log"; exit 1
#      fi
#    else
#      echo " [FAILED]"
#      echo "file $1.${PACKAGE_NAME}_install.bak does not exist." >> $installation_directory/logs/errors.log
#      echo "Could not add $CSH_CSHRC_LD_LIBRARY_PATH to $1." >> $installation_directory/logs/errors.log
#      echo "Please inspect $installation_directory/logs/errors.log"; exit 1
#    fi
#  fi
  if grep ^$CSH_CSHRC_GEMPACK_PATH$ $1 > /dev/null 2>&1
  then :      
  else
    echo -n "Adding \"$CSH_CSHRC_GEMPACK_PATH\" to $1"
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then :
    else
      cp -f $1 $1.${PACKAGE_NAME}_install.bak
    fi
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then
      echo "$GEMPACK_LOG_TAG Adding \"$CSH_CSHRC_GEMPACK_PATH\" to $1" >> $installation_directory/logs/errors.log
      echo "$CSH_CSHRC_GEMPACK_PATH" >> $1
      if $status
      then
        echo " [OK]"       
      else
        echo " [FAILED]"
        echo "Could not add $CSH_GEMPACK_PATH to $1." >> $installation_directory/logs/errors.log
        echo "Please inspect $installation_directory/logs/errors.log"; exit 1
      fi
    else
      echo " [FAILED]"
      echo "file $1.${PACKAGE_NAME}_install.bak does not exist." >> $installation_directory/logs/errors.log
      echo "Could not add $CSH_GEMPACK_PATH to $1." >> $installation_directory/logs/errors.log
      echo "Please inspect $installation_directory/logs/errors.log"; exit 1
    fi
  fi        

  if grep ^$CSH_CSHRC_GPDIR$ $1 > /dev/null 2>&1
  then :
  else
    echo -n "Adding \"$CSH_CSHRC_GPDIR\" to $1"
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then :
    else
      cp -f $1 $1.${PACKAGE_NAME}_install.bak
    fi
    if [ -f $1.${PACKAGE_NAME}_install.bak ]
    then
      echo "$GEMPACK_LOG_TAG Adding \"$CSH_CSHRC_GPDIR\" to $1" >> $installation_directory/logs/errors.log
      echo "$CSH_CSHRC_GPDIR" >> $1
      if $status
      then
        echo " [OK]"
      else
        echo " [FAILED]"
        echo "Could not add $CSH_CSHRC_GPDIR to $1." >> $installation_directory/logs/errors.log
        echo "Please inspect $installation_directory/logs/errors.log"; exit 1
      fi
    else       
      echo " [FAILED]"
      echo "Could not add $CSH_CSHRC_GPDIR to $1." >> $installation_directory/logs/errors.log
      echo "file $1.${PACKAGE_NAME}_install.bak does not exist." >> $installation_directory/logs/errors.log
      echo "Please inspect $installation_directory/logs/errors.log"; exit 1
    fi
  fi
else      
  echo "Creating $1"
#  echo "Adding \"$CSH_CSHRC_LD_LIBRARY_PATH\" to $1"
  echo "$GEMPACK_LOG_TAG Adding \"$CSH_CSHRC_LD_LIBRARY_PATH\" to $1" >> $installation_directory/logs/errors.log
#  echo "$CSH_CSHRC_LD_LIBRARY_PATH" >> $1
  echo "Adding \"$CSH_CSHRC_GEMPACK_PATH\" to $1"
  echo "$GEMPACK_LOG_TAG Adding \"$CSH_CSHRC_GEMPACK_PATH\" to $1" >> $installation_directory/logs/errors.log
  echo "$CSH_CSHRC_GEMPACK_PATH" >> $1
  echo "Adding \"$CSH_CSHRC_GPDIR\" to $1"
  echo "$GEMPACK_LOG_TAG Adding \"$CSH_CSHRC_GPDIR\" to $1" >> $installation_directory/logs/errors.log
  echo "$CSH_CSHRC_GPDIR" >> $1 
fi 
echo "$GEMPACK_LOG_TAG APPLIED $1 changes" >> $installation_directory/logs/errors.log
}               

set_permissions_for_group() 
{
  if `chmod g=rx $1`
  then                                       
    echo "Group users can read and execute $1 [OK]"
  else
    echo "Group users can read and execute $1 [FAILED]"  
  fi
  if `chmod o= $1` 
  then
    echo "Other users can not read write or execute $1 [OK]"
  else
    echo "Other users can not read write or execute $1 [FAILED]"
  fi
  if `chmod g=r $1/*` 
  then
    echo "Group users can read all files in $1 [OK]"
  else
    echo "Group users can read all files in $1 [FAILED]"
  fi
  if `chmod o= $1/*`
  then
    echo "Other users can not read write or execute files in $1 [OK]"
  else
    echo "Other users can not read write or execute files in $1 [FAILED]"
  fi
  if `chmod g=rx $1/gp80`
  then
    echo "Group users can not read and execute $1/gp80 [OK]"
  else
    echo "Group users can not read and execute $1/gp80 [FAILED]"
  fi
  if `chmod o= $1/gp80`
  then
    echo "Other users can not read write or execute $1/gp80 [OK]"
  else
    echo "Other users can not read write or execute $1/gp80 [FAILED]"
  fi
  if `chmod g=rx $1/gp80/*`
  then
    echo "Group users can read and execute all files in $1/gp80 [OK]"
  else
    echo "Group users can read and execute all files in $1/gp80 [FAILED]"
  fi
  if `chmod o= $1/gp80/*`
  then
    echo "Other users can not read write or execute files in $1/gp80 [OK]"
  else
    echo "Other users can not read write or execute files in $1/gp80 [FAILED]"
  fi
  if `chmod g=rx $1/gp80/examples`
  then
    echo "Group users can read and execute $1/gp80/examples [OK]"
  else
    echo "Group users can read and execute $1/gp80/examples [FAILED]"
  fi
  if `chmod o= $1/gp80/examples`
  then
    echo "Other users can not read write or execute $1/gp80/examples [OK]"
  else
    echo "Other users can not read write or execute $1/gp80/examples [FAILED]"
  fi
  if `chmod g=rx $1/gp80/examples/*`
  then
    echo "Group users can read and execute all files in $1/gp80/examples [OK]"
  else
    echo "Group users can read and execute all files in $1/gp80/examples [FAILED]"
  fi
  if `chmod o= $1/gp80/examples/*`
  then
    echo "Other users can not read write or execute files in $1/gp80/examples [OK]"
  else
    echo "Other users can not read write or execute files in $1/gp80/examples [FAILED]"
  fi
}

set_permissions_for_others()
{
  if `chmod o=rx $1`
  then
    echo "Other users can read and execute $1 [OK]"
  else
    echo "Other users can read and execute $1 [FAILED]"
  fi
  if `chmod o=r $1/*`
  then
    echo "Other users can read all files in $1 [OK]"
  else
    echo "Other users can read all files in $1 [FAILED]"
  fi
  if `chmod o=rx $1/gp80`
  then
    echo "Other users can read and execute $1/gp80 [OK]"
  else
    echo "Other users can read and execute $1/gp80 [FAILED]"
  fi
  if `chmod o=rx $1/gp80/*`
  then
    echo "Other users can read and execute all files in $1/gp80 [OK]"
  else
    echo "Other users can read and execute all files in $1/gp80 [FAILED]"
  fi
  if `chmod o=rx $1/gp80/examples`
  then
    echo "Other users can read and execute $1/gp80/examples [OK]"
  else
    echo "Other users can read and execute $1/gp80/examples [FAILED]"
  fi
  if `chmod o=rx $1/gp80/examples/*`
  then
    echo "Other users can read and execute all files in $1/gp80/examples [OK]"
  else
    echo "Other users can read and execute all files in $1/gp80/examples [FAILED]"
  fi
}

PACKAGE_NAME=gempackdm  
PACKAGE_VERSION=1.0.1
PACKAGE_RELEASE=7
DEFAULT_INSTALLATION_DIRECTORY=/usr/local/gp/gempack

current_directory=$PWD
clear 
echo "This script installs GEMPACK-$PACKAGE_VERSION-$PACKAGE_RELEASE Demonstration-Version."  
if [ -f gempackdm-1.0.1-8.tar.gz ] 
then
  installation_directory_is_correct=""
  until [ "$installation_directory_is_correct" ] 
  do
    echo "Where would you like to install GEMPACK-$PACKAGE_VERSION-$PACKAGE_RELEASE Demonstration-Version? [$DEFAULT_INSTALLATION_DIRECTORY]?" 
    echo -n "> "
    read installation_directory
    if [ "$installation_directory" = "" ]
    then 
      installation_directory=$DEFAULT_INSTALLATION_DIRECTORY
    else 
      case "$installation_directory" in
      /*) 
        :;;
      *) 
        installation_directory=$current_directory/$installation_directory;;
      esac
    fi
    echo -n "$installation_directory: Is this correct? [(n)o (q)uit] [y]"
    if 'answer_is_yes'
    then
      installation_directory_is_correct="yes"
      if [ -d $installation_directory ]
      then
        echo "$installation_directory already exists."
        if [ -w $installation_directory ]
        then :
        else
          echo "$installation_directory is write-protected."
          installation_directory_is_correct=""
        fi                       
      elif [ -f $installation_directory ]
      then
        echo "$installation_directory is a file."   
        installation_directory_is_correct=""
      else
        echo "$installation_directory does not exist."
        echo "$installation_directory will be created."
        install -d $installation_directory 2>/dev/null
        if [ -d $installation_directory ]
        then :
        else 
          echo "$installation_directory could not be created."
          installation_directory_is_correct=""
        fi
      fi
    fi
  done
  install -d $installation_directory/logs 2>/dev/null
  if [ ! -d $installation_directory/logs ] 
  then
    echo "$installation_directory/logs could not be created."
    abort
  fi
  cp -f gempackdm-1.0.1-8.tar.gz $installation_directory 2> $installation_directory/logs/errors.log
  cd $installation_directory 2> $installation_directory/logs/errors.log
  /bin/gzip -dc gempackdm-1.0.1-8.tar.gz | tar -xvvf - 2> $installation_directory/logs/errors.log
  cd gempackdm-1.0.1 2> $installation_directory/logs/errors.log
  install -d $installation_directory/gp80 2> $installation_directory/logs/errors.log 
  if [ ! -d $installation_directory/gp80 ] 
  then
    echo "$installation_directory/gp80 could not be created."
    abort
  fi
# was  for file in tablo gemsim gempie sagem modhar seehar mkhar rwhar libfj9f6.so.1 libfj9i6.so.1 examples-linux.tar
  for file in tablo gemsim gempie sagem modhar seehar mkhar rwhar examples-linux.tar
  do
    if [ -f $file ]
    then
      install $file $installation_directory/gp80/$file 2> $installation_directory/logs/errors.log
    else
      echo "file $PWD/$file does not exist." >> $installation_directory/logs/errors.log
      echo "Please inspect $installation_directory/logs/errors.log"
      abort
    fi
  done    

  cd $installation_directory 2> $installation_directory/logs/errors.log
  rm -rf gempackdm-1.0.1 2> $installation_directory/logs/errors.log

  install -d $installation_directory/logs 2> $installation_directory/logs/errors.log
  rm -rf $installation_directory/logs/* 2> $installation_directory/logs/errors.log
  
#  BASHRC_LD_LIBRARY_PATH="export LD_LIBRARY_PATH=$installation_directory/gp80:"'$LD_LIBRARY_PATH'
  BASHRC_GEMPACK_PATH="export PATH=$installation_directory/gp80:"'$PATH'
  BASHRC_GPDIR="export gpdir=$installation_directory" 
#  CSH_CSHRC_LD_LIBRARY_PATH="set LD_LIBRARY_PATH=($installation_directory/gp80 "'$LD_LIBRARY_PATH)'
  CSH_CSHRC_GEMPACK_PATH="set PATH=($installation_directory/gp80 "'$PATH)'
  CSH_CSHRC_GPDIR="setenv gpdir $installation_directory"
  GEMPACK_LOG_TAG='%%GP%%'

  cd $installation_directory/gp80 
  echo -n "Extracting $installation_directory/gp80/examples-linux.tar" 
  echo "$GEMPACK_LOG_TAG Extracting $installation_directory/gp80/examples-linux.tar" >> $installation_directory/logs/errors.log 
  if [ -f $installation_directory/gp80/examples-linux.tar ] 
  then
    tar xvf $installation_directory/gp80/examples-linux.tar > $installation_directory/logs/examples-linux.tar.log 2>&1
    cat $installation_directory/logs/examples-linux.tar.log >> $installation_directory/logs/errors.log
    if [ -d $installation_directory/gp80/examples ]
    then
      echo " [OK]"
    else
      echo " [FAILED]"
      echo "directory $installation_directory/gp80/examples does not exist." >> $installation_directory/logs/errors.log
    fi
  else
    echo " [FAILED]"
    echo "file $installation_directory/gp80/examples-linux.tar does not exist." >> $installation_directory/logs/errors.log
  fi
  if [ -f /etc/bashrc -a -w /etc/bashrc ]
  then
    echo "Would you like this script to make the required changes to your /etc/bashrc file? [(n)o (q)uit] [y]"
    echo -n "> "
    if 'answer_is_yes'
    then
      BASHRC=/etc/bashrc
      make_changes_to_bashrc /etc/bashrc
    else
      if [ ! -f $HOME/.bashrc ]
      then
        echo "Would you like this script to make the required changes to $HOME/.bashrc file? [(n)o (q)uit] [y]"
        echo -n "> "
        if 'answer_is_yes'
        then
  	  BASHRC=$HOME/.bashrc
          make_changes_to_bashrc $HOME/.bashrc
        else
          echo "You will need to manually amend /etc/bashrc to run GEMPACK from within a Bourne Shell."
          echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
        fi
      elif [ -f $HOME/.bashrc -a -w $HOME/.bashrc ]
      then
        echo "Would you like this script to make the required changes to $HOME/.bashrc file? [(n)o (q)uit] [y]"
        echo -n "> "
        if 'answer_is_yes'
        then
          BASHRC=$HOME/.bashrc
          make_changes_to_bashrc $HOME/.bashrc
        else
          echo "You will need to manually amend /etc/bashrc to run GEMPACK from within a Bourne Shell."
          echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
        fi
      else
        echo "You will need to manually amend /etc/bashrc to run GEMPACK from within a Bourne Shell."
        echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."     
      fi
    fi
  elif [ ! -f $HOME/.bashrc ]
  then
    echo "Would you like this script to make the required changes to $HOME/.bashrc file? [(n)o (q)uit] [y]"
    echo -n "> "
    if 'answer_is_yes'
    then
      BASHRC=$HOME/.bashrc
      make_changes_to_bashrc $HOME/.bashrc
    else
      echo "You will need to manually amend /etc/bashrc to run GEMPACK from within a Bourne Shell."
      echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
    fi
  elif [ -f $HOME/.bashrc -a -w $HOME/.bashrc ]
  then
    echo "Would you like this script to make the required changes to $HOME/.bashrc file? [(n)o (q)uit] [y]"
    echo -n "> "
    if 'answer_is_yes'
    then
      BASHRC=$HOME/.bashrc
      make_changes_to_bashrc $HOME/.bashrc
    else
      echo "You will need to manually amend /etc/bashrc to run GEMPACK from within a Bourne Shell."
      echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
    fi
  else
    echo "You will need to manually amend /etc/bashrc to run GEMPACK from within a Bourne Shell."    
    echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
  fi   

  if [ -f /etc/csh.cshrc -a -w /etc/csh.cshrc ]
  then
    echo "Would you like this script to make the required changes to your /etc/csh.cshrc file? [(n)o (q)uit] [y]"
    echo -n "> "
    if 'answer_is_yes'
    then
      CSHRC=/etc/csh.cshrc
      make_changes_to_cshrc /etc/csh.cshrc
    else
      if [ ! -f $HOME/.cshrc ]
      then
        echo "Would you like this script to make the required changes to $HOME/.cshrc file? [(n)o (q)uit] [y]"
        echo -n "> "
        if 'answer_is_yes'
        then
          CSHRC=$HOME/.cshrc
          make_changes_to_cshrc $HOME/.cshrc
        else
          echo "You will need to manually amend /etc/csh.cshrc to run GEMPACK from within a C Shell."
          echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
        fi
      elif [ -f $HOME/.cshrc -a -w $HOME/.cshrc ]
      then
        echo "Would you like this script to make the required changes to $HOME/.cshrc file? [(n)o (q)uit] [y]"
        echo -n "> "
        if 'answer_is_yes'
        then
          CSHRC=$HOME/.cshrc
          make_changes_to_cshrc $HOME/.cshrc
        else
          echo "You will need to manually amend /etc/csh.cshrc to run GEMPACK from within a C Shell."
          echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
        fi
      else
        echo "You will need to manually amend /etc/csh.cshrc to run GEMPACK from within a C Shell."
        echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
      fi
    fi  
  elif [ ! -f $HOME/.cshrc ]
  then
    echo "Would you like this script to make the required changes to $HOME/.cshrc file? [(n)o (q)uit] [y]"
    echo -n "> "
    if 'answer_is_yes'
    then
      CSHRC=$HOME/.cshrc
      make_changes_to_cshrc $HOME/.cshrc
    else
      echo "You will need to manually amend /etc/csh.cshrc to run GEMPACK from within a C Shell."
      echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
    fi
  elif [ -f $HOME/.cshrc -a -w $HOME/.cshrc ]
  then
    echo "Would you like this script to make the required changes to $HOME/.cshrc file? [(n)o (q)uit] [y]"
    echo -n "> "
    if 'answer_is_yes'
    then
      CSHRC=$HOME/.cshrc
      make_changes_to_cshrc $HOME/.cshrc
    else
      echo "You will need to manually amend /etc/csh.cshrc to run GEMPACK from within a C Shell."
      echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
    fi
  else
    echo "You will need to manually amend /etc/csh.cshrc to run GEMPACK from within a C Shell."
    echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
  fi         

  echo "Would you like to set permissions for your group? [(n)o (q)uit] [y]"
  echo -n "> "
  if 'answer_is_yes' 
  then
    set_permissions_for_group $installation_directory
  else
    echo "You will need to manually set GEMPACK permissions for your group."
    echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
  fi
  echo "Would you like to set permissions for other users? [(n)o (q)uit] [y]"
  echo -n "> "
  if 'answer_is_yes' 
  then
    set_permissions_for_others $installation_directory
  else
    echo "You will need to manually set GEMPACK permissions for other users."
    echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
  fi
  echo "Would you like this script to write an uninstall script? [(n)o (q)uit] [y]"
  echo -n "> "
  if 'answer_is_yes' 
  then
    write_uninstall_script $installation_directory $BASHRC $CSHRC
    echo "$PACKAGE_NAME-$PACKAGE_VERSION-$PACKAGE_RELEASE.uninstall.sh was written to $installation_directory."
  else
    echo "You will need to manually uninstall GEMPACK."
    echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
  fi
else
  echo "You need to copy gempackdm-1.0.1-8.tar.gz into your current directory $current_directory."
  echo "Please consult GEMPACK Document No. GPD-10 gpd10.pdf."
  abort
fi
echo
echo "GEMPACK-$PACKAGE_VERSION-$PACKAGE_RELEASE Demonstration-Version has been installed in $installation_directory."
echo 
echo "To utilise any changes made to /etc/bashrc, /etc/csh.cshrc, $HOME/.bashrc and $HOME/.cshrc and to use GEMPACK, you must login to a new shell session." 
echo "An update of the environment for GEMPACK takes place at login."
echo "Using an su command from an existing session will not invoke the login script and GEMPACK will not be available." 
echo


