Mercurial > gemma
view style-templates/upload-styles.sh @ 5593:88a41fc07c97
Merged surveysperbottleneckid
author | Sascha Wilde <wilde@sha-bang.de> |
---|---|
date | Tue, 19 Apr 2022 13:02:45 +0200 |
parents | 136dc9e528c4 |
children |
line wrap: on
line source
#!/bin/bash -e # # This is Free Software under GNU Affero General Public License v >= 3.0 # without warranty, see README.md and license for details. # # SPDX-License-Identifier: AGPL-3.0-or-later # License-Filename: LICENSES/AGPL-3.0.txt # # Copyright (C) 2019 by via donau # – Österreichische Wasserstraßen-Gesellschaft mbH # Software engineering by Intevation GmbH # # Author(s): # * Sascha Wilde <wilde@intevation.de> ME=`basename "$0"` BASEDIR=`dirname "$0"` usage() { cat <<EOF $ME [OPTION]... [input-file]... Upload map styles to gemma. Uses either the given input files or all files in the directory where this script resides. Input files must have the name of a published layer in gemma and the suffix .sld-template. Options: -P, --g_port=GPORT connect to gemma server at GPORT. Default 8000. -g, --g_host=GHOST connect to gemma server on GHOST. Default "localhost". -u, --g_user=GUSER login to gemma as user GUSER. Default "sophie". -d, --extra_dir=DIR search DIR in addition to the default styles directory. This option can be specified multiple times. --g_pw=GPW password for GUSER. Default "so2Phie4". --help display this help and exit EOF } fatal() { echo >&2 "$1" exit 23 } # Defaults: g_port=8000 g_host="localhost" g_user="sophie" g_pw="so2Phie4" declare -a extra_dirs # Parse options: OPTS=`getopt \ -l help,g_port:,g_host:,g_user:,g_pw:,extra_dir: \ -o P:g:u:d: -n "$ME" -- "$@"` [ $? -eq 0 ] || { usage ; exit 1 ; } eval set -- "$OPTS" while true ; do case "$1" in --g_port|-P) g_port="$2" shift 2 ;; --g_host|-g) g_host="$2" shift 2 ;; --g_user|-u) g_user="$2" shift 2 ;; --g_pw) g_pw="$2" shift 2 ;; --extra_dir|-d) extra_dirs+=("$2") shift 2 ;; --help) { usage ; exit 0 ; } ;; --) shift break ;; esac done # Main ------------------------------------------------------------ # Login to gemma server login=$(curl -f -s -S -X POST \ -d "{\"user\":\"${g_user}\",\"password\":\"${g_pw}\"}" \ "http://${g_host}:${g_port}/api/login") token=$(jq -r '.token' <<<"$login") if [ -z "$token" ] then echo "could not login to gemma server" >&2 exit 1 fi roles=$(jq -r '.roles' <<<"$login") basedir=$( dirname $( realpath "${BASH_SOURCE[0]}" )) datadir="${basedir}/." if jq -e 'any(. == "sys_admin")' <<<"$roles" > /dev/null then echo "== Configuring geoserver styles" >&2 if [ $# -gt 0 ]; then files=("$@") else files=($(find "$datadir" "${extra_dirs[@]}" \ -name "*.sld-template" -or -name "*.zip")) fi for file in ${files[@]} do style=$(basename $(basename "$file" .zip) .sld-template) echo "uploading ${style} ..." curl -f -s -S -H "X-Gemma-Auth:${token}" -X POST \ -F style=@"${file}" \ "http://${g_host}:${g_port}/api/geo/style/${style}" done echo 'done.' else echo >&2 'Not authorized as sys_admin' fi