#!/bin/csh 

echo "This release script must be run from the root directory"
echo "of the module.  So you would checkout a copy of it,"
echo "make changes, commit changes, then run this release script"  
sleep 1

if ( ! -d ./plot_read ) then 
   exit
endif

# check to see if there are any files that have not been committed.
set x=`cvs update | grep -v '^\?' | xargs`
if ( "$x" != "" ) then 
    echo "The following files need to be committed:"
    echo $x
    exit
endif



# PULL TAG # FROM VARIABLE "module" IN hydra_code_version.pro
set versiondb = "./plot_read/hydra_code_version.pro"
if ( ! -f $versiondb ) then
   echo "Can't find hydra_code_version.pro, are you in the root directory?"
   exit
endif
set vers = `./get_current_version module`



# UPDATE TAG # AT VARIABLE "module" IN hydra_code_version.pro
echo "Modifying $versiondb"
set new_vers = `echo "$vers + 0.01" | bc`

./set_current_version module $new_vers
cvs commit -m "updated version table" $versiondb
echo "New Version number is $new_vers.  "



# ENTER TAG # IN version_history.txt
echo "Please make a note of the changes in emacs."
emacs ./version_history.txt 
cvs commit -m "" ./version_history.txt



# DO A CVS TAG
set tt = `echo $new_vers | sed 's/\./_/'`    #DISK SPACE
set tt = v$tt
cvs tag $tt



# INSTALL this release to the INSTALL directory
echo "CHECKOUT TO INSTALL DIRECTORY"
set public_dir = /opt/hydra/papco/
cd $public_dir
mv polar_hydra polar_hydra.old
cvs checkout -r $tt -d polar_hydra papco_hydra_module
if ($status != 0) then
    echo "ERROR checking-out polar_hydra.  Re-instating prev release."
    rm -rf polar_hydra
    mv polar_hydra.old polar_hydra
    exit 10
else
    chmod 775 polar_hydra
    cd polar_hydra
    find . -type d | xargs chmod 775
    cd ..
#    rm -rf polar_hydra.old
endif
#echo "Compiling Papco..."
#cd 
#idl compile_papco
