Mercurial > gemma
annotate style-templates/upload-styles.sh @ 5637:7f9600ab5461
merge
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 14 Jun 2023 08:45:11 +0200 |
parents | 136dc9e528c4 |
children |
rev | line source |
---|---|
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
1 #!/bin/bash -e |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
2 # |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
3 # This is Free Software under GNU Affero General Public License v >= 3.0 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
4 # without warranty, see README.md and license for details. |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
5 # |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
6 # SPDX-License-Identifier: AGPL-3.0-or-later |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
7 # License-Filename: LICENSES/AGPL-3.0.txt |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
8 # |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
9 # Copyright (C) 2019 by via donau |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
10 # – Österreichische Wasserstraßen-Gesellschaft mbH |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
11 # Software engineering by Intevation GmbH |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
12 # |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
13 # Author(s): |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
14 # * Sascha Wilde <wilde@intevation.de> |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
15 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
16 ME=`basename "$0"` |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
17 BASEDIR=`dirname "$0"` |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
18 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
19 usage() |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
20 { |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
21 cat <<EOF |
4917
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
22 $ME [OPTION]... [input-file]... |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
23 |
4917
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
24 Upload map styles to gemma. Uses either the given input files or all files |
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
25 in the directory where this script resides. Input files must have the name |
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
26 of a published layer in gemma and the suffix .sld-template. |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
27 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
28 Options: |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
29 -P, --g_port=GPORT connect to gemma server at GPORT. Default 8000. |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
30 -g, --g_host=GHOST connect to gemma server on GHOST. Default "localhost". |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
31 -u, --g_user=GUSER login to gemma as user GUSER. Default "sophie". |
4986
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
32 -d, --extra_dir=DIR search DIR in addition to the default styles directory. |
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
33 This option can be specified multiple times. |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
34 --g_pw=GPW password for GUSER. Default "so2Phie4". |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
35 --help display this help and exit |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
36 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
37 EOF |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
38 } |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
39 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
40 fatal() |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
41 { |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
42 echo >&2 "$1" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
43 exit 23 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
44 } |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
45 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
46 # Defaults: |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
47 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
48 g_port=8000 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
49 g_host="localhost" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
50 g_user="sophie" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
51 g_pw="so2Phie4" |
4986
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
52 declare -a extra_dirs |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
53 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
54 # Parse options: |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
55 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
56 OPTS=`getopt \ |
4986
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
57 -l help,g_port:,g_host:,g_user:,g_pw:,extra_dir: \ |
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
58 -o P:g:u:d: -n "$ME" -- "$@"` |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
59 [ $? -eq 0 ] || { usage ; exit 1 ; } |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
60 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
61 eval set -- "$OPTS" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
62 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
63 while true ; do |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
64 case "$1" in |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
65 --g_port|-P) |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
66 g_port="$2" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
67 shift 2 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
68 ;; |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
69 --g_host|-g) |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
70 g_host="$2" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
71 shift 2 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
72 ;; |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
73 --g_user|-u) |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
74 g_user="$2" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
75 shift 2 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
76 ;; |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
77 --g_pw) |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
78 g_pw="$2" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
79 shift 2 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
80 ;; |
4986
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
81 --extra_dir|-d) |
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
82 extra_dirs+=("$2") |
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
83 shift 2 |
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
84 ;; |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
85 --help) |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
86 { usage ; exit 0 ; } |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
87 ;; |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
88 --) |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
89 shift |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
90 break |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
91 ;; |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
92 esac |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
93 done |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
94 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
95 # Main ------------------------------------------------------------ |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
96 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
97 # Login to gemma server |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
98 login=$(curl -f -s -S -X POST \ |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
99 -d "{\"user\":\"${g_user}\",\"password\":\"${g_pw}\"}" \ |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
100 "http://${g_host}:${g_port}/api/login") |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
101 token=$(jq -r '.token' <<<"$login") |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
102 if [ -z "$token" ] |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
103 then |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
104 echo "could not login to gemma server" >&2 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
105 exit 1 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
106 fi |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
107 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
108 roles=$(jq -r '.roles' <<<"$login") |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
109 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
110 basedir=$( dirname $( realpath "${BASH_SOURCE[0]}" )) |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
111 datadir="${basedir}/." |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
112 |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
113 if jq -e 'any(. == "sys_admin")' <<<"$roles" > /dev/null |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
114 then |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
115 echo "== Configuring geoserver styles" >&2 |
4917
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
116 if [ $# -gt 0 ]; then |
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
117 files=("$@") |
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
118 else |
4986
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
119 files=($(find "$datadir" "${extra_dirs[@]}" \ |
136dc9e528c4
Added option --extra_dir to upload-styles.sh script.
Sascha Wilde <wilde@intevation.de>
parents:
4985
diff
changeset
|
120 -name "*.sld-template" -or -name "*.zip")) |
4917
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
121 fi |
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
122 for file in ${files[@]} |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
123 do |
4920
a9fac2394238
Allow script based upload of zipped styles
Tom Gottfried <tom@intevation.de>
parents:
4917
diff
changeset
|
124 style=$(basename $(basename "$file" .zip) .sld-template) |
4917
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
125 echo "uploading ${style} ..." |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
126 curl -f -s -S -H "X-Gemma-Auth:${token}" -X POST \ |
4917
0098cfd602be
Allow uploading of single SLD templates
Tom Gottfried <tom@intevation.de>
parents:
4631
diff
changeset
|
127 -F style=@"${file}" \ |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
128 "http://${g_host}:${g_port}/api/geo/style/${style}" |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
129 done |
4631
15372dd971e9
Made upload-styles.sh a little more verbose.
Sascha Wilde <wilde@intevation.de>
parents:
4481
diff
changeset
|
130 echo 'done.' |
4481
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
131 else |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
132 echo >&2 'Not authorized as sys_admin' |
43c52a2d4f17
Add style-templates for geoserver
Bernhard Reiter <bernhard@intevation.de>
parents:
diff
changeset
|
133 fi |