comparison style-templates/upload-styles.sh @ 4537:e0d04cd8f992 iso-areas

Add SLD templates dir for geoserver with one template * Add script to upload SLD templates to gemma. * Add sounding_results_area.sld-template for polygons, still visible at all zoom level for debugging (see xml commented out line).
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 25 Sep 2019 22:01:05 +0200
parents
children 15372dd971e9
comparison
equal deleted inserted replaced
4536:3130c005abef 4537:e0d04cd8f992
1 #!/bin/bash -e
2 #
3 # This is Free Software under GNU Affero General Public License v >= 3.0
4 # without warranty, see README.md and license for details.
5 #
6 # SPDX-License-Identifier: AGPL-3.0-or-later
7 # License-Filename: LICENSES/AGPL-3.0.txt
8 #
9 # Copyright (C) 2019 by via donau
10 # – Österreichische Wasserstraßen-Gesellschaft mbH
11 # Software engineering by Intevation GmbH
12 #
13 # Author(s):
14 # * Sascha Wilde <wilde@intevation.de>
15
16 ME=`basename "$0"`
17 BASEDIR=`dirname "$0"`
18
19 usage()
20 {
21 cat <<EOF
22 $ME [OPTION]...
23
24 Upload map styles to gemma.
25
26 Options:
27 -P, --g_port=GPORT connect to gemma server at GPORT. Default 8000.
28 -g, --g_host=GHOST connect to gemma server on GHOST. Default "localhost".
29 -u, --g_user=GUSER login to gemma as user GUSER. Default "sophie".
30 --g_pw=GPW password for GUSER. Default "so2Phie4".
31 --help display this help and exit
32
33 EOF
34 }
35
36 fatal()
37 {
38 echo >&2 "$1"
39 exit 23
40 }
41
42 # Defaults:
43
44 g_port=8000
45 g_host="localhost"
46 g_user="sophie"
47 g_pw="so2Phie4"
48
49 # Parse options:
50
51 OPTS=`getopt \
52 -l help,g_port:,g_host:,g_user:,g_pw: \
53 -o P:g:u: -n "$ME" -- "$@"`
54 [ $? -eq 0 ] || { usage ; exit 1 ; }
55
56 eval set -- "$OPTS"
57
58 while true ; do
59 case "$1" in
60 --g_port|-P)
61 g_port="$2"
62 shift 2
63 ;;
64 --g_host|-g)
65 g_host="$2"
66 shift 2
67 ;;
68 --g_user|-u)
69 g_user="$2"
70 shift 2
71 ;;
72 --g_pw)
73 g_pw="$2"
74 shift 2
75 ;;
76 --help)
77 { usage ; exit 0 ; }
78 ;;
79 --)
80 shift
81 break
82 ;;
83 esac
84 done
85
86 if [ $# != 0 ] ; then
87 { usage ; exit 23 ; }
88 fi
89
90 # Main ------------------------------------------------------------
91
92 # Login to gemma server
93 login=$(curl -f -s -S -X POST \
94 -d "{\"user\":\"${g_user}\",\"password\":\"${g_pw}\"}" \
95 "http://${g_host}:${g_port}/api/login")
96 token=$(jq -r '.token' <<<"$login")
97 if [ -z "$token" ]
98 then
99 echo "could not login to gemma server" >&2
100 exit 1
101 fi
102
103 roles=$(jq -r '.roles' <<<"$login")
104
105 basedir=$( dirname $( realpath "${BASH_SOURCE[0]}" ))
106 datadir="${basedir}/."
107
108 if jq -e 'any(. == "sys_admin")' <<<"$roles" > /dev/null
109 then
110 echo "== Configuring geoserver styles" >&2
111 for style in $(basename -s .sld-template $(ls $datadir/*.sld-template))
112 do
113 curl -f -s -S -H "X-Gemma-Auth:${token}" -X POST \
114 -F style=@"${datadir}/${style}.sld-template" \
115 "http://${g_host}:${g_port}/api/geo/style/${style}"
116 done
117 else
118 echo >&2 'Not authorized as sys_admin'
119 fi