-
Notifications
You must be signed in to change notification settings - Fork 3
/
create.sh
executable file
·66 lines (56 loc) · 1.72 KB
/
create.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
#!/usr/bin/env bash
if [ "$1" == "--help" ]; then
echo "Utility to create Kong plugins with alternative priority."
echo
echo "It will create a NEW plugin identical to the original one,"
echo "but with the new priority."
echo
echo "Usage:"
echo " ${BASH_SOURCE[0]} \"PLUGIN_NAME\" \"NEW_PRIORITY\""
echo
echo " PLUGIN_NAME : name of existing plugin to re-prioritize"
echo " NEW_PRIORITY : the priority the new plugin should have"
echo
echo "The new plugin will have the old name with priority attached."
echo "This new name is mandatory and cannot be changed."
echo
echo "Example:"
echo " ${BASH_SOURCE[0]} \"request-termination\" \"15\""
echo
echo "Will create:"
echo " kong-plugin-request-termination_15-0.1-1.rock"
echo
echo "It can be installed using:"
echo " luarocks install kong-plugin-request-termination_15-0.1-1.rock"
echo
exit 0
fi
PLUGINNAME="$1"
PRIORITY="$2"
if [ "$PLUGINNAME" == "" ]; then
echo "Missing plugin name, rerun with '--help' for info."
exit 1
fi
if [ "$PRIORITY" == "" ]; then
echo "Missing plugin priority, rerun with '--help' for info."
exit 1
fi
docker -v > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Utility 'docker' was not found, please make sure it is installed"
echo "and available in the system path."
echo
exit 1
fi
rm ./template/plugin/*.rock > /dev/null 2>&1
rm ./template/plugin/*.rockspec > /dev/null 2>&1
docker run \
--rm \
--user root \
--volume "$PWD/template:/template" \
--workdir="/template/plugin" \
-e KONG_PRIORITY_NAME="$PLUGINNAME" \
-e KONG_PRIORITY="$PRIORITY" \
kong:3.2.2 \
/usr/local/openresty/luajit/bin/luajit ../priority.lua
mv ./template/plugin/*.rock ./ > /dev/null 2>&1