summaryrefslogtreecommitdiff
path: root/scripts/vyatta-cfg-cmd-wrapper
blob: ef4cb8171726465e9a4f652b6f5bc5b02ca29f60 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash

# Author: Vyatta <eng@vyatta.com>
# 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 ****

# note: this script MUST be running as the vyattacfg group, e.g., with "sg".
# otherwise there WILL be permission problems with the files created.

# some env variables are needed
export vyatta_sysconfdir=/opt/vyatta/etc
export vyatta_sbindir=/opt/vyatta/sbin

# 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
# set up the session environment (get it from the unified lib)
session_env=$(${vyatta_sbindir}/my_cli_shell_api getSessionEnv $SID)
eval "$session_env"

RET_STATUS=0

case "$1" in
  begin)
    # set up the session
    ${vyatta_sbindir}/my_cli_shell_api setupSession
    RET_STATUS=$?
    ;;
  end)
    # tear down the session
    ${vyatta_sbindir}/my_cli_shell_api teardownSession
    RET_STATUS=$?
    ;;
  cleanup|discard)
    /opt/vyatta/sbin/my_discard
    RET_STATUS=$?
    ;;
  set)
    /opt/vyatta/sbin/my_set "${@:2}"
    RET_STATUS=$?
    ;;
  delete)
    /opt/vyatta/sbin/my_delete "${@:2}"
    RET_STATUS=$?
    ;;
  deactivate)
   /opt/vyatta/sbin/my_deactivate "${@:2}"
   RET_STATUS=$?
   ;;
  activate)
   /opt/vyatta/sbin/my_activate "${@:2}"
   RET_STATUS=$?
   ;;
  show)
   ${vyatta_sbindir}/my_cli_shell_api showCfg
   RET_STATUS=$?
   ;;
  comment)
   /opt/vyatta/sbin/my_comment "${@: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=$?
    ;;
  commit_with_error)
    /opt/vyatta/sbin/my_commit -x
    RET_STATUS=$?
    ;;
  save)
    /opt/vyatta/sbin/vyatta-save-config.pl "${@:2}"
    RET_STATUS=$?
    ;;
  load)
    /opt/vyatta/sbin/vyatta-load-config.pl "${@:2}"
    RET_STATUS=$?
    ;;
  rule-rename)
    # this option is to be used for renaming firewall and nat rules only
    # usage for this option specified on the next two lines -
    #             2        3                 4    5         6  7    8
    # rule-rename firewall $firewall_ruleset rule $rule_num to rule $rename_rulenum
    #             2   3    4         5  6    7
    # rule-rename nat rule $rule_num to rule $rename_rulenum
    if [ "$2" == "firewall" ]; then
      /opt/vyatta/sbin/my_move firewall name "$3" rule "$5" to "$8"
      RET_STATUS=$?
    elif [ "$2" == "nat" ]; then
      /opt/vyatta/sbin/my_move service nat rule "$4" to "$7"
      RET_STATUS=$?
    fi
    ;;
  move)
    # this is similar to the CLI edit+rename command.
    # e.g., "move interfaces ethernet eth2 vif 100 to 200"
    # is similar to "edit interfaces ethernet eth2" plus
    # "rename vif 100 to vif 200".
    /opt/vyatta/sbin/my_move "${@:2}"
    RET_STATUS=$?
    ;;
  *)
    echo "Invalid command \"$1\" for vyatta-cfg-cmd-wrapper"
    RET_STATUS=1  
    ;;
esac

exit $RET_STATUS