summaryrefslogtreecommitdiff
path: root/scripts/vyatta-cfg-cmd-wrapper
blob: b0ec349096ecab0196288e6143671ccbdf681134 (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
#!/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"

case "$1" in
  begin)    # set up the session
    exec ${vyatta_sbindir}/my_cli_shell_api setupSession
    ;;
  end)    # tear down the session
    exec ${vyatta_sbindir}/my_cli_shell_api teardownSession
    ;;
  cleanup|discard)
    exec ${vyatta_sbindir}/my_discard
    ;;
  set)
    exec ${vyatta_sbindir}/my_set "${@:2}"
    ;;
  delete)
    exec ${vyatta_sbindir}/my_delete "${@:2}"
    ;;
  deactivate)
    exec ${vyatta_sbindir}/my_deactivate "${@:2}"
    ;;
  activate)
    exec ${vyatta_sbindir}/my_activate "${@:2}"
    ;;
  show)
    exec ${vyatta_sbindir}/my_cli_shell_api showCfg
    ;;
  comment)
    exec ${vyatta_sbindir}/my_comment "${@:2}"
    ;;
  commit)
    export COMMIT_VIA=cfg-cmd-wrapper
    ${vyatta_sbindir}/my_commit -a >> /tmp/vyatta-commit.log
    ${vyatta_sbindir}/my_commit -s >> /tmp/vyatta-commit.log
    exec ${vyatta_sbindir}/my_commit -e -d >> /tmp/vyatta-commit.log
    ;;
  commit_with_error)
    exec ${vyatta_sbindir}/my_commit
    ;;
  save)
    exec ${vyatta_sbindir}/vyatta-save-config.pl "${@:2}"
    ;;
  load)
    exec ${vyatta_sbindir}/vyatta-load-config.pl "${@:2}"
    ;;
  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
      exec ${vyatta_sbindir}/my_move firewall name "$3" rule "$5" to "$8"
    elif [ "$2" == "nat" ]; then
      exec ${vyatta_sbindir}/my_move service nat rule "$4" to "$7"
    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".
    exec ${vyatta_sbindir}/my_move "${@:2}"
    ;;
  *)
    echo "Invalid command \"$1\" for vyatta-cfg-cmd-wrapper"
    exit 1
    ;;
esac

# Only get here if exec failed.
echo "!!! Missing Vyatta shell infrastructure for $1 !!!!"
exit 1