comparison style-templates/upload-styles.sh @ 4917:0098cfd602be fairway-marks-import

Allow uploading of single SLD templates
author Tom Gottfried <tom@intevation.de>
date Thu, 13 Feb 2020 11:37:22 +0100
parents 15372dd971e9
children a9fac2394238
comparison
equal deleted inserted replaced
4916:d456621404c2 4917:0098cfd602be
17 BASEDIR=`dirname "$0"` 17 BASEDIR=`dirname "$0"`
18 18
19 usage() 19 usage()
20 { 20 {
21 cat <<EOF 21 cat <<EOF
22 $ME [OPTION]... 22 $ME [OPTION]... [input-file]...
23 23
24 Upload map styles to gemma. 24 Upload map styles to gemma. Uses either the given input files or all files
25 in the directory where this script resides. Input files must have the name
26 of a published layer in gemma and the suffix .sld-template.
25 27
26 Options: 28 Options:
27 -P, --g_port=GPORT connect to gemma server at GPORT. Default 8000. 29 -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". 30 -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". 31 -u, --g_user=GUSER login to gemma as user GUSER. Default "sophie".
81 break 83 break
82 ;; 84 ;;
83 esac 85 esac
84 done 86 done
85 87
86 if [ $# != 0 ] ; then
87 { usage ; exit 23 ; }
88 fi
89
90 # Main ------------------------------------------------------------ 88 # Main ------------------------------------------------------------
91 89
92 # Login to gemma server 90 # Login to gemma server
93 login=$(curl -f -s -S -X POST \ 91 login=$(curl -f -s -S -X POST \
94 -d "{\"user\":\"${g_user}\",\"password\":\"${g_pw}\"}" \ 92 -d "{\"user\":\"${g_user}\",\"password\":\"${g_pw}\"}" \
106 datadir="${basedir}/." 104 datadir="${basedir}/."
107 105
108 if jq -e 'any(. == "sys_admin")' <<<"$roles" > /dev/null 106 if jq -e 'any(. == "sys_admin")' <<<"$roles" > /dev/null
109 then 107 then
110 echo "== Configuring geoserver styles" >&2 108 echo "== Configuring geoserver styles" >&2
111 for style in $(basename -s .sld-template $(ls $datadir/*.sld-template)) 109 if [ $# -gt 0 ]; then
110 files=("$@")
111 else
112 files=($(ls $datadir/*.sld-template))
113 fi
114 for file in ${files[@]}
112 do 115 do
113 echo "uploading $style ..." 116 style=$(basename "$file" .sld-template)
117 echo "uploading ${style} ..."
114 curl -f -s -S -H "X-Gemma-Auth:${token}" -X POST \ 118 curl -f -s -S -H "X-Gemma-Auth:${token}" -X POST \
115 -F style=@"${datadir}/${style}.sld-template" \ 119 -F style=@"${file}" \
116 "http://${g_host}:${g_port}/api/geo/style/${style}" 120 "http://${g_host}:${g_port}/api/geo/style/${style}"
117 done 121 done
118 echo 'done.' 122 echo 'done.'
119 else 123 else
120 echo >&2 'Not authorized as sys_admin' 124 echo >&2 'Not authorized as sys_admin'