#!/bin/bash # Author: An-Cheng Huang # Date: 2007 # Description: command wrapper # **** License **** # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # This code was originally developed by Vyatta, Inc. # Portions created by Vyatta are Copyright (C) 2006, 2007, 2008 Vyatta, Inc. # All Rights Reserved. # **** End License **** if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then export UNIONFS=aufs else export UNIONFS=unionfs fi # permissions ## note: this script should be running as the vyattacfg group, e.g., with "sg". ## otherwise there may be permission problems with the files created. UMASK_SAVE=`umask` umask 0002 export VYATTA_EDIT_LEVEL=/; export VYATTA_TEMPLATE_LEVEL=/; export VYATTA_ACTIVE_CONFIGURATION_DIR=/opt/vyatta/config/active; # allow env variable to override default session id (ppid). this enables # the script to handle cases where the invocations can come from # different parents. SID=$PPID if [ -n "$CMD_WRAPPER_SESSION_ID" ]; then SID=$CMD_WRAPPER_SESSION_ID fi export VYATTA_CHANGES_ONLY_DIR=/tmp/changes_only_$SID; export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$SID; export VYATTA_CONFIG_TMP=/opt/vyatta/config/tmp/tmp_$SID; RET_STATUS=0 case "$1" in begin) # set up the environment/directories mkdir -p $VYATTA_ACTIVE_CONFIGURATION_DIR mkdir -p $VYATTA_CHANGES_ONLY_DIR if [ ! -d $VYATTA_TEMP_CONFIG_DIR ]; then mkdir -p $VYATTA_TEMP_CONFIG_DIR sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:${VYATTA_ACTIVE_CONFIGURATION_DIR}=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR} fi mkdir -p $VYATTA_CONFIG_TMP ;; end) # tear down the environment/directories sudo umount ${VYATTA_TEMP_CONFIG_DIR} rm -rf ${VYATTA_CHANGES_ONLY_DIR} rm -rf ${VYATTA_CONFIG_TMP} rm -rf ${VYATTA_TEMP_CONFIG_DIR} ;; cleanup) sudo umount ${VYATTA_TEMP_CONFIG_DIR} rm -rf $VYATTA_CHANGES_ONLY_DIR/* $VYATTA_CHANGES_ONLY_DIR/.modified sudo mount -t $UNIONFS -o dirs=${VYATTA_CHANGES_ONLY_DIR}=rw:${VYATTA_ACTIVE_CONFIGURATION_DIR}=ro $UNIONFS ${VYATTA_TEMP_CONFIG_DIR} ;; set) /opt/vyatta/sbin/my_set "${@:2}" RET_STATUS=$? ;; delete) /opt/vyatta/sbin/my_delete "${@:2}" RET_STATUS=$? ;; commit) # debug file /tmp/bar should be deleted before release /opt/vyatta/sbin/my_commit -a >> /tmp/bar /opt/vyatta/sbin/my_commit -s >> /tmp/bar /opt/vyatta/sbin/my_commit -e -d >> /tmp/bar RET_STATUS=$? ;; save) /opt/vyatta/sbin/vyatta-save-config.pl "${@:2}" RET_STATUS=$? ;; *) echo "Invalid command \"$1\" for vyatta-cfg-cmd-wrapper" RET_STATUS=1 ;; esac umask ${UMASK_SAVE} exit $RET_STATUS