#!/bin/bash UMASK_SAVE=`umask` umask 0111 XORPLOGFILE=/tmp/xorp_tmpl_tool.log touch ${XORPLOGFILE} umask ${UMASK_SAVE} #need to pass in value to change... as part of set command... ## cli ENV_EDIT_LEVEL export VYATTA_EDIT_LEVEL=/; ## cli ENV_TEMPLATE_LEVEL export VYATTA_TEMPLATE_LEVEL=/; ## cli ENV_A_DIR export VYATTA_ACTIVE_CONFIGURATION_DIR=/opt/vyatta/config/active; mkdir -p $VYATTA_ACTIVE_CONFIGURATION_DIR #now need to grab the parent pid. ## XXX eventually, we will use each session's bash shell pid for this. ## however, for now, to interact with XORP we will rely on a global lock ## instead of separate config dirs. #export VTID=$PPID export VTID=XORP # lock for XORP export XORP_LOCK="/opt/vyatta/config/active/.xorp.lck" ## cli ENV_C_DIR export VYATTA_CHANGES_ONLY_DIR=/opt/vyatta/config/tmp/changes_only_$VTID; mkdir -p $VYATTA_CHANGES_ONLY_DIR ## cli ENV_M_DIR export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$VTID; if [ ! -d $VYATTA_TEMP_CONFIG_DIR ] then mkdir -p $VYATTA_TEMP_CONFIG_DIR sudo mount -t unionfs -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro unionfs ${VYATTA_TEMP_CONFIG_DIR} fi ## cli ENV_TMP_DIR export VYATTA_CONFIG_TMP=/opt/vyatta/config/tmp/tmp_$VTID; mkdir -p $VYATTA_CONFIG_TMP RET_STATUS=0 #this needs to be the array string of commands, something like $[*] or whatever echo "Command: ${@}" | grep -v -i password >> ${XORPLOGFILE} #echo "ConfigDirectories BEFORE ========>>>>>>" >> ${XORPLOGFILE} #find /opt/vyatta/config -name "*" -print | grep interface >> ${XORPLOGFILE} #echo "<=========ConfigDirectories BEFORE" >> ${XORPLOGFILE} ## for tracing command-line XRL calls. ## 1 => info level ## 2 => warning level #export CL_XRLTRACE=2 UMASK_SAVE=`umask` umask 0111 MYCMDERRLOGFILE=/tmp/my_cmd_err_${RANDOM}.log rm -rf ${MYCMDERRLOGFILE} umask ${UMASK_SAVE} case "$1" in set) /opt/vyatta/sbin/my_set "${@:2}" >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE} RET_STATUS=$? if [ $RET_STATUS != 0 ]; then rm -rf $XORP_LOCK >&/dev/null fi ;; delete) /opt/vyatta/sbin/my_delete "${@:2}" >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE} RET_STATUS=$? if [ $RET_STATUS != 0 ]; then rm -rf $XORP_LOCK >&/dev/null fi ;; commit) /opt/vyatta/sbin/my_commit >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE} RET_STATUS=$? rm -rf $XORP_LOCK >&/dev/null ;; test) "${@:2}" >>${XORPLOGFILE} 2>>${MYCMDERRLOGFILE} RET_STATUS=$? ;; cleanup) LOCKTRYCOUNTER=0 LOCKTRYSTATUS=-1 while [[ ${LOCKTRYCOUNTER} -lt 60 && ${LOCKTRYSTATUS} -ne 0 ]] ; do if mkdir $XORP_LOCK >&/dev/null ; then LOCKTRYSTATUS=0 else LOCKTRYCOUNTER=`expr ${LOCKTRYCOUNTER} + 1` sleep 1; fi done if [ ${LOCKTRYCOUNTER} -ge 60 ] ; then echo "Cannot unlock configuration" >> ${MYCMDERRLOGFILE} rm -rf ${XORP_LOCK} mkdir $XORP_LOCK >&/dev/null fi sudo umount ${VYATTA_TEMP_CONFIG_DIR} sudo rm -rf $VYATTA_CHANGES_ONLY_DIR/* $VYATTA_CHANGES_ONLY_DIR/.modified sudo mount -t unionfs -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:/opt/vyatta/config/active=ro unionfs ${VYATTA_TEMP_CONFIG_DIR} RET_STATUS=0 ;; end_loading) sudo umount ${VYATTA_TEMP_CONFIG_DIR} sudo rm -rf ${VYATTA_CHANGES_ONLY_DIR} sudo rm -rf ${VYATTA_CONFIG_TMP} sudo rm -rf ${VYATTA_TEMP_CONFIG_DIR} RET_STATUS=0 ;; rtrmgr_indirect_cleanup) # do nothing now that we handle XORP interaction differently. RET_STATUS=0 ;; *) rm -rf ${MYCMDERRLOGFILE} exit 1 ;; esac if [ -f ${MYCMDERRLOGFILE} ] ; then echo -n "STDERR:" >>${XORPLOGFILE} cat ${MYCMDERRLOGFILE} >>${XORPLOGFILE} echo "end of STDERR" >>${XORPLOGFILE} cat ${MYCMDERRLOGFILE} 1>&2 rm -rf ${MYCMDERRLOGFILE} fi #echo "ConfigDirectories AFTER ========>>>>>>" >> ${XORPLOGFILE} #find /opt/vyatta/config -name "*" -print | grep interface >> ${XORPLOGFILE} #echo "<=========ConfigDirectories AFTER" >> ${XORPLOGFILE} echo "ret=${RET_STATUS}" >> ${XORPLOGFILE} exit $RET_STATUS