#!/bin/sh
#
# The following script removes the 'CMASK=022' string or restores its
# pre-patch value in the /etc/default/init file. 
#
#     

INITDIR=$ROOTDIR/etc/default
PP_VALUE_FOUND=""

# Check installation log file to see if user had previously set the
# CMASK variable in /etc/default/init prior to the installation
# of the patch.  Want to preserve the user's pre-patch customization.

# If user had previously set the CMASK variable to 022, then do nothing 
# and exit script.  Else, if CMASK= exists in the log file, then user had
# previously set its value to some value.  In this case, set the pre-patch 
# variable PP_VALUE_FOUND value to "Y".

if [ -f $ROOTDIR/var/sadm/patch/${PatchNum}/log ]; then
    /usr/bin/grep 'CMASK=022' $ROOTDIR/var/sadm/patch/${PatchNum}/log >/dev/null 2>&1

    if [ "$?" -eq "0" ]; then
       exit 0 
    else 
       /usr/bin/grep 'CMASK=' $ROOTDIR/var/sadm/patch/${PatchNum}/log >/dev/null 2>&1
    fi
    
    if  [ "$?" -eq "0" ]; then
        PP_VALUE_FOUND="Y" 
    fi
fi

# Check to see if the init file exists

if [ -f ${INITDIR}/init ]; then

    # If /etc/default/init exists, check if the 'CMASK=022' string is present

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

    # If 'CMASK=022' string present, we remove the related init line

    if [ "$?" -eq "0" ]; then
        /usr/bin/grep -v 'CMASK=022' ${INITDIR}/init > ${INITDIR}/init.tmp
        /usr/bin/mv ${INITDIR}/init.tmp ${INITDIR}/init
    fi
  
    if [ "$PP_VALUE_FOUND" = "Y" ]; then
       /usr/bin/grep 'CMASK=' $ROOTDIR/var/sadm/patch/${PatchNum}/log >> ${INITDIR}/init
    fi

    # Re-set the file permissions
    /usr/bin/chmod 0555 ${INITDIR}/init
fi

exit 0
