-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.sos.sh
90 lines (84 loc) · 2.05 KB
/
post.sos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# PURPOSE: call irea SOS service given post request file(name)
# USAGE: <script name> <post request filename>
# the script writes the response content in the working directory and opens it with the default xml editor
# AUTHOR: tagliolato.p@irea.cnr.it
display_help() {
echo "Usage: $(basename $0) [-h] [-a <application>] [-e <sos endpoint>] <sos request file>"
echo "-a open resulting xml within the given application"
echo "-e post request to the given sos endpoint"
echo "-h display help"
}
# check envir
for tool in getopts curl open; do
if ! type $tool >/dev/null 2>&1;
then
echo " ERROR: \"$tool\" not found." >&2
echo " This is needed by $(basename $0) to work. Check your" >&2
echo " \$PATH variable or install the tool \"$tool\"." >&2
#echo " try the following:"
#echo " export PATH=\"\$PATH:/usr/local/pgsql/bin\" "
exit 2
fi
done
while getopts "a:e:h" opt; do
case $opt in
a)
OPEN="apri"
XMLApp="$OPTARG"
if [ "$XMLApp" = "" ]
then
echo "OPEN WITH default XML application"
else
echo "OPEN WITH = $XMLApp"
fi
shift $((OPTIND-1))
;;
e)
ENDPOINT="$OPTARG"
if [ "$ENDPOINT" = "" ]
then
ENDPOINT = "http://10.0.0.100/observations/sos"
echo "POST to default ENDPOINT: $ENDPOINT"
else
echo "ENDPOINT = $ENDPOINT"
fi
shift $((OPTIND-1))
;;
h)
display_help
exit 0
;;
\?)
echo " Invalid option: -$OPTARG" >&2
display_help && exit 2
;;
esac
done
# check input
echo "OPEN= $OPEN"
echo "ENDPOINT=$ENDPOINT"
if [ "$1" == "" ]
then
display_help
echo " input mancante $1" >&2
#echo "$@" >&2
exit 1
else
if [ -f $1 ]
then
curl -v -X POST -d @$1 $ENDPOINT --header "Content-Type:text/xml" > $1.SOS.response.xml
if [ "$OPEN" == "apri" ]
then
if [ "$XMLApp" != "" ]
then
open $1.SOS.response.xml -a $XMLApp
else
open $1.SOS.response.xml
fi
fi
else
echo " la risorsa $1 non esiste" >&2
exit 2
fi
fi