-
Notifications
You must be signed in to change notification settings - Fork 0
/
dscmd-trigger
executable file
·109 lines (91 loc) · 2.64 KB
/
dscmd-trigger
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Generate a JSON string and send it to a Docserv² instance.
#
# To use:
#
# 1-Provide a file `.dscmd-server.conf` in your home directory. Include
# the following contents:
# server=http://server.address # server address
# port=8080 # server port
# validtargets=target,names # target server names, as in Docserv2 INI
# 2-Run this script:
# ./$0 --targets=TARGET --products=PRODUCTS --docsets=DOCSETS --langs=LANGS
#
# * all parameters are mandatory
# * "=" characters are mandatory
# * multiple values may be comma-separated or space-separated
me=$(test -L $(realpath $0) && readlink $(realpath $0) || echo $(realpath $0))
mydir=$(dirname $me)
config=$HOME/.dscmd-server.conf
out() {
>&2 echo -e "$1"
exit 1
}
app_help() {
sed -rn '/#!/{n; p; :loop n; p; /^[ \t]*$/q; b loop}' $me | sed -r -e 's/^# ?//' -e "s/\\\$0/$(basename $me)/"
exit
}
products=
docsets=
langs=
for i in "$@"
do
case $i in
-h|--help)
app_help
;;
--targets=*|--target=*|-t=*)
targets=$(echo "$i" | sed -r -e 's/^[^=]+=//' -e 's/,/ /g')
;;
--products=*|--product=*|-p=*)
products=$(echo "$i" | sed -r -e 's/^[^=]+=//' -e 's/,/ /g')
;;
--docsets=*|--docset=*|-d=*)
docsets=$(echo "$i" | sed -r -e 's/^[^=]+=//' -e 's/,/ /g')
;;
--langs=*|--lang=*|-l=*)
langs=$(echo "$i" | sed -r -e 's/^[^=]+=//' -e 's/,/ /g')
;;
*)
unknown+=" $i\n"
;;
esac
done
if [[ -f $config ]]; then
. $config
else
out "No $config found. See --help."
fi
([[ ! "$validtargets" ]] || [[ ! "$server" ]] || [[ ! "$port" ]]) && \
out "$config does not include all necessary parameters. See --help."
[[ "$unknown" ]] &&
out "Unknown command-line parameters present:\n${unknown}See --help."
([[ ! "$targets" ]] || [[ ! "$products" ]] || [[ ! "$docsets" ]] || [[ ! "$langs" ]]) && \
out "Missing at least one command-line parameter. See --help."
for target in $targets; do
[[ ! $(echo " $validtargets " | sed 's/,/ /g' | grep -oP " $target ") ]] && \
out "Target $target is unknown."
done
# ---
json='['
for target in $targets; do
for product in $products; do
for docset in $docsets; do
for lang in $langs; do
json+='{'
json+='"target":"'$target'",'
json+='"product":"'$product'",'
json+='"docset":"'$docset'",'
json+='"lang":"'$lang'"'
json+='},'
done
done
done
done
json=$(echo "$json" | sed -r 's/,$/]/')
curl \
--header "Content-Type: application/json" \
--request POST \
--data "$json" \
${server}:${port}
echo -e "Sent JSON to $server:$port:\n$json"