#!/bin/bash

# This script customize the HMC console
# First setup PAM authentication

cd /etc/pam.d
for i in *
do
  if [ "$i" != "passwd" ]
  then
     x=`grep "auth" $i | grep "pam_hsc.so"  2>/dev/null`
     if [ $? -eq 1 ]
     then
        echo "auth    required    /lib/security/pam_hsc.so" >> $i
     fi

     x=`grep "session" $i | grep "pam_hsc.so"  2>/dev/null`
     if [ $? -eq 1 ]
     then
        echo "session optional    /lib/security/pam_hsc.so" >> $i
     fi
  fi
done

if [ -f /etc/crontab ]
then
  x=`grep "MAILTO=root" /etc/crontab`
  if [ $? -eq 0 ]
  then
    sed -e 's/MAILTO=root/MAILTO=/g' /etc/crontab > /tmp/_newCrontab
    cp /tmp/_newCrontab /etc/crontab
  fi
fi

if [ -f /etc/rc.d/boot.local ]
then
  x=`grep "rm -rf /var/hsc/access/db/credmgr.bk" /etc/rc.d/boot.local`
  if [ $? -eq 1 ]
  then
    echo "rm -rf /var/hsc/access/db/credmgr.bk" >>/etc/rc.d/boot.local
  fi

  x=`grep "touch /var/lock/subsys/local" /etc/rc.d/boot.local`
  if [ $? -eq 1 ]
  then
    echo "touch /var/lock/subsys/local" >>/etc/rc.d/boot.local
  fi

  x=`grep "/opt/hsc/bin/cfgRMC" /etc/rc.d/boot.local`
  if [ $? -eq 1 ]
  then
    echo "/opt/hsc/bin/cfgRMC 2>>/dev/null" >>/etc/rc.d/boot.local
  fi

  x=`grep "/sbin/hdparm" /etc/rc.d/boot.local`
  if [ $? -eq 1 ]
  then
    HD=`/opt/hsc/bin/GetHD`
    echo "/sbin/hdparm -u1 -m16 -c3 /dev/${HD}" >>/etc/rc.d/boot.local
  fi

# We decided to not write the trace log to the file.
  x=`grep "/usr/sbin/iqzdtcon" /etc/rc.d/boot.local`
  if [ $? -eq 0 ]
  then
    sed -e 's/\/usr\/sbin\/iqzdtcon/#\/usr\/sbin\/iqzdtcon/' /etc/rc.d/boot.local
> /opt/hsc/data/boot_local.dup
    cp -f /opt/hsc/data/boot_local.dup /etc/rc.d/boot.local
    rm -f /opt/hsc/data/boot_local.dup
  fi
  x=`grep "cp -pf /opt/hsc/data/iqzdtrac.trm /opt/hsc/data/iqzdtrac.trm.previous" /etc/rc.d/boot.local`
  if [ $? -eq 1 ]
  then
    echo "if [ -f /opt/hsc/data/iqzdtrac.trm ]" >> /etc/rc.d/boot.local
    echo "then" >>/etc/rc.d/boot.local
    echo "   cp -pf /opt/hsc/data/iqzdtrac.trm /opt/hsc/data/iqzdtrac.trm.previous" >>/etc/rc.d/boot.local
    echo "fi" >>/etc/rc.d/boot.local
  fi

fi
grep "^auth\.\*" /etc/syslog.conf 2>/dev/null | grep "~/var/log/messages" 2>&1 >/dev/null
if [ $? -eq 1 ]
then
  echo "auth.*                                      ~/var/log/messages" >> /etc/syslog.conf
fi
grep "^auth\.\*" /etc/syslog.conf 2>/dev/null | grep "/var/hsc/log/secure" 2>&1 >/dev/null
if [ $? -eq 1 ]
then
  echo "auth.*                                      /var/hsc/log/secure" >> /etc/syslog.conf
fi

grep "^SyslogFacility[ \t] *AUTH\b" /etc/ssh/sshd_config 2>/dev/null
if [ $? -ne 0 ]
then
  /bin/sed -e 's/^SyslogFacility[ \t] *AUTHPRIV/SyslogFacility AUTH/' /etc/ssh/sshd_config > /tmp/saved_sshd_config
  mv /tmp/saved_sshd_config /etc/ssh/sshd_config
fi
grep "^LogLevel ERROR" /etc/ssh/sshd_config 2>/dev/null
if [ $? -ne 0 ]
then
  echo "LogLevel ERROR" >>/etc/ssh/sshd_config
fi

if [ ! -f /var/hsc/log/secure ]
then
   touch /var/hsc/log/secure
fi
chown root.hmc /var/hsc/log/secure 2>/dev/null
chmod 640 /var/hsc/log/secure
chown root.hmc /var/hsc/log/secure.* 2>/dev/null
chmod 640 /var/hsc/log/secure.*

if [ -f /var/run/syslogd.pid ]
then
   /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null
fi

if [ -f /var/run/httpd.pid ]
then
   /bin/kill -HUP `cat /var/run/httpd.pid 2> /dev/null` 2> /dev/null
fi
# Update Chinese fonts in font.alias file
grep -q "! HMC_ADDED_CHINESE_FONTS" /usr/X11R6/lib/X11/fonts/misc/fonts.alias 2>/dev/null
if [ $? -ne 0 ]
then
   echo "! HMC_ADDED_CHINESE_FONTS" >> /usr/X11R6/lib/X11/fonts/misc/fonts.alias
   echo "-dynalab-ming-medium-r-normal--16-160-75-75-c-160-big5-0 -dynalab-ming-medium-r-normal-fantizi-16-160-75-75-c-160-big5-0" >> /usr/X11R6/lib/X11/fonts/misc/fonts.alias
   echo "-dynalab-ming-medium-r-normal--24-240-75-75-c-240-big5-0 -dynalab-ming-medium-r-normal-fantizi-24-240-75-75-c-240-big5-0" >> /usr/X11R6/lib/X11/fonts/misc/fonts.alias
fi
grep -q "! HMC_ADDED_CHINESE_FONTS" /usr/X11R6/lib/X11/fonts/truetype/fonts.alias 2>/dev/null
if [ $? -ne 0 ]
then
   echo "-Arphic-AR PL Mingti2L Big5-medium-r-normal--16-0-0-0-c-0-big5-0" "-Arphic-AR PL Mingti2L Big5-medium-r-normal--16-120-0-0-c-0-big5-0" >>/usr/X11R6/lib/X11/fonts/truetype/fonts.alias
fi

exit 0
