From 2b12e94e3f19b694808fb2513f8e2a1e08eaec2d Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Wed, 18 Jun 2008 19:17:19 -0700 Subject: fix for bug 2622: add "copy" and "rename" commands for configuration mode. --- etc/bash_completion.d/20vyatta-cfg | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/etc/bash_completion.d/20vyatta-cfg b/etc/bash_completion.d/20vyatta-cfg index 102ce8f..c7e9ed7 100755 --- a/etc/bash_completion.d/20vyatta-cfg +++ b/etc/bash_completion.d/20vyatta-cfg @@ -113,6 +113,66 @@ top () set_config_ps1 '' } +rename() +{ + mvcp rename Rename mv "$@" +} + +copy() +{ + mvcp copy Copy "cp -a" "$@" +} + +mvcp () +{ + local str=$1 + shift + local Str=$1 + shift + local cmd=$1 + shift + local _otag=$1 + local _ovalu=$2 + local _to=$3 + local _ntag=$4 + local _nvalu=$5 + local _oval='' + local _nval='' + local _mpath=${VYATTA_TEMP_CONFIG_DIR}/${VYATTA_EDIT_LEVEL} + local _tpath=${VYATTA_CONFIG_TEMPLATE}/${VYATTA_TEMPLATE_LEVEL} + vyatta_escape _ovalu _oval + vyatta_escape _nvalu _nval + if [ "$_to" != 'to' ] || [ -z "$_ntag" ] || [ -z "$_nval" ]; then + echo "Invalid $str command" + return 1 + fi + if [ "$_otag" != "$_ntag" ]; then + echo "Cannot $str from \"$_otag\" to \"$_ntag\"" + return 1 + fi + if [ ! -d "$_tpath/$_otag/$VYATTA_TAG_NAME" ]; then + echo "Cannot $str under \"$_otag\"" + return 1 + fi + if [ ! -d "$_mpath/$_otag/$_oval" ]; then + echo "Configuration \"$_otag $_ovalu\" does not exist" + return 1 + fi + if [ -d "$_mpath/$_ntag/$_nval" ]; then + echo "Configuration \"$_ntag $_nvalu\" already exists" + return 1 + fi + if ! /opt/vyatta/sbin/my_set $_ntag "$_nvalu"; then + echo "$Str failed" + return 1 + fi + /opt/vyatta/sbin/my_delete $_ntag "$_nvalu" >&/dev/null 3>&1 + + $cmd "$_mpath/$_otag/$_oval" "$_mpath/$_ntag/$_nval" + + return 0 +} + edit () { local num_comp=${#@} -- cgit v1.2.3