Skip to content

Commit d23e8fc

Browse files
committed
Added connect-db.sh file
1 parent 9618725 commit d23e8fc

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

scripts/connect-db.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
version="0.1.0"
3+
echo "Connecting to DB....(connect-db.sh v$version)"
4+
5+
if [ "$1" == "-h" ]; then
6+
echo "Usage: $(basename $0)"
7+
exit 0
8+
fi
9+
10+
[ -z "$RG_HOME" ] && RG_HOME='/opt/deploy/sp2'
11+
echo "RG_HOME=$RG_HOME"
12+
myinput=$(cat "$RG_HOME/config/mongo-config.json")
13+
if [ -z "$myinput" ]; then
14+
echo "Could not find DB details file. Exiting"
15+
exit 1
16+
fi
17+
18+
mydbuser=$(jq -r '.db_auth_config.username' <<<"${myinput}")
19+
mydbuserpwd=$(jq -r '.db_auth_config.password' <<<"${myinput}")
20+
21+
if [ -z "$mydbuser" ] || [ -z "$mydbuserpwd" ]; then
22+
echo "Could not find DB details. Exiting"
23+
exit 1
24+
fi
25+
26+
if [ ! -f "$RG_HOME/docker-compose.yml" ]; then
27+
echo "docker-compose.yml does not exist. Exiting"
28+
exit 1
29+
fi
30+
mydocdburl=$(grep DB_HOST "$RG_HOME/docker-compose.yml" | head -1 | sed -e "s/.*DB_HOST=//")
31+
if [ -z "$mydocdburl" ]; then
32+
echo "Could not find DB URL. Exiting"
33+
exit 1
34+
fi
35+
36+
mongo --ssl --host "$mydocdburl:27017" --sslCAFile "$RG_HOME/config/rds-combined-ca-bundle.pem" \
37+
--username "$mydbuser" --password "$mydbuserpwd"

0 commit comments

Comments
 (0)