#!/bin/bash
# Syslog-ng trigger to sym-link the Hash file to the certificate file.
# Read the contents of the syslog_link_hash file and execute them.
FILE_NAME=$1
PRI_VER=$2
SEC_VER=$3
CFILE=$4
SYSLOGCA_DIR="/etc/syslog-ng/ca.d"
SYSLOG_LINK_HASH="syslog_link_hash"

# Need to copy the file from /mnt to / since the execution of trigger will by-pass the file sync operation of PDM from /mnt to /
if [ -f $FILE_NAME ]; then
	cp -f $FILE_NAME $SYSLOGCA_DIR
fi

# Execute the command in the syslog_link_hash file in-order to create the link
if [ -f /mnt$SYSLOGCA_DIR/$SYSLOG_LINK_HASH ]; then
	CERT_FILE=`/bin/cat /mnt$SYSLOGCA_DIR/$SYSLOG_LINK_HASH | /usr/bin/cut -d ' ' -f 3`
	# Check for the existence of the file before trying to sync.
	if [ -f $CERT_FILE ]; then
		CMD=`/bin/cat /mnt/$SYSLOGCA_DIR/$SYSLOG_LINK_HASH`
		$CMD
	fi
fi

exit 0
