|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +/wait.sh |
| 4 | + |
| 5 | +response=$(curl --write-out %{http_code} --silent --output /dev/null http://couchdb:5984/visualizer) |
| 6 | + |
| 7 | +if [ ${response} = "404" ] |
| 8 | +then |
| 9 | + |
| 10 | +echo "Database is not instantiated. Create it." |
| 11 | + |
| 12 | +curl -X POST -H "Content-Type: application/json" http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/_cluster_setup -d '{"action": "finish_cluster"}' |
| 13 | + |
| 14 | +# Init rest-on-couch users |
| 15 | +curl -X POST http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/_users \ |
| 16 | + -H 'Content-Type: application/json' \ |
| 17 | + -d '{ "_id": "org.couchdb.user:rest-on-couch", "name": "rest-on-couch", "type": "user", "roles": [], "password": "'${COUCHDB_PASSWORD}'" }' |
| 18 | + |
| 19 | +curl -X POST http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/_users \ |
| 20 | + -H 'Content-Type: application/json' \ |
| 21 | + -d '{ "_id": "org.couchdb.user:[email protected]", "name": "[email protected]", "type": "user", "roles": [], "password": "'${COUCHDB_PASSWORD}'" }' |
| 22 | + |
| 23 | + |
| 24 | +# Init couchdb databases and security setup, and create rest-on-couch groups (they all can be edited later) |
| 25 | + |
| 26 | +echo "Create visualizer database" |
| 27 | +curl -X PUT http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/visualizer |
| 28 | +echo "Create groups in visualizer database" |
| 29 | +curl -X POST http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/visualizer \ |
| 30 | + -H 'Content-Type: application/json' \ |
| 31 | + -d '{"$type": "group", "$owners": ["[email protected]"], "name": "anonymousRead", "users": [], "rights": ["read"], "$lastModification": "[email protected]", "$modificationDate": 0, "$creationDate": 0}'; |
| 32 | +curl -X POST http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/visualizer \ |
| 33 | + -H 'Content-Type: application/json' \ |
| 34 | + -d '{"$type": "group", "$owners": ["[email protected]"], "name": "anyuserRead", "users": [], "rights": ["read"], "$lastModification": "[email protected]", "$modificationDate": 0, "$creationDate": 0}'; |
| 35 | + |
| 36 | +echo "Create default groups in visualizer" |
| 37 | +curl -X PUT http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/visualizer/defaultGroups \ |
| 38 | + -H 'Content-Type: application/json' \ |
| 39 | + -d '{"_id": "defaultGroups","$type": "db","anonymous": ["anonymousRead"],"anyuser": ["anyuserRead"]}' |
| 40 | + |
| 41 | +echo "Setup visualizer database _security" |
| 42 | +curl -X PUT http://${COUCHDB_USER}:${COUCHDB_PASSWORD}@couchdb:5984/visualizer/_security \ |
| 43 | + -H 'Content-Type: application/json' \ |
| 44 | + -d '{ "admins": { "names": ["rest-on-couch"], "roles": [] }, "members": { "names": ["rest-on-couch"], "roles": [] } }' |
| 45 | + |
| 46 | + |
| 47 | +fi |
0 commit comments