summaryrefslogtreecommitdiff
path: root/scripts/vyatta-cfg-cmd-wrapper
blob: b419f55d78abbfe060c27a119d4044bc74be078a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash

# **** License ****
# Version: VPL 1.0
# 
# The contents of this file are subject to the Vyatta Public License
# Version 1.0 ("License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.vyatta.com/vpl
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
# 
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2006, 2007 Vyatta, Inc.
# All Rights Reserved.
# 
# Author: An-Cheng Huang
# Date: 2007
# Description: command wrapper
# 
# **** End License ****

if grep -q union=aufs /proc/cmdline || grep -q aufs /proc/filesystems ; then
  export UNIONFS=aufs
else
  export UNIONFS=unionfs
fi

UMASK_SAVE=`umask`
umask 0002

export VYATTA_EDIT_LEVEL=/;
export VYATTA_TEMPLATE_LEVEL=/;
export VYATTA_ACTIVE_CONFIGURATION_DIR=/opt/vyatta/config/active;

export VYATTA_CHANGES_ONLY_DIR=/opt/vyatta/config/tmp/changes_only_$PPID;
export VYATTA_TEMP_CONFIG_DIR=/opt/vyatta/config/tmp/new_config_$PPID;
export VYATTA_CONFIG_TMP=/opt/vyatta/config/tmp/tmp_$PPID;

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)
    /opt/vyatta/sbin/my_commit
    RET_STATUS=$?
    ;;
  *)
    echo "Invalid command \"$1\" for vyatta-cfg-cmd-wrapper"
    RET_STATUS=1  
    ;;
esac

umask ${UMASK_SAVE}
exit $RET_STATUS