#! /bin/csh
#  Install :: Build Skyview driver script
#
# Copyright (C) 1992,1993,1994,1996 California Institute of Technology.
# U.S. Government Sponsorship under NASA Contract NAS7-918
# is acknowledged.
#
#
#  Rick Ebert  <rick@ipac.caltech.edu> Thu Dec 22 10:54:02 PST 1994
#                                      Skyview Release 3.1
# (SunOS4.x, Solaris2.3, BSD4.3, Ultrix4.4) 
#
# modified by RBH 4-7-04 to add RGBFILE  (Skyview Release 3.5)
#
# minor changes made by RBH on 8-29-96 for Skyview Release 3.2.1
#
# modified by RBH 9-21-95 to add AGRADIR  (Skyview Release 3.2)
#   and to handle /stage in addition to /tmp_mnt
#   and to correct for csh treatment of $path inside double quotes
#
# SDIR is the directory that Skyview is being installed in
# normally it is the directory that contains this script
#setenv SDIR `pwd | sed -e "s/^\/tmp_mnt//"` 
setenv SDIR `pwd | sed -e "s/^\/tmp_mnt//" | sed -e "s/^\/stage//"` 
# 
# Tape device that will be accessed by s's internal tape commands (tr & tw)
# compiled in default: /dev/rmt12
#
setenv STAPE /dev/rmt12
#
# skyview script name ("skyview" :: what the user types to invoke skyview )
setenv SNAME skyview
#
# skyview executable's name, normally this is  "skyview.exe"
setenv SEXE skyview.exe
#
#SLOGIN=
# Path of directories to look for data files (fov and graphics overlay script)
# See SDATA below.
setenv SDATAPATH '.:${SDIR}/lib'
# Directory to look for agra font directory (grid command)
setenv AGRADIR '${SDIR}/lib'
# Default Postscript printer device accessible via lpr
setenv SPRINTER qms1
#
if ( -x /bin/uname ) then
   set mhtype=(`/bin/uname -m`)
   set uname=(/bin/uname)
else if ( -x /usr/bin/uname ) then
   set mhtype=(`/bin/uname -m`)
   set uname=(/usr/bin/uname)
else
   set mhtype=()
endif
#
if ( -x /bin/hostname ) then
 set hostname=(`/bin/hostname`)
else
 set host=(`$uname -n`)
 set dom=(`domainname`)
 set hostname=($host.$dom)
endif
set user=(`who am i`)
if ( $shell == "/bin/tcsh") then
    if ( $tcsh != "6.05.00") then
	set user=($user)
    endif
else
    set user=($user)
endif
if ( "${user}" != "" ) then
  set user=($user[1])
  if ( ${user} =~ *\!* ) then
     set user=(`echo $user | sed -e 's/\(.*\)!\(.*\)/\2/'`)
  endif
## echo $user
endif

#	if ( "$mhtype" == "" || $mhtype !~ sun4? ) then
#	  echo "This doesn't appear to be a Sun4"  ;
#	  echo "The Skyview release has only been tested on Sun4's."  ;
#	  echo "You've been told.  Now we'll continue." ;
#	endif

	echo "Installing Skyview  ..."
	echo " "
	echo "The Skyview Directory is the full pathname of the"
	echo " subdirectory containing the Skyview distribution,"
	echo " which should be the current directory."
	echo " <cr> accepts the [default]"
	echo " "
	echo -n "Skyview Directory [${SDIR}]: "
	setenv ANSWER $<
#	echo ${ANSWER}
#
# Executables

	if ( "${ANSWER}" == "") then
	   setenv ANSWER ${SDIR}
	else if ("${ANSWER}" == "." ) then
	   setenv ANSWER ${SDIR}
	else
	 setenv SDIR ${ANSWER}
	endif
	echo " "
#	echo sdir is ${SDIR}

        if ( ! -d ${SDIR}/bin ) then
	   echo "Something's wrong: ${SDIR} doesn't contain  bin" ;
	   exit 1
        endif

	echo "#! /bin/csh -f" > ${SDIR}/bin/${SNAME}
	echo '#' >> ${SDIR}/bin/${SNAME}
	echo '# This script built by Install for Skyview Release 3.5' \
					       >> ${SDIR}/bin/${SNAME}
	echo -n '# on ' >> ${SDIR}/bin/${SNAME}
	date >> ${SDIR}/bin/${SNAME}
	echo -n '# by ' >> ${SDIR}/bin/${SNAME}
        echo $user@$hostname >> ${SDIR}/bin/${SNAME}
	echo '#' >> ${SDIR}/bin/${SNAME}

        echo "In order to use some of the accompanying programs"
	echo " outside of the skyview program, e.g. contour and contourtek,"
	echo " you must set the SDIR environment variable with a"
	echo " command like"
	echo "setenv SDIR ${SDIR}"
	echo

	echo setenv SDIR ${SDIR} >> ${SDIR}/bin/${SNAME}

	echo "That means the  bin subdirectory is probably"
	echo "${SDIR}/bin"
	echo " "
	echo "That directory must be added to your shell's PATH."
	echo " "
	echo "If this is a system-wide installation and you want skyview"
	echo "to look for the executables in directories other than"
	echo "the default path you may add them here.  Skyview will pre-pend"
	echo "these directories to the existing path.  For most"
	echo "installations this should be left empty (take the default)."
	echo " "
	echo "Separate multiple paths with space."
	echo " "
	echo -n "S path []: "
	setenv ANSWER $<
	if ( "${ANSWER}" != "" ) then
            echo "set path=(${ANSWER}" \$path")" >> ${SDIR}/bin/${SNAME} ;
	else
            echo "set path = (${SDIR}/bin" \$path")" >> ${SDIR}/bin/${SNAME} ;
	endif
	echo " "
#
# Manpages
	echo "The man subdirectory is probably"
	echo "${SDIR}/man"
	echo -n "Skyview Manual Pages [${SDIR}/man]: "
	setenv ANSWER $<
	if ( "${ANSWER}" == "" ) setenv ANSWER '${SDIR}/man'
	echo 'if ( $?SMAN == 0 ) ' "setenv SMAN ${ANSWER}" \
						 >> ${SDIR}/bin/${SNAME}

        echo "If you want access to the Skyview on-line manual pages"
	echo "outside of skyview, add this directory to your MANPATH"
	echo "shell variable with a command like (for c-shell)"
	echo " "
	echo 'setenv MANPATH ${SDIR}/man:$MANPATH'
	echo " "
	echo "We recommend that you DO NOT do this. Since some Skyview"
	echo "command names conflict with UNIX command names (e.g. ls)."
	echo "This would make the UNIX manpages inaccessible."
	echo -n "<cr> to continue..."
	setenv ANSWER $<
	echo " "
#
# Help files
#       echo "S also has a set of on-line help files."
#	echo -n "S Help-file directory [${SDIR}/help]: "
#	setenv ANSWER $<
#	if ( "${ANSWER}" == "" ) setenv ANSWER '${SDIR}/help'
#	echo 'if ( $?SHELP == 0 ) ' "setenv SHELP ${ANSWER}" \
#					       >> ${SDIR}/bin/${SNAME}
#        echo "If you want access to the S help files via the s.help"
#	echo "command (outside of s), set SHELP environment variable"
#	echo "to this directory with a command like"
#	echo " "
#	echo "setenv SHELP ${SDIR}/help"
#	echo " "
#	echo -n "<cr> to continue..."
#	setenv ANSWER  $<
#	echo " "
#
# Data files search path
	echo "The Data Path is the list of directories that skyview will"
	echo "search, in order, looking for data files required by"
	echo "some internal functions (currently only  fov )."
	echo "This is a Path-type variable so directory names should be"
	echo "separated by colons (:)"
	echo -n "Skyview Data path [${SDATAPATH}]: "
	setenv ANSWER $<
	if ( "${ANSWER}" == "" ) setenv ANSWER "${SDATAPATH}"
	echo 'if ( $?SDATA == 0) ' "setenv SDATA $ANSWER" \
                                        	>> ${SDIR}/bin/${SNAME}
	echo " "
	echo -n "<cr> to continue..."
	setenv ANSWER $<
	echo " "
#
# Agra font location
	echo "The Agra Dir is the directory where skyview will"
	echo "look for the font directory to be used by Agra."
	echo -n "Agra Directory [${AGRADIR}]: "
	setenv ANSWER $<
	if ( "${ANSWER}" == "" ) setenv ANSWER "${AGRADIR}"
	echo 'if ( $?AGRADIR == 0) ' "setenv AGRADIR $ANSWER" \
                                        	>> ${SDIR}/bin/${SNAME}
	echo " "
	echo -n "<cr> to continue..."
	setenv ANSWER $<
	echo " "
#
# Postscript printer Device
	echo "The Printer Name is the name of the postscript printer"
	echo "that skyview will use.  If your computer system has no"
	echo "postscript printer available respond with  -nops-  including"
	echo "the dashes.  Be prepared for error messages from"
        echo "commands that try to print."
	echo " "
	echo -n "Printer Name [${SPRINTER}]: "
	setenv ANSWER $<
	if ( "${ANSWER}" == "" ) setenv ANSWER ${SPRINTER}
	if ( "${ANSWER}" != "-nops-" ) then
	   echo 'if ( $?SPRINTER == 0 ) ' "setenv SPRINTER ${ANSWER}" \
						>> ${SDIR}/bin/${SNAME} ;
        endif

# Location of X Windows file rgb.txt
	if (-e /usr/openwin/lib/rgb.txt ) then
	   echo 'if ( $?RGBFILE == 0 ) ' "setenv RGBFILE /usr/openwin/lib" \
						>> ${SDIR}/bin/${SNAME} ;
        endif
	if (-e /usr/openwin/lib/X11/rgb.txt ) then
	   echo 'if ( $?RGBFILE == 0 ) ' "setenv RGBFILE /usr/openwin/lib/X11" \
						>> ${SDIR}/bin/${SNAME} ;
        endif
	if (-e /usr/X11R6/share/X11/rgb.txt ) then
	   echo 'if ( $?RGBFILE == 0 ) ' "setenv RGBFILE /usr/X11R6/share/X11" \
						>> ${SDIR}/bin/${SNAME} ;
        endif
	if (-e /usr/X11R6/lib/X11/rgb.txt ) then
	   echo 'if ( $?RGBFILE == 0 ) ' "setenv RGBFILE /usr/X11R6/lib/X11" \
						>> ${SDIR}/bin/${SNAME} ;
        endif
	if (-e /usr/share/X11/rgb.txt ) then
	   echo 'if ( $?RGBFILE == 0 ) ' "setenv RGBFILE /usr/share/X11" \
						>> ${SDIR}/bin/${SNAME} ;
        endif


	echo exec ${SEXE} '$*' >> ${SDIR}/bin/${SNAME}
	chmod 755 ${SDIR}/bin/${SNAME}
	echo " "

	echo "Installation is complete."
	echo "If you have any comments or suggestions regarding the"
	echo "installation software or about Skyview send mail to:"
	echo " "
	echo "     skyview-help@ipac.caltech.edu"
	echo " "
