#!/bin/csh -f
#
# Precheck procedure for SunOs (5.9 and 5.10 )
#
set pr1="--------------------------------------------------------------------------------"
set pr2="================================================================================"
set pr3="------------------------------------------- EOF --------------------------------"

if ( -f precheck.ini ) then 
    source ./precheck.ini
endif
if ( -f param_csh.ini ) then 
    source ./param_csh.ini
endif
alias straight 'printf "%-60s %s" \!*'
alias straightln 'printf "%-60s %s\n" \!*'

rm $log >& /dev/null
touch $log
echo "" >> $log
echo "Pre Installation Check Engine." >> $log 
echo "The additional log file: ./log/pre_checks_info_file.log " >> $log
echo "------------------------------------------------" >> $log
################################################################################
#open info log file.
rm $info >& /dev/null
touch $info
echo $pr2 >> $info
echo "Pre-installation checks INFO file.">> $info
echo $pr1 >> $info
echo "" >> $info
echo "Operating system  --->  SunOs" >> $info
echo "Server name ---> `uname -n`" >> $info
echo "Operation system ---> `uname` `uname -r`" >> $info

################################################################################
echo $pr2 >> $info
#/etc/hosts
echo "Hosts table." >> $info 
cat /etc/hosts >> $info
echo "">> $info
################################################################################
bash -f serverinfo.sh | tee -a $log
csh -f precheck_net.csh | tee -a $log
################################################################################
#memory size  
echo "Memory size." >> $info
/usr/sbin/prtconf |grep size >> $info
set memory_size = `/usr/sbin/prtconf |grep size | awk '{print $3}'`
if ( "$memory_size" <  "$MEMORY_SIZE_MIN" ) then
                  straightln "Checking the memory size." "[FAULT]" >> $log
else
                  straightln "Checking the memory size." "[OK]" >> $log
endif
echo $pr2 >> $info
################################################################################
echo "Swap size." >> $info
/usr/sbin/swap -s  >> $info
#swap size
set swap_size = `/usr/sbin/swap -s | awk '{print $11}' | sed 's/k//' `
if ( "$swap_size" < "$SWAP_SIZE_MIN" ) then
                  straightln "Checking the swap size." "[FAULT]" >> $log
else
                  straightln "Checking the swap size." "[OK]" >> $log
endif
echo $pr2 >> $info
################################################################################
#/exlibris directory existing + size
echo "" >> $info
echo "Disk size." >> $info
df -k >> $info
echo "" >> $info

df -k /exlibris >& /dev/null
if ("$status" != "0" ) then
           straightln  "Checking whether /exlibris directory does exist." "[FAULT]" >> $log
else 
       	   straightln  "Checking whether /exlibris directory does exist." "[OK]" >> $log
endif
echo $pr2 >> $info
################################################################################
set exlibris_size = ` df -k /exlibris | awk '{print $4}' `
if ( "$exlibris_size[2]" < "$EXLIBRIS_SIZE_MIN" ) then
           straightln "Checking the /exlibris directory size." "[WARNING]" >> $log
else
           straightln "Checking the /exlibris directory size." "[OK]" >> $log
endif 	   
################################################################################
#check /tmp directory exist + size
echo "/tmp directory." >> $info
if (! -d /tmp ) then 
           straightln "Checking whether /tmp directory  exists." "[FAULT]" >>$log
	   echo "The /tmp directory does not exist." >> $info
else
           straightln "Checking whether /tmp directory exists." "[OK]"  >> $log 
	   ls -l / | grep tmp >> $info	
endif	      
echo $pr2 >> $info
################################################################################
set tmp_size = ` df -k /tmp | awk '{print $4}' `
if ("$tmp_size[2]" < "$TMP_SIZE_MIN" ) then
           straightln "Checking the /tmp directory size." "[FAULT]" >> $log
else 
           straightln "Checking the /tmp directory size." "[OK]" >> $log
endif	   	      

################################################################################
#check ORACLE_VERSION dir exist
echo "" >> $info
if ( -d /exlibris/app/oracle/product/${ORACLE_VER} ) then
         echo "The /exlibris/app/oracle/product/${ORACLE_VER} directory exists. " >> $info  
         echo "">> $info
else
         echo "The /exlibris/app/oracle/product/${ORACLE_VER} directory does not exist. " >> $info
endif
################################################################################
#users metalib oracle in the server.
echo "" >> $info
echo "Exlibris users information." >> $info
echo $pr1 >> $info
echo "Users:" >> $info
echo "" >> $info
grep metalib: /etc/passwd >> $info
grep aleph: /etc/passwd >> $info
grep dtl: /etc/passwd >> $info
grep dps: /etc/passwd >> $info
grep primo: /etc/passwd >> $info
grep oracle /etc/passwd >> $info
grep verde /etc/passwd >> $info
grep crn /etc/passwd >> $info
echo $pr1 >> $info
echo "Groups:" >> $info
echo "">> $info
grep "^dba:" /etc/group >> $info
grep "^exlibris:" /etc/group >> $info
echo $pr2 >> $info
################################################################################
#check gzip,su,tar,compress,sftp
set comlist = "gzip su tar compress sftp make ar ld nm"
foreach arg ( $comlist )
   foreach i ( $path )
      if ( -x $i/$arg && ! -d $i/$arg ) then
         set found
         break
      endif
   end
   if ( ! $?found  ) then
       straightln "Checking whether ${arg} exists in the path." "[FAULT]" >> $log
       echo "The ${arg} does not exist in the path." >> $info
   else
       straightln "Checking whether ${arg} exists in the path." "[OK]" >> $log
       echo "The ${arg} exists in the path." >> $info
   endif
end
echo $pr2 >> $info
###############################################################################
#check whether /dev/random exist.
if  ( ! -e  /dev/random ) then
  echo "The /dev/random link does not exist." >> $info
  echo "Install patch from:" >> $info 
  echo "http://sunsolve.sun.com/pub-cgi/findPatch.pl?patchId=112438&rev=01" >> $info
  straightln "Checking whether /dev/random package exists." "[FAULT]" >> $log
else
  echo "The /dev/random link exists." >> $info
  straightln "Checking whether /dev/random package exists." "[OK]" >> $log
endif
echo $pr2 >> $info
###############################################################################
#checking server architecture
set patch_level = `grep -s Solaris /etc/release | grep 's10._u.w' | sed 's/^.*s10._u\([0-9]*\).*/\1/'`
if ( "$patch_level" > "5" ) then
     straightln "Checking whether the OS update is greater then 5" "[OK]" >> $log
     echo "The OS update is greater then 5" >> $info
else
     straightln "Checking whether the OS update is greater then 5" "[FAULT]" >> $log
     echo "The OS update is lower then 6" >> $info
endif
################################################################################
#check SUNWarc,SUNWbtool,SUNWhea,SUNWlibm,SUNWlibms,SUNWsprot,SUNWtoo.
uname -a | grep 5.10 >& /dev/null
if ( "$status" != "0" ) then
   set pkglist = "SUNWtcsh SUNWarc SUNWbtool SUNWhea SUNWlibm SUNWlibms SUNWsprot SUNWtoo SUNWmfrun SUNWsprox SUNWxwfnt SUNWi1of SPROsunms SPROcc"
else
   set pkglist = "SUNWtcsh SUNWarc SUNWbtool SUNWhea SUNWlibm SUNWlibms SUNWsprot SUNWtoo SUNWmfrun SUNWxwfnt SUNWi1of SPROsunms SPROcc SUNWgcc SUNWbinutils SUNWgccruntime"
endif
/usr/bin/pkginfo > ./tmp/tmp_a
echo "Package cc on the pkginfo" >> $info
echo $pr1 >> $info
foreach i ( $pkglist ) 
  grep $i ./tmp/tmp_a >& /dev/null 
  if ( "$status" != "0" ) then
     straightln "Checking whether ${i} exists in the system." "[FAULT]" >> $log
     echo "The ${i} does not exist in the system." >> $info
  else
     straightln "Checking whether ${i} exists in the system." "[OK]" >> $log
     echo "The ${i} exists in in the system." >> $info
  endif
end
set pkglist = "SUNWi1cs SUNWi15cs"
foreach i ( $pkglist ) 
  grep $i ./tmp/tmp_a >& /dev/null 
  if ( "$status" != "0" ) then
     straightln "Checking whether ${i} exists in the system." "[WARNING]" >> $log
     echo "The ${i} does not exist in the system." >> $info
  else
     straightln "Checking whether ${i} exists in the system" "[OK]" >> $log
     echo "The ${i} exists in in the system." >> $info
  endif
end

###############################################################################
#check cc compiler
set c_compiler_path = "null";
if ( -e /opt/sunstudio12.1/prod/bin/cc && -f  /opt/sunstudio12.1/prod/lib/crti.o ) then
 set c_compiler_path = "/opt/sunstudio12.1/prod/bin"
endif
if ( -e /usr/local/SUNWspro/bin/cc && -f /usr/local/SUNWspro/lib/crti.o ) then
 set c_compiler_path = "/opt/SUNWspro/bin"
endif
if ( -e /opt/SUNWspro/bin/cc && -f /opt/SUNWspro/lib/crti.o ) then
 set c_compiler_path = "/opt/SUNWspro/bin"
endif
if ( -e /opt/SUNWspro/SC4.2/bin/cc && -f /opt/SUNWspro/SC4.2/lib/crti.o ) then
 set c_compiler_path = "/opt/SUNWspro/SC4.2/bin"
endif
if ( -e /opt/SUNWspro/WS6U1/bin/cc && -f /opt/SUNWspro/WS6U1/lib/crti.o ) then
 set c_compiler_path = "/opt/SUNWspro/WS6U1/bin"
endif
if ( -e /opt/SUNWspro/WS6U2/bin/cc && -f /opt/SUNWspro/WS6U2/lib/crti.o ) then
 set c_compiler_path = "/opt/SUNWspro/WS6U2/bin"
endif
if ( -e /opt/SUNWspro/SC5.0/bin/cc && -f /opt/SUNWspro/SC5.0/lib/crti.o ) then
 set c_compiler_path = "/opt/SUNWspro/SC5.0/bin"
endif
if ( -e /opt/SUNWspro/prod/bin/cc && -f  /opt/SUNWspro/prod/lib/crti.o ) then
 set c_compiler_path = "/opt/SUNWspro/prod/bin"
endif

if ( "$c_compiler_path" == "null" ) then
     straightln "Checking if the cc compiler exist in the standart place." "[FAULT]" >> $log
     echo "The system cc compiler does not exist in the standart place." >> $info
else
     straightln "Checking if the cc compiler exist in the standart place." "[OK]" >> $log
     echo "The cc compiler path is ${c_compiler_path}" >> $info
endif
###############################################################################
#checking the Native-C compiler.
if ( "$c_compiler_path" != "null" ) then
  echo "Checking Native-C compiler." >> $info
  echo "cc check_c.c" >> $info
  ${c_compiler_path}/cc check_c.c -s -o check_c >>& $info
  if ( -f check_c ) then
     chmod +x check_c
     ./check_c >> $info
     straightln "Checking the Native-C compiler." "[OK]" >> $log
  else 
    echo "The check_c object was not created." >> $info 
    straightln "Checking the Native-C compiler." "[FAULT]" >> $log
  endif
endif
###############################################################################
echo $pr2 >> $info
echo "" >> $info
echo "" >> $info
echo "               RESULTS" >> $info
echo $pr1 >> $info
echo "" >> $info
cat $log >> $info
echo "" >> $info
echo $pr3 >> $info
################################EOF#############################################
