Monday, 2 August 2021

PUMMER Deployment

Script to Deploy PUM Images Automatically

Main: pummer.ksh
==============
process_id=$(echo $$);
clear
echo ""
echo ""
echo ""

deploy_pum_image()
{

# Clone Container
# MODULE="CRM"
# bugid="31046243"
# NUMBER=3

# Prepare the container

echo "Destroying the existing ${MODULE}${bugid} container, if it exists \n"
    
lxc-ls --active
lxc-stop -k -n ${MODULE}${bugid}
lxc-destroy -n ${MODULE}${bugid}

echo "Cloning and Creating ${MODULE}${bugid} container"
lxc-clone oraclepumtemplate ${MODULE}${bugid}

echo "Preparing ${MODULE}${bugid} container"
mkdir -p /container/${MODULE}${bugid}/rootfs/pumdownload     
unalias cp;cp -rf /container/templates/config_template /container/${MODULE}${bugid}/config
sed -i "s/"__HOSTNAME__"/"${MODULE}${bugid}"/g" /container/${MODULE}${bugid}/config
cat /container/${MODULE}${bugid}/config

# Start the container

lxc-start -n ${MODULE}${bugid} -d -o /container/${MODULE}${bugid}.log -l DEBUG

# Deploy PUM IMAGE
lxc-attach -e -n "${MODULE}${bugid}" -o /tmp/${MODULE}${bugid}_$$.log -- chmod +x /root/scripts/pum_deploy.sh
lxc-attach -e -n "${MODULE}${bugid}" -o /tmp/${MODULE}${bugid}_$$.log -- /root/scripts/pum_deploy.sh ${NUMBER} ${bugid}

}

echo "==========================================="
echo "Welcome to PUMMER - PUM Deployment Manager"
echo "==========================================="

read -p 'Please Enter your Oracle ID:  ' uservar
read -sp 'Password: ' passvar
echo ""
echo ""
echo -n "Validating your Credentials: "
if [ $(/usr/bin/java -jar /root/pumdump/getMOSPatch.jar MOSUser=$uservar MOSPass=$passvar platform=226P download=all patch=32356044|grep "ERROR: Invalid credentials"|wc -l) -eq 1 ]; then
        echo -n "Invalid Credentials"
else
        echo -n " All Good"
        echo ""
        echo ""

        #read -p 'Application Module Number? 1-FSCM, 2-HCM, 3-CRM, 4-PORTAL:  ' module

                while true
                do
                read -p "Module Number? 1-FSCM, 2-HCM, 3-CRM, 4-PORTAL, 5-ELM, 6-CampusSolutions:  " NUMBER
                case $NUMBER in
                                1) MODULE="FSCM"; break;;
                                2) MODULE="HCM"; break;;
                                3) MODULE="CRM"; break;;
                                4) MODULE="PORTAL"; break;;
5) MODULE="ELM"; break;;
5) MODULE="CS"; break;;
                                *) echo "Not a valid option" ; continue ;;
                esac
                done

        echo ""

                while true
                do
                read -p 'Please Enter PUM / Bug ID:  ' bugid
                /usr/bin/java -jar /root/pumdump/getMOSPatch.jar MOSUser=$uservar MOSPass=$passvar platform=226P patch=$bugid > /tmp/${bugid}_${process_id}.txt 2>/dev/null

                                if [ $(cat /tmp/${bugid}_${process_id}.txt|grep zip|wc -l) -gt 5 ];
                                then
                                        break;
                                else
                                        continue
                                fi
                done

fi

 cat /tmp/${bugid}_${process_id}.txt

 echo "Please confirm if you want to move forward with the download of the BUG ID : $bugid and create a PUM instance ?"

read -r -p "Are you sure? [y/N] " response

if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
                mkdir -p /pumdownloads/${MODULE}/${bugid} && cd /pumdownloads/${MODULE}/${bugid}

                if [ -f /pumdownloads/${MODULE}/${bugid}/ALL_GOOD_FILES.txt ]
                then
                        echo ""
                        echo ""
                        echo "Good News: PUM Image ${MODULE} has been already downloaded no need to download once again. :)"
                        echo "Thanks, PUMMER will sent email notification along with the URL to your oracle $uservar once the PUM image is successfully deployed"
deploy_pum_image
                        echo ""
                        echo ""
                else
cd /pumdownloads/${MODULE}/${bugid}
nohup /container/scripts/download_deploy_pum_image.ksh uservar passvar bugid MODULE NUMBER > /pumdownloads/download_deploy_pum_image_${bugid}_${process_id}.log 2>&1 &
# deploy_pum_image
touch /pumdownloads/${MODULE}/${bugid}/ALL_GOOD_FILES.txt
                        echo ""
                        echo ""
                        echo "Thanks, PUMMER will sent email notification along with the URL to your oracle $uservar once the PUM image is successfully deployed"
                        echo ""
                        echo ""
                fi
else
 echo "Ok, your request is cancelled!"
fi



[root@localhost scripts]# cat download_deploy_pum_image.ksh
uservar=$1
passvar=$2
bugid=$3
MODULE=$4
NUMBER=$5

deploy_pum_image()
{

# Clone Container
# MODULE="CRM"
# bugid="31046243"
# NUMBER=3

# Prepare the container

echo "Destroying the existing ${MODULE}${bugid} container, if it exists \n"

        lxc-ls --active
        lxc-stop -k -n ${MODULE}${bugid}
        lxc-destroy -n ${MODULE}${bugid}

echo "Cloning and Creating ${MODULE}${bugid} container"

        lxc-clone oraclepumtemplate ${MODULE}${bugid}

echo "Preparing ${MODULE}${bugid} container"

        mkdir -p /container/${MODULE}${bugid}/rootfs/pumdownload
        unalias cp;cp -rf /container/templates/config_template /container/${MODULE}${bugid}/config
        sed -i "s/"__HOSTNAME__"/"${MODULE}${bugid}"/g" /container/${MODULE}${bugid}/config
        cat /container/${MODULE}${bugid}/config

# Start the container

lxc-start -n ${MODULE}${bugid} -d -o /container/${MODULE}${bugid}.log -l DEBUG

# Deploy PUM IMAGE
lxc-attach -e -n "${MODULE}${bugid}" -o /tmp/${MODULE}${bugid}_$$.log -- chmod +x /root/scripts/pum_deploy.sh
lxc-attach -e -n "${MODULE}${bugid}" -o /tmp/${MODULE}${bugid}_$$.log -- /root/scripts/pum_deploy.sh ${NUMBER} ${bugid}

}


/usr/bin/java -jar /root/pumdump/getMOSPatch.jar MOSUser=$uservar MOSPass=$passvar download=all platform=226P patch=$bugid; > /pumdownloads/${bugid}_${process_id}.log
touch /pumdownloads/${MODULE}/${bugid}/ALL_GOOD_FILES.txt
deploy_pum_image



# pum_deploy.sh
==============

[root@localhost scripts]# cat pum_deploy.sh
#pum_deploy.sh <APPLICATION> <PUMIMAGEID>
# 1-FSCM, 2-HCM, 3-CRM, 4-PORTAL, 5-ELM, 6-CampusSolutions

TEMPLATES=/root/scripts/templates
APPLICATION=$1
PUMIMAGE=$2
# /etc/hosts file update
if [ $(/sbin/ifconfig|grep eth1|wc -l) -eq 1 ]
then
        /sbin/ifconfig| grep eth1 -A 1|grep inet|awk -v host=$(hostname) '{ print "127.0.0.1 localhost\n"  $2 " " host }' > /etc/hosts
else
        echo "eth1 Not Found"
fi

if [ $APPLICATION -eq 1 ]
then
        # FSCM execution
        if [ -d /pumdownload/pumdownloads/FSCM/$PUMIMAGE ]; then
                cd /pumdownload/pumdownloads/FSCM/$PUMIMAGE/ && unzip -o *_1of*.zip
                cd /pumdownload/pumdownloads/FSCM/$PUMIMAGE/setup
                sh psft-dpk-setup.sh --silent --response_file=$TEMPLATES/fscm_response.txt --customization_file=$TEMPLATES/fscm_psft_customizations.yaml
        else
                echo "Sorry the PUM Image $PUMIMAGE Not Found for FSCM"
                exit 5
        fi
elif [ $APPLICATION -eq 2 ]; then
        # HCM execution
        if [ -d /pumdownload/pumdownloads/HCM/$PUMIMAGE ]; then
                cd /pumdownload/pumdownloads/HCM/$PUMIMAGE/ && unzip -o *_1of*.zip
                cd /pumdownload/pumdownloads/HCM/$PUMIMAGE/setup
                sh psft-dpk-setup.sh --silent --response_file=$TEMPLATES/hcm_response.txt --customization_file=$TEMPLATES/hcm_psft_customizations.yaml
        else
                echo "Sorry the PUM Image $PUMIMAGE Not Found for HCM"
                exit 5
        fi
elif [ $APPLICATION -eq 3 ]; then
        # CRM execution
        if [ -d /pumdownload/pumdownloads/CRM/$PUMIMAGE ]; then
                cd /pumdownload/pumdownloads/CRM/$PUMIMAGE/ && unzip -o *_1of*.zip
                cd /pumdownload/pumdownloads/CRM/$PUMIMAGE/setup
                sh psft-dpk-setup.sh --silent --response_file=$TEMPLATES/crm_response.txt --customization_file=$TEMPLATES/crm_psft_customizations.yaml
        else
                echo "Sorry the PUM Image $PUMIMAGE Not Found for CRM"
                exit 5
        fi
elif [ $APPLICATION -eq 4 ]; then
        # PORTAL execution
        if [ -d /pumdownload/pumdownloads/PORTAL/$PUMIMAGE ]; then
                cd /pumdownload/pumdownloads/PORTAL/$PUMIMAGE/ && unzip -o *_1of*.zip
                cd /pumdownload/pumdownloads/PORTAL/$PUMIMAGE/setup
                sh psft-dpk-setup.sh --silent --response_file=$TEMPLATES/portal_response.txt --customization_file=$TEMPLATES/portal_psft_customizations.yaml
        else
                echo "Sorry the PUM Image $PUMIMAGE Not Found for PORTAL"
                exit 5
        fi
elif [ $APPLICATION -eq 5 ]; then
        # ELM execution
                if [ -d /pumdownload/pumdownloads/ELM/$PUMIMAGE ]; then
                cd /pumdownload/pumdownloads/ELM/$PUMIMAGE/ && unzip -o *_1of*.zip
                cd /pumdownload/pumdownloads/ELM/$PUMIMAGE/setup
                sh psft-dpk-setup.sh --silent --response_file=$TEMPLATES/elm_response.txt --customization_file=$TEMPLATES/elm_psft_customizations.yaml
        else
                echo "Sorry the PUM Image $PUMIMAGE Not Found for ELM"
                exit 5
        fi
elif [ $APPLICATION -eq 6 ]; then
        # CS execution

        if [ -d /pumdownload/pumdownloads/CS/$PUMIMAGE ]; then
                cd /pumdownload/pumdownloads/CS/$PUMIMAGE/ && unzip -o *_1of*.zip
                cd /pumdownload/pumdownloads/CS/$PUMIMAGE/setup
                sh psft-dpk-setup.sh --silent --response_file=$TEMPLATES/cs_response.txt --customization_file=$TEMPLATES/cs_psft_customizations.yaml
        else
                echo "Sorry the PUM Image $PUMIMAGE Not Found for CS"
                exit 5
        fi
else
                echo "Wrong Option for the PUM Images"
                exit 1;
fi


No comments:

Post a Comment