#!/bin/csh -f
#
# Precheck procedure for AIX 5.3
#
if (-f param_const.dat) then
	source param_const.dat
endif
if (-f param_main.dat) then
	source param_main.dat
endif
if (-f precheck.ini) then
	source precheck.ini
endif

alias straight 'printf "%-60s %s" \!*'
alias straightln 'printf "%-60s %s\n" \!*'

set pr1="--------------------------------------------------------------------------------"
set pr2="================================================================================"
set pr3="------------------------------------------- EOF --------------------------------"

rm $log >& /dev/null
touch $log
echo "" | tee -a $log
echo "Pre  Installation Check  Engine." | tee -a  $log 
echo "The additional log file  - ./pre_checks_info_file.log " | tee -a $log
echo "------------------------------------------------" | tee -a $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  --->  AIX" >> $info
echo "Server name ---> `uname -n`" >> $info
echo "Operation system ---> `uname` `uname -r`" >> $info
csh -f precheck_net.csh | tee -a $log
set OSVER=`uname -v`
set OSREV=`uname -r`
if ($OSVER == 5 && $OSREV == 3) then
           straightln "Checking OS version"  "[OK]" | tee -a $log
else
           straightln "Checking OS version" "[FAULT]" | tee -a $log
endif
straight         "Checking OS revision" | tee -a $log
set oslevel=`oslevel -r | cut -d- -f2`
straight "OS Level -->  " >> $info
oslevel -r >> $info
if ($oslevel < 5) then
    echo                             "[FAULT]" | tee -a $log
else
    echo                             "[OK]"| tee -a $log
endif
straight "Checking required packages" | tee -a $log | tee -a $info
lslpp -l bos.adt.base bos.adt.lib bos.adt.libm bos.perf.perfstat \
bos.perf.libperfstat bos.perf.proctools >>& $info
if ($status) then

	echo                         "[FAULT]" | tee -a $log
else
	echo                         "[OK]" | tee -a $log
endif

rpm -qa > tmp/tmp_a
foreach rpm (bash tcsh gcc)
        straight  "Checking rpm package $rpm" | tee -a $log
	(grep $rpm tmp/tmp_a >>  $info && echo "[OK]" || echo "[FAULT]") | tee -a $log
end
straight "Checking required OS patches" | tee -a $log | tee -a $info
/usr/sbin/instfix -i -k "IY59386 IY60930 IY66513 IY70159 IY68989 IY89080" >>& $info
if ($status) then
	echo                         "[FAULT]" | tee -a $log
else
	echo                         "[OK]" | tee -a $log
endif
foreach shell (bash tcsh)
	straight "Checking $shell in /etc/security/login.cfg " | tee -a $log
	grep $shell /etc/security/login.cfg >>& $info 
	if ($status) then
		set stat="[FAULT]"
	else
		set stat="[OK]"
	endif
	echo "$stat" | tee -a $log
end

################################################################################
echo $pr2 >> $info
#/etc/hosts
echo "Hosts table." >> $info 
cat /etc/hosts >> $info
echo "">> $info

################################################################################
#memory size  
echo "Memory size." >> $info
lsattr -El mem0 >> $info
#set MEMORY_SIZE_MIN = 1024
set memory_size = `lsattr -El mem0 | grep Total | awk '{print $2}'`
if ( "$memory_size" <  "$MEMORY_SIZE_MIN" ) then
           straightln "Checking the memory size." "[FAULT]" | tee -a $log
else
           straightln "Checking the memory size." "[OK]" | tee -a $log
endif
echo $pr2 >> $info
################################################################################
echo "Swap size." >> $info
lsps -a >> $info
#swap size
#set SWAP_SIZE_MIN = 1024
set swap_size = ` lsps -a `
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 if the /exlibris directory does exist." "[FAULT]" | tee -a $log
else 
       	   straightln  "Checking if the /exlibris directory does exist." "[OK]" | tee -a $log
endif
echo $pr2 >> $info
################################################################################
#set EXLIBRIS_SIZE_MIN = 26214400
set exlibris_size = ` df -k /exlibris | grep exlibris | awk '{print $3}' `
if ( "$exlibris_size" < "$EXLIBRIS_SIZE_MIN" ) then
           straightln "Checking the /exlibris directory size." "[WARNING]" | tee -a $log
else
           straightln "Checking the /exlibris directory size." "[OK]" | tee -a $log
endif 	   
################################################################################
#check /tmp directory exist + size
echo "/tmp directory." >> $info
if (! -d /tmp ) then 
           straightln "Checking if the /tmp directory does exist." "[FAULT]" >>$log
	   echo "The /tmp directory does not exist." >> $info
else
           straightln "Checking if the /tmp directory does exist." "[OK]"  | tee -a $log 
	   ls -l / | grep tmp >> $info	
endif	      
echo $pr2 >> $info
################################################################################
#set TMP_SIZE_MIN = 1024
set tmp_size = ` df -k /tmp | grep tmp | awk '{print $3}' `
if ("$tmp_size" < "$TMP_SIZE_MIN" ) then
           straightln "Checking the /tmp directory size." "[FAULT]" | tee -a $log
else 
           straightln "Checking the /tmp directory size." "[OK]" | tee -a $log
endif	   	      
set maxuproc=`lsattr -E -l sys0 -a maxuproc | awk '{print $2}'`
set ncargs=`lsattr -E -l sys0 -a ncargs | awk '{print $2}'`
if ($maxuproc >= 1024) then
   straightln "Checking maxuproc value  (>1024)" "[OK]" | tee -a $log
else
   straightln "Checking maxuproc value  (>1024)" "[FAULT]" | tee -a $log
endif
        
if ($ncargs >= 128) then
   straightln "Checking ncargs   value  (>128)" "[OK]" | tee -a $log
else
   straightln "Checking ncargs   value  (>128)" "[FAULT]" | tee -a $log
endif

################################################################################
#check /exlibris/app/oracle/product/920
echo "" >> $info
if ( -d /exlibris/app/oracle/product/920 ) then
         echo "The /exlibris/app/oracle/product/920 directory exist. " >> $info  
         echo "">> $info
else
         echo "The /exlibris/app/oracle/product/920 directory does not exist. " >> $info
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#############################################
