aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-04-09 18:09:51 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-04-09 18:09:51 +0300
commitd72d3a32b3f8777f91896b00dd44704025b3b52f (patch)
tree8134f37c9a36e3db3edf37eb78a30f1e2639c705
parentd7172f46f0774f235aa972d3bf01306808b3aebc (diff)
downloadscripts-d72d3a32b3f8777f91896b00dd44704025b3b52f.tar.gz
scripts-d72d3a32b3f8777f91896b00dd44704025b3b52f.tar.bz2
Improve copy-tags
* copy-tags: Fix --help handling; add new options for filtering and debugging.
-rwxr-xr-xcopy-tags68
1 files changed, 60 insertions, 8 deletions
diff --git a/copy-tags b/copy-tags
index e54bc14..8af1a3a 100755
--- a/copy-tags
+++ b/copy-tags
@@ -21,6 +21,11 @@ usage: $0 [OPTIONS] SRC DST
copies tags between from EC2 object SRC to DST
OPTIONS are:
+ -n, --dry-run do not actually copy tags to DST, show them
+ instead
+ --exclude=REGEXP exclude tag with names matching REGEXP
+ --exclude-value=REGEXP exclude tags with values matching REGEXP
+ --filter=FILE use AWK program FILE to filter tags
-O, --access-key=STRING set access key to use
-W, --secret-key=STRING set secret key to use
-a, --access-file=NAME set access file
@@ -47,8 +52,11 @@ for translation.
EOT
}
-obj=
ECLAT_OPTIONS=
+obj=
+prog=
+filter=
+dry_run=
while [ $# -ne 0 ]
do
case $1 in
@@ -56,10 +64,29 @@ do
eval $1
shift
;;
+ -n|--dry-run)
+ dry_run=1
+ shift
+ ;;
+ --exclude=*)
+ arg=$(expr "$1" : '--exclude=\(.*\)')
+ prog="$prog /^${arg}=/ { next }"
+ shift
+ ;;
+ --exclude-value=*)
+ arg=$(expr "$1" : '--exclude-value=\(.*\)')
+ prog="$prog /=$arg/ { next }"
+ shift
+ ;;
+ --filter=*)
+ filter=$(expr "$1" : '--filter=\(.*\)')
+ shift
+ ;;
-[aisv])
obj=$1; shift;;
-h|--help)
- help;;
+ help
+ exit 0;;
-[MOWac]*)
opt=$(expr "$1" : '-\(.\).*')
arg=$(expr "$1" : '-.\(.*\)')
@@ -75,7 +102,7 @@ do
fi
shift
;;
- -x|-n|--dry-run|--access-key=*|--secret-key=*|--access-file=*|--config-file=*|--region=*|--ssl|--map=*)
+ -x|--access-key=*|--secret-key=*|--access-file=*|--config-file=*|--region=*|--ssl|--map=*)
ECLAT_OPTIONS="$ECLAT_OPTIONS $1"
shift
;;
@@ -117,11 +144,36 @@ esac
export ECLAT_OPTIONS
-eclat -e 'if (.DescribeTagsResponse)
- for (var in .DescribeTagsResponse.tagSet.item)
- print(var.key,"=",var.value,"\n");' \
- describe-tags $obj $1 |
- eclat create-tags $obj $2 -T -
+gettags() {
+ eclat -e 'if (.DescribeTagsResponse)
+ for (var in .DescribeTagsResponse.tagSet.item)
+ print(var.key,"=",var.value,"\n");' \
+ describe-tags $obj $1
+}
+
+puttags() {
+ if [ -n "$dry_run" ]; then
+ cat -
+ else
+ eclat create-tags $obj $1 -T -
+ fi
+}
+
+if [ -n "$filter" ]; then
+ if [ -n "$prog" ]; then
+ echo >&2 "--filter and --exclude cannot be used together"
+ exit 1
+ fi
+ awk -f $filter < /dev/null || exit 1
+ gettags $1 | awk -f $filter | puttags $2
+elif [ -n "$prog" ]; then
+ prog="$prog { print }"
+ awk "$prog" < /dev/null || exit 1
+ gettags $1 | awk "$prog" | puttags $2
+else
+ gettags $1 | puttags $2
+fi
+
# EOF

Return to:

Send suggestions and report system problems to the System administrator.