#!/usr/bin/bash

# SHLINT:yes
# Copyright (c) 2020 by NetApp, Inc.
# All Rights Reserved.

#
# This script:
#   Updates the mop_epk structure in server.cfg file
#
# Example usage
#
# ./netapp_epk_agent_update 45454-545454-44ddd check_interval 60
# ./netapp_epk_agent_update 45454-545454-44ddd log_traffic true
#

readonly CAT="/bin/cat"
readonly EPK_AGENT="/usr/sbin/epk_agent"
readonly KMIP_SERVER_DIR="/cfcard/kmip/server"

readonly EPK_AGENT_LOG_FILE="${KMIP_SERVER_DIR}/epk_agent.log"

PWD=`pwd`


cd ${KMIP_SERVER_DIR}
	
partition=$1
label=$2
value=$3
retVal=0
    
# /usr/sbin/epk_agent expects input of <label>\n<value>\n pairs
# if <label> exists in server.cfg then the old <value> will be overwritten
epk_label="mop_epk.${partition}.${label}"
epk_value="${value}"

echo "$0: updating server.cfg at `date` (`date +%s`)" >> ${EPK_AGENT_LOG_FILE}
${CAT} << EOF | ${EPK_AGENT}
${epk_label}
${epk_value}
EOF

retVal=$?
echo "$0: finished updating server.cfg at `date` (`date +%s`)" >> ${EPK_AGENT_LOG_FILE}
cd $PWD

exit $retVal
