
#
#    Borne shell install script for FORTRAN-lint
#

PATH=/bin:/usr/bin

echo ""
echo ""
echo "              FORTRAN-lint Installation Script"
echo ""
echo "     Before attempting installation of FORTRAN-lint, you should"
echo "     have decided where FORTRAN-lint's support files are to be "
echo "     installed. System privileges may be necessary to install the"
echo "     man page and the executable."
echo ""

supp_install_dir="/usr/local/flint" ;export supp_install_dir
exe_install_dir="/usr/bin"; export exe_install_dir
man_install_dir="/usr/man/man1"; export man_install_dir
curr_dir=`pwd`; export curr_dir
daemon_hostname=`uname -n`; export hostname
export ans

#
# get support file installation directory
#
echo ""
echo  "     Installation directory (default: $supp_install_dir)? "

read ans
if test -n "$ans"
then
   supp_install_dir=$ans
fi

if test -d $supp_install_dir 
then
    if test ! -w $supp_install_dir 
    then
       echo ""
       echo "     You do not have write privileges to $supp_install_dir"
       echo "     Installation Aborted."
       
       echo ""
       echo "     This script has aborted, no installation was performed."
       echo "     It is likely that you do not have the proper privileges"
       echo "     to the installation directories or one of the directory"
       echo "     names was misspelled."
       exit
    fi 
elif test -d `dirname $supp_install_dir`
then
    if test ! -w  `dirname $supp_install_dir` 
    then
       echo ""
       echo "     You do not have write privileges to `dirname $supp_install_dir`"
       echo "     Installation Aborted."
       
       echo ""
       echo "     This script has aborted, no installation was performed."
       echo "     It is likely that you do not have the proper privileges"
       echo "     to the installation directories or one of the directory"
       echo "     names was misspelled."
       exit
     else
       cd `dirname $supp_install_dir`
       mkdir `basename $supp_install_dir`
       chmod ugo+rx `basename $supp_install_dir`
       cd $curr_dir 
     fi
else
     echo ""
     echo "     Invalid directory specification"
     
     echo ""
     echo "     This script has aborted, no installation was performed."
     echo "     It is likely that you do not have the proper privileges"
     echo "     to the installation directories or one of the directory"
     echo "     names was misspelled."
     exit
fi

#
# get directory executable will go in
#


echo ""  
echo "     Directory for executable (default: $exe_install_dir)? "

read ans
if test -n "$ans"
then
    exe_install_dir=$ans
fi

if test ! -d $exe_install_dir 
then
   echo "" 
   echo "     directory $exe_install_dir does not exist."
   echo "     executable not copied"
   
   echo ""
   echo "     This script has aborted, no installation was performed."
   echo "     It is likely that you do not have the proper privileges"
   echo "     to the installation directories or one of the directory"
   echo "     names was misspelled."
   exit
elif test ! -w $exe_install_dir 
then 
   echo ""
   echo "     You do not have write privileges to $exe_install_dir"
   echo "     executable not copied"
   
   echo ""
   echo "     This script has aborted, no installation was performed."
   echo "     It is likely that you do not have the proper privileges"
   echo "     to the installation directories or one of the directory"
   echo "     names was misspelled."
   exit
fi

#
# get host that daemon will be run on
#
echo ""  
echo "     Host for license daemon (default: $daemon_hostname)? "

read ans
if test -n "$ans" 
then
    daemon_hostname=$ans
fi

#
# check and get correct executable for type of sun system
#
    cp flint $exe_install_dir/flint
    cp xlint $exe_install_dir/xlint 
    cp iptlma $supp_install_dir/iptlma
    cp iptlmd $supp_install_dir/iptlmd
    cp iptlmr $supp_install_dir/iptlmr
    cp flpatch $supp_install_dir/flpatch
    chmod a+x $exe_install_dir/flint $exe_install_dir/xlint 
    chmod a+x $supp_install_dir/ipt* $supp_install_dir/flpatch

echo ""
echo "     Patching support file directory name in executable"
echo ""
$supp_install_dir/flpatch $exe_install_dir/flint home $supp_install_dir
$supp_install_dir/flpatch $exe_install_dir/xlint home $supp_install_dir

if test  $daemon_hostname!="" 
then
   echo ""
   echo "     Patching daemon host name name in executable"
   echo ""
   $supp_install_dir/flpatch $exe_install_dir/flint host $daemon_hostname
   $supp_install_dir/flpatch $exe_install_dir/xlint host $daemon_hostname
fi

echo ""
echo "     Copying FORTRAN-lint support files to $supp_install_dir"
cp flint.* XLint *.lsh *.lbt  $supp_install_dir
cp -rip Doc $supp_install_dir
cp -rip Examples $supp_install_dir
echo "     Copy Done."


echo ""
echo "     Installation directory for man page(Default: $man_install_dir)? "

read ans
if test -n "$ans"
then
   man_install_dir=$ans
fi

if test  ! -d $man_install_dir 
then
   echo ""
   echo "     directory $man_install_dir does not exist."
   echo "     man page copied instead to $supp_install_dir."
   cp flint.1 $supp_install_dir
elif test ! -w $man_install_dir 
then 
   echo ""
   echo "     You do not have write privileges to $man_install_dir"
   echo "     man page copied instead to $supp_install_dir."
   cp flint.1 $supp_install_dir
else
   cp flint.1 $man_install_dir
fi

echo ""
echo "     Installation is now complete. "

if test $supp_install_dir != $curr_dir 
then
    echo  "Do you wish to delete FORTRAN-lint files in $curr_dir (Y/N)? "
    echo  ""
    read ans
    if test $ans = "Y" -o $ans = "y"
     then
       rm -f flint*
       rm -f install_flint
       rm -f ipt*
       rm -f flpatch 
       rm -f unixlib.lbt
       rm -f unixlib.lsh
       rm -f vmslib.lbt
       rm -f vmslib.lsh
       rm -rf Doc 
       rm -rf Examples 
    fi 
fi
echo ""
exit
