From b14830e4e3898cf14f70ffd248097bab93fc8d28 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 20 Dec 2013 10:17:31 +0100 Subject: [PATCH] Add command-line script to update a template --- tools/update_template | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 tools/update_template diff --git a/tools/update_template b/tools/update_template new file mode 100755 index 00000000..6fcdb181 --- /dev/null +++ b/tools/update_template @@ -0,0 +1,47 @@ +#!/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 -z "$tpl"; then + tpl="$1" + elif test -z "$cfg"; then + cfg="$1" + else + echo "Unused parameter $1" >&2 + fi + shift +done + +if test -z "$cfg"; 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 1 +fi + +cmd="curl -X PUT -skH Content-Type:application/json --data-binary @- ${tiler_url}/${tpl}?api_key=${apikey}" +if test x${verbose} = xyes; then + cmd="${cmd} -v" +fi +res=`cat ${cfg} | tr '\n' ' ' | ${cmd}` +if test $? -gt 0; then + echo "curl command failed: ${cmd}" +fi + +if test x${verbose} = xyes; then + echo "${res}" +fi + +tok=`echo "$res" | sed 's/.*"template_id":"\([^"]*\)".*/\1/'` +echo $tok