#!/bin/sh
#Theme:  11gR2 Preinstallation Operations On RHEL5.4 32bit Only
#Author: Majesty.
#MyBlog: http://majesty.blog.51cto.com  for more research about oracle.

#Forward
#  referencing http://docs.oracle.com/cd/E11882_01/install.112/e24324/toc.htm
#  and some internet resource.

#Before Anything:
#  If you assure you install all os packages already, you could skip this step.
#  You had batter mount RHEL5 32bit on /mnt

#Main Dir
#  #1 add essential user and group for O11gR2 installation.
#  #2 modify ~/.bash_profile
#  #3 modify /etc/sysctl.conf
#  #4 modify /etc/security/limits.conf
#  #5 /etc/profile
#  #6 /etc/pam.d/login
#  #7 install essential os packages for oracle installation.
 
#set -x
#assure you already configure the yum
#1 add essential user and group for O11gR2 installation.
groupadd dba
groupadd oper
groupadd oinstall
useradd oracle
usermod -g oinstall -G dba oracle
passwd oracle <oracle
EOF
mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app

#2 modify ~/.bash_profile
cat > /home/oracle/.bash_profile <<'EOF'
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0
export ORACLE_SID=ocm11g
export ORACLE_OWNER=oracle
export ORACLE_TERM=vt100
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH
export PATH=$PATH:/usr/sbin:/usr/bin;
export NLS_LANG=american_america.AL32UTF8
export LANG=en_US 
export EDITOR=vim
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_DATE_FORMAT="yyyy-mm-dd hh24:mi:ss"
EOF


#3 modify /etc/sysctl.conf
cat > /etc/sysctl.conf <# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536

# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536

#append here for install O11gR2
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912 ###half of your memory
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
EOF


#4 modify /etc/security/limits.conf
# It is the resource limit for the number of processes available to a user.
cat > /etc/security/limits.conf  <# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#           
#
#Where:
# can be:
#        - an user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
# can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
# can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open files
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to
#        - rtprio - max realtime priority
#
#                
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4

# End of file
oracle soft nproc  2047
oracle hard nproc  16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack  10240
EOF

#5 /etc/profile
check_profile=`grep "ulimit -p 16384" /etc/profile`
if [ "$check_profile" == ''  ]; then
cat >> /etc/profile <if [ $USER = "oracle" ]; then
  if [ $SHELL = "/bin/ksh" ]; then
     ulimit -p 16384
     ulimit -n 65536
  else
     ulimit -u 16384 -n 65536
  fi
fi
EOF
else
  echo "Negative........../etc/profile ware already modified!!"
fi
 
#6 /etc/pam.d/login
check_pam=`grep "/lib/security/pam_limits.so" /etc/pam.d/login | awk {'print $3'}`
if [ $? = 0 ];
then
    echo "Negative........../etc/pam.d/login ware already modified!!"
else
cat >> /etc/pam.d/login <session required /lib/security/pam_limits.so 
session required pam_limits.so
!
fi


#please mount RHEL5 cdrom to /mnt directory!!!
#7 install essential os packages for oracle installation.
cd  /mnt/Server
rpm -ivh      binutils-2.17.50.0.6*
rpm -ivh    compat-libstdc++-33-3.2.3*
rpm -ivh    elfutils-libelf-0.125*
rpm -ivh    elfutils-libelf-devel-0.125*
rpm -ivh    elfutils-libelf-devel-static-0.125*
rpm -ivh    gcc-4.1.2*
rpm -ivh    gcc-c++-4.1.2*
rpm -ivh    glibc-2.5-24*
rpm -ivh    glibc-common-2.5*
rpm -ivh    glibc-devel-2.5*
rpm -ivh    glibc-headers-2.5*
rpm -ivh    kernel-headers-2.6.18*
rpm -ivh    ksh-20060214*
rpm -ivh    libaio-0.3.106*
rpm -ivh    libaio-devel-0.3.106 *
rpm -ivh    libgcc-4.1.2*
rpm -ivh    libgomp-4.1.2*
rpm -ivh    libstdc++-4.1.2 *
rpm -ivh    libstdc++-devel-4.1.2*
rpm -ivh    make-3.81*
rpm -ivh    sysstat-7.0.2*