#!/bin/sh
#
# The following script appends the 'CMASK=022' string to
# /etc/default/init, if it is not present.  If the CMASK
# variable is present and has been set to some value, the
# script will append the column heading "PRE PATCH CMASK 
# VALUE:" to the log file.  It will then add the string 
# CMASK=<some value> below the column heading.  These
# These entries will be, used to restore the CMASK 
# variable to its pre-install value.

INITDIR=$ROOTDIR/etc/default
LOG=$ROOTDIR/var/sadm/patch/$PatchNum/log
PP_VALUE_FOUND=""

# Check to see if the init file exists
if [ -f ${INITDIR}/init ]; then

    # If the init file exists, check if the 'CMASK=022' string already present.
    # If so, record its value in the LOG file and do nothing else. 

    /usr/bin/grep 'CMASK=022' $INITDIR/init >/dev/null 2>&1

    if [ "$?" -eq "0" ]; then
       PP_VALUE_FOUND="Y"
       echo "PRE PATCH CMASK VALUE:" >> $LOG
       /usr/bin/grep 'CMASK=' $INITDIR/init >> $LOG
    fi

    # If CMASK= string not present, add it to the init file with patch value.
    # Else, if CMASK= is present, record its current value in the LOG file
    # and remove it from the init file.  Then add patch CMASK value to init
    # file.

    /usr/bin/grep 'CMASK=' $INITDIR/init >/dev/null 2>&1

    if [ "$?" -ne "0" ]; then
        echo "CMASK=022" >> $INITDIR/init
    else
        if  [ "$PP_VALUE_FOUND" != "Y" ]; then
          echo "PRE PATCH CMASK VALUE:" >> $LOG
          /usr/bin/grep 'CMASK=' $INITDIR/init >> $LOG
        fi
        /usr/bin/grep -v 'CMASK' ${INITDIR}/init > ${INITDIR}/init.tmp
        /usr/bin/mv ${INITDIR}/init.tmp ${INITDIR}/init
        echo "CMASK=022" >> $INITDIR/init
        /usr/bin/chmod 0555 ${INITDIR}/init
        
    fi
fi

exit 0
