forked from SAP-archive/teched2020-developer-keynote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault-env-gen
executable file
·63 lines (48 loc) · 1.6 KB
/
default-env-gen
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
#!/usr/bin/env bash
# Generate a default-env.json file - default-env-gen
# Expects a single mandatory argument - a temporary app name
# Produces a default-env.json file containing the VCAP_SERVICES
# JSON data.
# As a minimum, it will bind the enterprise messaging service
# instance. It will also check for a destination service
# instance and an xsuaa service instance, with specific names,
# and bind those if it finds them.
declare instance_enterprise_messaging=emdev
declare targetfilename=default-env.json
declare sedcommandfile=default-env-gen.sed
# shellcheck disable=SC2034
declare instance_destination=destination-lite
# shellcheck disable=SC2034
declare instance_xsuaa=xsuaa-application
main() {
local appname=$1
local instance=${2:-$instance_enterprise_messaging}
# Remove any existing dir and app
rmdir "$appname" 2>/dev/null
cf d -f "$appname" 2>/dev/null
# Create new temp dir and deploy
mkdir "$appname"
cf push -c null \
-k 64M \
-m 32M \
--no-route \
--no-start \
"$appname" "$appname"
# Remove dir
rmdir "$appname" 2>/dev/null
# Bind the SAP Enterprise Messaging service instance to the app
cf bind-service "$appname" "$instance"
# If present, also bind the destination and xsuaa service instances
for i in destination xsuaa; do
local name="instance_$i"
cf service "${!name}" > /dev/null 2>&1 \
&& cf bind-service "$appname" "${!name}"
done
# Request environment info
cf env "$appname" | sed -n -f "$sedcommandfile" > "$targetfilename"
}
if [[ $# -eq 0 ]]; then
echo Usage: "$(basename "$0") <temporary-app-name>"
exit 1
fi
main "$@"