This repository has been archived by the owner on Nov 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
setup_functions.sh
executable file
·140 lines (115 loc) · 4.06 KB
/
setup_functions.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
#
# Copyright 2016 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Color vars to be used in shell script output
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
NC='\033[0m'
# load configuration variables
source .env
# capture the namespace where actions will be created
# as we need to pass it to our change listener
CURRENT_NAMESPACE=`ibmcloud fn property get --namespace | awk '{print $3}'`
echo "Current namespace is $CURRENT_NAMESPACE."
function usage() {
echo -e "${YELLOW}Usage: $0 [--install,--uninstall,--reinstall,--env]${NC}"
}
function install() {
echo -e "${YELLOW}Installing..."
echo "Creating image_db package"
ibmcloud fn package create image_db
echo "Adding VCAP_SERVICES as parameter"
ibmcloud fn package update image_db\
--param cloudantUrl https://$CLOUDANT_USERNAME:$CLOUDANT_PASSWORD@$CLOUDANT_HOST\
--param cloudantDbName $CLOUDANT_DB\
--param watsonKey $VR_KEY\
--param watsonClassifiers $VR_CLASSIFIERS\
--param functionsHost $FUNCTIONS_APIHOST\
--param functionsAuth $FUNCTIONS_AUTHORIZATION
# we will need to listen to cloudant event
echo "Binding cloudant"
ibmcloud fn package bind /whisk.system/cloudant \
image_db-cloudant\
--param username $CLOUDANT_USERNAME\
--param password $CLOUDANT_PASSWORD\
--param host $CLOUDANT_HOST
echo "Creating trigger"
echo ": $CLOUDANT_DB"
ibmcloud fn trigger create image_db-cloudant-update-trigger --feed image_db-cloudant/changes --param dbname $CLOUDANT_DB
echo "Creating actions"
ibmcloud fn action create image_db/analysis analysis.js
# No Longer Needed
#ibmcloud fn action create image_db/dataCleaner dataCleaner.js
echo "Creating change listener action"
#ibmcloud fn action create image_db-cloudant-changelistener changelistener.js --param targetNamespace $CURRENT_NAMESPACE
#recently added to address removal of includeDoc support
echo "Creating action sequence"
#ibmcloud fn action create sequenceAction --sequence image_db-cloudant/read,image_db-cloudant
ibmcloud fn action create sequenceAction --sequence image_db/analysis
echo "Enabling change listener"
#ibmcloud fn rule create image_db-rule image_db-cloudant-update-trigger image_db-cloudant-changelistener
ibmcloud fn rule create image_db-rule image_db-cloudant-update-trigger image_db/analysis
#echo "Set Cloudant Param on Trigger"
#echo -e $CLOUDANT_DB
#ibmcloud fn trigger update image_db-cloudant-update-trigger --param dbname $CLOUDANT_DB
echo -e "${GREEN}Install Complete${NC}"
ibmcloud fn list
}
function uninstall() {
echo -e "${RED}Uninstalling..."
echo "Removing actions..."
ibmcloud fn action delete image_db/analysis
#ibmcloud fn action delete image_db/dataCleaner
echo "Removing rule..."
ibmcloud fn rule disable image_db-rule
ibmcloud fn rule delete image_db-rule
#echo "Removing change listener..."
#ibmcloud fn action delete image_db-cloudant-changelistener
echo "Removing trigger..."
ibmcloud fn trigger delete image_db-cloudant-update-trigger
echo "Removing packages..."
ibmcloud fn package delete image_db-cloudant
ibmcloud fn package delete image_db
echo -e "${GREEN}Uninstall Complete${NC}"
ibmcloud fn list
}
function showenv() {
echo -e "${YELLOW}"
echo CLOUDANT_USERNAME=$CLOUDANT_USERNAME
echo CLOUDANT_PASSWORD=$CLOUDANT_PASSWORD
echo CLOUDANT_HOST=$CLOUDANT_HOST
echo CLOUDANT_DB=$CLOUDANT_DB
echo VR_KEY=$VR_KEY
echo -e "${NC}"
}
case "$1" in
"--install" )
install
;;
"--uninstall" )
uninstall
;;
"--reinstall" )
uninstall
install
;;
"--env" )
showenv
;;
* )
usage
;;
esac