Skip to content

Commit

Permalink
Let us use predefined superservice credentials (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague committed Jun 11, 2020
1 parent bc96a35 commit 310558b
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions scripts/installNuve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,39 @@ install_nuve(){
cd $CURRENT_DIR
}

create_credentials(){
mongo $dbURL --eval "db.services.insert({name: 'superService', key: '$RANDOM', rooms: []})"
SERVID=`mongo $dbURL --quiet --eval "db.services.findOne()._id"`
SERVKEY=`mongo $dbURL --quiet --eval "db.services.findOne().key"`
SERVID=`echo $SERVID| cut -d'"' -f 2`
SERVID=`echo $SERVID| cut -d'"' -f 1`
}
add_credentials(){
RESULT=`mongo $dbURL --quiet --eval "db.services.insert({name: 'superService', _id: ObjectId('$SERVID'), key: '$SERVKEY', rooms: []})"`
echo $RESULT
NOTFOUND=`echo $RESULT | grep "writeError"`
if [[ ! -z "$NOTFOUND" ]]; then
SERVID=""
SERVKEY=""
fi
}

check_credentials(){
RESULT=`mongo $dbURL --quiet --eval "db.services.find({name: 'superService', _id: ObjectId('$SERVID'), key: '$SERVKEY', rooms: []})"`
echo $RESULT
if [[ -z "$RESULT" ]]; then
add_credentials
fi
}

get_or_create_superservice_credentials(){
if [[ -z "$SERVID" && -z "$SERVKEY" ]]; then
create_credentials
else
check_credentials
fi
}

populate_mongo(){

if ! pgrep mongod; then
Expand All @@ -44,12 +77,15 @@ populate_mongo(){
dbURL=`echo $dbURL| cut -d'"' -f 1`

echo [licode] Creating superservice in $dbURL
mongo $dbURL --eval "db.services.insert({name: 'superService', key: '$RANDOM', rooms: []})"
SERVID=`mongo $dbURL --quiet --eval "db.services.findOne()._id"`
SERVKEY=`mongo $dbURL --quiet --eval "db.services.findOne().key"`
get_or_create_superservice_credentials

if [[ -z "$SERVID" && -z "$SERVKEY" ]]; then
echo "We could not get or create superservice credentials"
exit 1
else
echo "We got superservice credentials"
fi

SERVID=`echo $SERVID| cut -d'"' -f 2`
SERVID=`echo $SERVID| cut -d'"' -f 1`

if [ -f "$BUILD_DIR/mongo.log" ]; then
echo "Mongo Logs: "
Expand Down

0 comments on commit 310558b

Please sign in to comment.