From 6a599ccb5d4e559486f4db3a54ec2b407a108644 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 13 Feb 2014 09:19:19 +0100 Subject: [PATCH] Add script to list templates --- NEWS.md | 1 + tools/list_templates | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 tools/list_templates diff --git a/NEWS.md b/NEWS.md index 75a31ab0..ad315d16 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ Enhancements: * Add script to flush caches (#140) + * Add script to list templates * Add statsd support (#139) * Add support for specifying a varnish password * Avoid sending multiple varnish invalidation at once (#135) diff --git a/tools/list_templates b/tools/list_templates new file mode 100755 index 00000000..a8ee9db9 --- /dev/null +++ b/tools/list_templates @@ -0,0 +1,46 @@ +#!/bin/sh + +verbose=no +tiler_url=http://dev.localhost.lan:8181/tiles/template +apikey=${CDB_APIKEY} + +while test -n "$1"; do + if test "$1" = "-v"; then + verbose=yes + elif test "$1" = "-k"; then + shift + apikey="$1" + elif test "$1" = "-u"; then + shift + tiler_url="$1" + elif test "$1" = "-h" -o "$1" = "-?"; then + echo "Usage: $0 [-v] [-k ] [-u ]" >&2 + echo "Default is ${tiler_url}" >&2 + echo "Default is read from CDB_APIKEY env variable" >&2 + exit 0 + else + echo "Unused parameter $1" >&2 + fi + shift +done + + +cmd="curl -X GET -sk ${tiler_url}?api_key=${apikey}" +if test x${verbose} = xyes; then + cmd="${cmd} -v" +fi +res=`${cmd}` +if test $? -gt 0; then + echo "curl command failed: ${cmd}" +fi + +if test x${verbose} = xyes; then + echo "${res}" +fi + +# Successful response contains no space +echo "$res" | grep " " && { echo $res && exit 1; } + +tok=`echo "$res" | sed 's/.*"template_id":"\([^"]*\)".*/\1/'` +echo $tok +