#!/bin/csh -f
#
# zlister.install.csh         Author:   Joe Wulf - 20070718@17:54, MD.
#                             v1.7a     Copyright (C) 1997-2007, Joe Wulf
#
# Simple, automated script to install zlister
# Presumes the current working directory is the directory where the zlister scripts reside.
if ( ! -e zlisterProduction-1.7a.tar.gz ) then
     echo "Exiting, as the zlisterProduction-1.7a.tar.gz file isn't in the current directory."
     exit 1
else
     echo "Installing zlister v.1.7a Filesystem Integrity Tool at /sysadmin/zlister.bin"
     echo "Read /sysadmin/zlister.bin/zlister for additional instruction and information."
endif


mkdir /sysadmin
# Protected alternate full copy
cp -p zlisterProduction-1.7a.tar.gz /root
# Prime location
cp -p zlisterProduction-1.7a.tar.gz /sysadmin

cd /sysadmin
gunzip  zlisterProduction-1.7a.tar.gz
tar xf  zlisterProduction-1.7a.tar
gzip -9 zlisterProduction-1.7a.tar

touch Output_Today
chown 0:0  Output_Today
chmod 0600 Output_Today

echo ""
if ( -e /usr/local/bin ) then
     echo "Linking sagrep into the search path (of /usr/local/bin)"
     ln -s /sysadmin/zlister.bin/sagrep /usr/local/bin/sagrep
else
     if ( -e /usr/bin ) then
          echo "Linking sagrep into the search path for solaris (/usr/bin)"
          ln -s /sysadmin/zlister.bin/sagrep /usr/bin/sagrep
     else
          echo "Error"
          echo "Error: A standard location where sagrep can be in the path does not exist."
          echo "Error: Therefore, sagrep must be manually executed from /sysadmin/zlister.bin"
          echo "Error"
     endif
endif

echo ""
# Just in case no crontab exists for root, pipe out the errors as well.
set x = `crontab -l |& grep zlister | wc -l`
if ( $x == 0 ) then
     echo "Adding standard execution entry into roots crontab for daily at 2am"
     setenv EDITOR ed
     crontab -e <<END >/dev/null
a
01 02 * * * /bin/mv  /sysadmin/Output_Today   /sysadmin/Output_Yesterday
02 02 * * * /sysadmin/zlister.bin/zlister  >  /sysadmin/Output_Today  2>&1
.
p
w
q
END
else
     echo "The crontab for root already has zlister included."
endif
echo ""
crontab -l

mkdir -p /sysadmin/zhostlists/`hostname | cut -d"." -f1`

echo ""
echo "********************************************************************"
echo "***  Manual execution is accomplished with the following line:   ***"
echo "***  /sysadmin/zlister.bin/zlister                               ***"
echo "***                                                              ***"
echo "***  File system entries are found with:                         ***"
echo "***  sagrep <pattern to search for>                              ***"
echo "***                                                              ***"
echo "********************************************************************"
echo " zlister v.1.7a, Filesystem Integrity Tool, Successfully Installed."
exit 
