#!/bin/sh
set -x
IDRAC_DEF_PWD_CHANGE_FLAG="/flash/data0/change_idrac_def_pwd"

# Change password for Greyjoy platforms to ibm-Genesis-Cl0ud
# If platform Sunderly or Quellon found then set flag IDRAC_DEF_PWD_CHANGE_FLAG
# to change pwd if not already set
pt_ID=$(get-system-id)
if [ "$pt_ID" == "7e" ] || [ "$pt_ID" == "7d" ]; then
	if [ ! -e /flash/data0/change_idrac_def_pwd ]
	then
  		#pwd: ibm-Genesis-Cl0ud > 17 bytes long, so use 20 byte set pwd command
    	IPMICmd 0x20 0x06 0x00 0x47 0x82 0x02 0x69 0x62 0x6d 0x2d 0x47 0x65 0x6e 0x65 0x73 0x69 0x73 0x2d 0x43 0x6c 0x30 0x75 0x64 0 0 0
	 	#set flag for pwd change
    	touch $IDRAC_DEF_PWD_CHANGE_FLAG
	fi

 	# Enable IPMI Over LAN - Non-Volatile Channel
	IPMICmd 0x20 0x06 0x00 0x40 0x01 0x7a 0x04
 	# Enable IPMI Over LAN - Volatile Channel
	IPMICmd 0x20 0x06 0x00 0x40 0x01 0xba 0x04
fi

# call Backup and Restore initcleanup
/bin/brorch initcleanup

# call System Erase function to cleanup
/bin/jsyserase delete

#BITS148646: Removing the following code for launch_ssm
# After cleanup (possibly of SSIB task too, check if there is anything left )
# Moved here from verify_maser.sh to allow maser server process to startup
#if  lcllibtest CHECKSSIB /tmp/masmount/
#then
#    touch /tmp/launch_ssm
#fi

#BITS182568: Removing host power on here and adding new service(bnr-host-poweron.service)
# which waits for DM to be fully initialized before powering on host.
#
# if [ -e /flash/data0/DontBackup/restorepwrupreq ]; then
# echo Powering up host
# status=`/bin/IPMICmd 20 0 0 2 1`
# echo ${status}
# rm /flash/data0/DontBackup/restorepwrupreq
# fi

#create uboot_env vars if needed
if [ -f /mnt/cores/CRCs.txt ] ; then
  echo "Setting FWN and FWN1"
  /bin/fw_setenv FWN `cat /mnt/cores/CRCs.txt`
  /bin/fw_setenv FWN1 `cat /mnt/cores/CRCs.txt`
  rm -f /mnt/cores/CRCs.txt
fi

#keep iDRAC connection UP in shared NIC mode while HOST is rebooting(for INTEL cards only)
libncsitest 2 1 1 1 > /var/log/ncsi.log
Vendor_ID=$(grep -e 0x8086 /var/log/ncsi.log | cut -d "=" -f2)

if [ "$(readcfg -g16486 -f8)" == "KeepPhyLinkUp_1=1" ]; then
    if [ "$Vendor_ID" == "0x8086" ]; then
        libncsitest 20 0 3 10 100 0x00 0x01 0x00 0x01 0x50 0x00 0x00 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x57 0x20 0x00 0x01 0x00 0x00 0x00 0x00 0x00 >> /var/log/ncsi.log
        libncsitest 20 1 3 10 100 0x00 0x01 0x00 0x01 0x50 0x00 0x00 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x57 0x20 0x00 0x01 0x00 0x00 0x00 0x00 0x00 >> /var/log/ncsi.log
        libncsitest 20 2 3 10 100 0x00 0x01 0x00 0x01 0x50 0x00 0x00 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x57 0x20 0x00 0x01 0x00 0x00 0x00 0x00 0x00 >> /var/log/ncsi.log
        libncsitest 20 3 3 10 100 0x00 0x01 0x00 0x01 0x50 0x00 0x00 0x07 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0x57 0x20 0x00 0x01 0x00 0x00 0x00 0x00 0x00 >> /var/log/ncsi.log
    fi
fi

