#!/bin/csh

if ( ${?ROSERT_HOME} == 0 ) then
echo "Set ROSERT_HOME variable first and then run this script"
exit 1
endif

foreach file ($path) 
if ( -f $file/gzip ) then
setenv GZIP_FOUND 1
endif
if ( -f $file/tar ) then
setenv TAR_FOUND 1
endif
end

if ( (${?GZIP_FOUND} == 0) ) then
echo "gzip not in path, make sure gzip is in path and rerun this script"
exit 1
endif

if ( (${?TAR_FOUND} == 0) ) then
echo "tar not in path, make sure tar is in path and rerun this script"
exit 1
endif

setenv CURRNT_DIR_TEMP `pwd`

cd $ROSERT_HOME
if ($status ) then
echo "cannot change directory to $ROSERT_HOME, set the proper permissions for $ROSERT_HOME and rerun this sctipt."
exit 1
endif 

if ( -f $CURRNT_DIR_TEMP/SR4.sun5.1415.tar.gz ) then
echo "Unzipping $CURRNT_DIR_TEMP/SR4.sun5.1415.tar.gz, please wait...." 
gzip -d  $CURRNT_DIR_TEMP/SR4.sun5.1415.tar.gz 
if ($status ) then
echo "gzip -d $CURRNT_DIR_TEMP/SR4.sun5.1415.tar.gz failed, run gunzip  $CURRNT_DIR_TEMP/SR4.sun5.1415.tar.gz \
      manually and rerun this script."
exit 1
endif
else 
if ( ! (-f $CURRNT_DIR_TEMP/SR4.sun5.1415.tar) ) then
echo "RoseRT SR4 Install patch not found in $CURRNT_DIR_TEMP, copy the file SR4.sun5.1415.tar.gz and rerun the script."
exit 1
endif
endif 

tar  xvf $CURRNT_DIR_TEMP/SR4.sun5.1415.tar
if ($status ) then
echo "untar not succesfull, installation failed."
exit 1
endif 

echo
echo
echo
echo
echo

if ( -f $ROSERT_HOME/bin/sun5/summit/libtl.so ) then
echo "Moving $ROSERT_HOME/bin/sun5/summit/libtl.so to $ROSERT_HOME/bin/sun5/summit/libtl.so.bak as \
      $ROSERT_HOME/bin/sun5/summit/libtl.so is not required for this release."
mv -f $ROSERT_HOME/bin/sun5/summit/libtl.so $ROSERT_HOME/bin/sun5/summit/libtl.so.bak
if ( $status ) then
echo "Move failed, manually rename or remove the file $ROSERT_HOME/bin/sun5/summit/libtl.so"
endif 
endif

if ( -f $ROSERT_HOME/bin/sun5/summit/tl.rsb ) then
echo "Moving $ROSERT_HOME/bin/sun5/summit/tl.rsb to $ROSERT_HOME/bin/sun5/summit/tl.rsb.bak as \
      $ROSERT_HOME/bin/sun5/summit/tl.rsb is not required for this release."
mv -f $ROSERT_HOME/bin/sun5/summit/tl.rsb $ROSERT_HOME/bin/sun5/summit/tl.rsb.bak
if ( $status  ) then
echo "Move failed, manually rename or remove the file $ROSERT_HOME/bin/sun5/summit/tl.rsb"
endif 
endif

cd $CURRNT_DIR_TEMP
unsetenv CURRNT_DIR_TEMP
echo
echo "RoseRT SR4 patch installation successful"
echo
