-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_plugin.sh
executable file
·114 lines (92 loc) · 2.88 KB
/
install_plugin.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
#
# Obdi - a REST interface and GUI for deploying software
# Copyright (C) 2014 Mark Clarkson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# helloworld-runscript plugin
[[ -z $guid ]] && {
echo "ERROR: environment variable 'guid' must be set."
exit 1
}
proto="https"
opts="-k -s" # don't check ssl cert, silent
ipport="127.0.0.1:443"
#
# Create a temporary file and a trap to delete it
#
t="/tmp/install_helloworld_runscript_$$"
touch $t
[[ $? -ne 0 ]] && {
echo "Could not create temporary file. Aborting."
exit 1
}
trap "rm -f -- '$t'" EXIT
#
# Create a custom environment capability to which a worker
# URL can be added.
#
curl -k -d '{
"Code":"HELLOWORLD_RUNSCRIPT_WORKER",
"Desc":"Location of the worker helloworld-runscript will use.",
"IsWorkerDef":true
}' $proto://$ipport/api/admin/$guid/envcaps
#
# Create the plugin entry in obdi, so it can be shown in the sidebar
#
curl -k -d '{
"Name":"helloworld-runscript",
"Desc":"Hello World plugin.",
"HasView":1,
"Parent":"helloworld"
}' $proto://$ipport/api/admin/$guid/plugins | tee $t
# Grab the id of the last insert
id=`grep Id $t | grep -Eo "[0-9]+"`
#
# Add the AJS controller files
#
# These need to be loaded when the application starts
#
curl -k -d '{
"Name":"helloworld-runscript.js",
"Desc":"Controller for HelloWorld Runscript.",
"Type":1,
"PluginId":'"$id"',
"Url":"helloworld-runscript/js/controllers/helloworld-runscript.js"
}' $proto://$ipport/api/admin/$guid/files
#
# Add the scripts, removing comment lines (#) and empty lines
#
script="helloworldrunscript-show.sh"
source=`sed '1n;/^\s*#/d;/^$/d;' scripts/$script | base64 -w 0`
curl -k $proto://$ipport/api/admin/$guid/scripts?name=$script | tee $t
# Grab the id of the last insert
id=`grep Id $t | grep -Eo "[0-9]+"`
if [[ -z $id ]]; then
curl -k -d '{
"Desc": "Shows some information. Arg1 - Must be set to any value",
"Name": "'"$script"'",
"Source": "'"$source"'"
}' $proto://$ipport/api/admin/$guid/scripts
else
curl -k -X PUT -d '{ "Source": "'"$source"'" }' \
$proto://$ipport/api/admin/$guid/scripts/$id
fi
# --
# Delete the temporary file and delete the trap
rm -f -- "$t"
trap - EXIT
# Now force all the golang plugins to compile...
curl -k "$proto://$ipport/api/admin/$guid/helloworld-runscript/helloworld-runscript"