#!/bin/csh
#
# lostfile - script to allow users to request file restoration from backups
# 	     in a consistent manner.  The user simply types 'lostfile' and 
#	     they are prompted for all of the necessary information.
#

onintr quit
set noglob
# login name or mail alias of whoever is responsible for 
# retrieving lost files
set mailto = operator

set filename = not_null
set count = 1
echo ""
echo -n "Enter the login name of the owner of the lost files: "
set login = $<
echo "Lost files owned by ${login}"  >>  /tmp/lostxfer$$
echo ""  >>  /tmp/lostxfer$$
echo ""
echo -n "Were all of the files in the same directory? "
set dirsame = $<
echo ""
echo "Enter the names of lost files, one at a time;"
echo "A <CR> with no name ends the querys."
echo ""

while ( ${filename} != "" )
   echo -n "Enter the name of lost file ${count}: " 
   set filename = $<
   if  ( ${filename} != "" )  then
      echo "Filename: ${filename}"  >>  /tmp/lostxfer$$
      echo -n "Enter the last modification date of ${filename}: "
      set modtime = $<
      echo "Modtime: ${modtime}"  >>  /tmp/lostxfer$$
      if  ( ( ${dirsame} == "no" )  ||  ( ${dirsame} == "n" ) )  then
         echo -n "Give the full pathname of the"
	 echo -n " directory containing ${filename}: "
         set dirname = $<
         echo "Directory: ${dirname}"  >>  /tmp/lostxfer$$
      endif
      echo -n "Was ${filename} a directory? "
      set dir = $<
      if  ( ( ${dir} == "yes" )  ||  ( ${dir} == "y" ) )  then
         echo -n "File was a directory; "  >>  /tmp/lostxfer$$
         echo -n "Do you want subdirectories of ${filename}? "
         set subdirs = $<
         if  ( ( ${subdirs} == "yes" )  ||  ( ${subdirs} == "y" ) )  then
            echo "entire contents wanted."  >>  /tmp/lostxfer$$
         else
            echo "only the regular files wanted."  >>  /tmp/lostxfer$$
         endif
      endif
      echo ""
      echo ""  >>  /tmp/lostxfer$$
   endif
   @ count++
end

if  ( ( ${dirsame} == "yes" )  ||  ( ${dirsame} == "y" ) )  then
   echo ""
   echo -n "Give the full pathname of the directory that the files were in: "
   set dirname = $<
   echo "All files were in the directory: ${dirname}"  >>  /tmp/lostxfer$$
endif
echo ""
echo "You will be contacted by mail if further information is needed,"
echo "and you will be notified when the files have been retrieved."
echo "Your files should be recovered to the best of our ability within" 
echo "a day or two.  Please 'mail ${mailto}' if you have questions or"
echo "problems concerning lost files.  Thank You."
echo ""

unalias mail
mail -s "Lost file report for $login" ${mailto}  <  /tmp/lostxfer$$

unalias rm
rm -f /tmp/lostxfer$$
exit

quit:
   echo "Interrupt received, lost aborted"
   unalias rm
   unset noglob
   rm -f /tmp/lostxfer$$
