-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·162 lines (130 loc) · 3.5 KB
/
setup.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
usage() {
echo "Usage: $0 [init|clean]" 1>&2;
echo
exit 1;
}
post_data_for_token()
{
cat <<EOF
{
"name": "$username",
"password": "$password"
}
EOF
}
post_data_for_application()
{
cat <<EOF
{
"application": {
"name": "Test_application 1",
"description": "description",
"redirect_uri": "http://127.0.0.1/complete/fiware/",
"url": "http://127.0.0.1",
"grant_type": [
"authorization_code",
"implicit",
"password"
]
}
}
EOF
}
initialize() {
echo
####################################
# Install jq if it is not installed
####################################
command -v jq >/dev/null || { echo; echo "Need to install jq"; echo; apt-get install -y jq; }
##############################################
# We need to wait until the IDM is Up & Ready
##############################################
echo
echo -n "Waiting to get Up & Ready the IdM service ... "
curl http://127.0.0.1:3000 2>/dev/null >/dev/null
result=$?
while [ "$result" -eq "7" -o "$result" -eq "52" ]; do
curl http://127.0.0.1:3000 2>/dev/null >/dev/null
result=$?
done
tput setaf 2; echo "done"
tput sgr0; echo
###################
# Get Auth Tokens
###################
read -p "Username: " username
echo -n "Password: "
read -s password
echo
token=$( curl -v \
--silent \
-X POST \
-H 'Content-Type: application/json' \
--data-binary "$(post_data_for_token)" \
'http://127.0.0.1:3000/v1/auth/tokens' 2>&1 | awk '/X-Subject-Token: /{print substr($3,0,36)}' )
result=$(curl -v \
--silent \
-X POST \
-H "Content-Type: application/json" \
-H "X-Auth-Token: $token" \
--data-binary "$(post_data_for_application)" \
'http://127.0.0.1:3000/v1/applications' 2>&1 > a.out)
ClientID=$(cat a.out | jq .application.id | sed 's/\"//g')
ClientSecret=$(cat a.out | jq .application.secret | sed 's/\"//g')
echo "Client ID: " $ClientID
echo "Client Secret: " $ClientSecret
rm a.out
echo
docker-compose exec wirecloud sh config-idm.sh $ClientID $ClientSecret
docker-compose exec wirecloud manage.py migrate
docker-compose exec wirecloud manage.py collectstatic
docker-compose restart wirecloud
}
clean_environment() {
echo "WARNING!!! This operation will delete all the local data"
while true; do
read -p "Do you really want to continue [y/N]? " yn
yn=${yn:-no}
case $yn in
[Yy]* )
echo
echo "Removing dockers..."
docker-compose kill
docker-compose rm
docker-compose down
echo
echo " Removing local content..."
rm -rf ./postgres-data
rm -rf ./static
rm -rf ./wirecloud_instance
rm -rf ./mysql-idm
rm -rf ./mongodb
echo
exit
;;
[Nn]* )
echo
exit
;;
* )
echo
echo "Please answer yes or no."
;;
esac
done
}
echo
case "$1" in
init)
echo "Initialize process ..."
initialize
;;
clean)
echo "Cleaning the dockers ..."
clean_environment
;;
*)
usage
;;
esac