forked from Tangerine-Community/Tangerine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·113 lines (105 loc) · 3.96 KB
/
entrypoint.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
#!/usr/bin/env bash
# Send nginx logs to docker logs.
tail -f /var/log/nginx/access.log &
tail -f /var/log/nginx/error.log &
echo ""
echo ""
echo ""
echo "Setting up database user"
echo "$T_ADMIN = $T_PASS" >> /etc/couchdb/local.ini
sudo chown -R couchdb /var/run/couchdb
couchdb -k
couchdb &
echo ""
echo ""
echo ""
echo "We will relax while the couch gets ready."
while true; do nc -vz $T_COUCH_HOST 5984 > /dev/null && break; done
echo ""
echo ""
echo ""
echo "CouchDB is ready"
echo ""
echo ""
echo ""
echo "Creating user1 at http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/_users/org.couchdb.user:$T_USER1"
curl -HContent-Type:application/json -vXPUT "http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/_users/org.couchdb.user:$T_USER1" --data-binary '{"_id": "'"org.couchdb.user:$T_USER1"'","name": "'"$T_USER1"'","roles": ["manager"],"type": "user","password": "'"$T_USER1_PASSWORD"'"}'
echo ""
echo ""
echo ""
echo "Push the ojai design doc"
cd /tangerine-server/editor/app
couchapp push
echo ""
echo ""
echo ""
echo "Insert documents used for new groups."
cd /tangerine-server/
sed "s#INSERT_HOST_NAME#"$T_HOST_NAME"#g" ./documents-for-new-groups/configuration.template | sed "s#INSERT_TREE_URL#"$T_TREE_URL"#g" | sed "s#INSERT_PROTOCOL#"$T_PROTOCOL"#g" > ./documents-for-new-groups/configuration.json
sed "s#INSERT_HOST_NAME#"$T_HOST_NAME"#g" ./documents-for-new-groups/settings.template | sed "s#INSERT_PROTOCOL#"$T_PROTOCOL"#g" > ./documents-for-new-groups/settings.json
curl -XPUT -d "@./documents-for-new-groups/LocationList.json" -H "Content-Type: application/json" http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/tangerine/location-list
curl -XPUT -d "@./documents-for-new-groups/acl.json" -H "Content-Type: application/json" http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/tangerine/acl
curl -XPUT -d "@./documents-for-new-groups/settings.json" -H "Content-Type: application/json" http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/tangerine/settings
curl -XPUT -d "@./documents-for-new-groups/templates.json" -H "Content-Type: application/json" http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/tangerine/templates
curl -XPUT -d "@./documents-for-new-groups/configuration.json" -H "Content-Type: application/json" http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/tangerine/configuration
echo ""
echo ""
echo ""
echo ""
echo "Update globals in group databases."
tangerine deploy-globals
echo ""
echo ""
echo ""
echo ""
echo "Locking down tangerine database in case it is not already secured."
curl -XPOST -d \
'{ "_id": "_design/_auth", "language": "javascript", "validate_doc_update": "function(newDoc, oldDoc, userCtx, secObj) { if (userCtx.roles.indexOf(\"_admin\") === -1) { throw({forbidden: \"Only admins may update this database.\"}); } }" }' \
-H "Content-Type: application/json" \
http://$T_ADMIN:$T_PASS@localhost:5984/tangerine
if [ $PUSH_COUCHAPP_TO_ALL_GROUPS_ON_ENTRYPOINT = true ]
then
echo ""
echo ""
echo ""
echo "Push design doc and default docs to all group databases"
curl http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/_all_dbs | jq '.' | grep 'group-' | sed -e 's/\"//g' | sed -e 's/,//' | xargs -I {} couchapp push http://$T_ADMIN:$T_PASS@$T_COUCH_HOST:$T_COUCH_PORT/{}
echo ""
echo ""
echo ""
fi
echo "Push the server couchapp"
cd /tangerine-server/server/couchapp
couchapp push
echo ""
echo ""
echo ""
echo "Go nginx!"
sed -i -e "s#INSERT_PROTOCOL#"$T_PROTOCOL"#g" /etc/nginx/sites-available/tangerine.conf
service nginx start
service nginx reload
echo ""
echo ""
echo ""
if [ "$T_RUN_MODE" = "production" ]
then
echo "Start the pm2 process"
cd /tangerine-server
pm2 start --no-daemon ecosystem.json
fi
if [ "$T_RUN_MODE" = "development" ]
then
echo "Start the pm2 process"
cd /tangerine-server
pm2 start --no-daemon ecosystem.json &
echo ""
echo ""
echo ""
echo "Monitoring for editor chages..."
cd /tangerine-server/editor && npm run debug &
echo ""
echo ""
echo ""
echo "Monitoring for client chages..."
cd /tangerine-server/client && npm run debug
fi