-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·107 lines (107 loc) · 6.94 KB
/
install.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
#!/bin/bash
#installation bash script
#
#${1} is couchbase database admin username
#${2} is couchbase database admin password
#${3} is couchbase database ip (local private ip ie 192.168.0.15)
#${4} is couchbase database loopback IP
#${5} is openmoney API admin username
#${6} is openmoney API admin password
#${7} is openmoney API admin email
#${8} is openmoney API root namespace
#${9} is openmoney API root currency
#
#example execution:
#./install.sh admin password 127.0.0.1 127.0.0.1 admin password [email protected] cc cc
#or
#./install.sh
#
#Setting script variables.
COUCHBASE_ADMIN_USERNAME=${1:-admin}
COUCHBASE_ADMIN_PASSWORD=${2:-password}
COUCHBASE_IP=${3:-$(hostname -I | awk 'NR==1{print $1}')}
COUCHBASE_LO=${4:-127.0.0.1}
ADMIN_USERNAME=${5:-admin}
ADMIN_PASSWORD=${6:-password}
ADMIN_EMAIL=${7:[email protected]}
ROOT_SPACE=${8:-cc}
ROOT_CURRENCY=${9:-cc}
#
#set the environment variables for the node scripts
cat <<- EOF > ./.env
COUCHBASE_ADMIN_USERNAME=$COUCHBASE_ADMIN_USERNAME
COUCHBASE_ADMIN_PASSWORD=$COUCHBASE_ADMIN_PASSWORD
COUCHBASE_IP=$COUCHBASE_IP
COUCHBASE_LO=$COUCHBASE_LO
ADMIN_USERNAME=$ADMIN_USERNAME
ADMIN_PASSWORD=$ADMIN_PASSWORD
ADMIN_EMAIL=$ADMIN_EMAIL
ROOT_SPACE=$ROOT_SPACE
ROOT_CURRENCY=$ROOT_CURRENCY
EOF
#output the status of script variables so you know what your values are
cat .env
#
#install dependency applications
sudo apt-get update
sudo apt-get install -y npm net-tools apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install -y docker-ce
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt-get install -y nodejs
sudo npm install -g n
sudo n 10.19.0
# NOTE: https://github.com/barrysteyn/node-scrypt/issues/193
# is preventing upgrade to node v12
# solution is to change implementation to native crypto module in node
#
#pull the couchbase database docker container
sudo docker pull couchbase:community-6.5.0
#
#run the docker container
sudo docker run -dit --restart unless-stopped -d --name db -p 8091-8094:8091-8094 -p 11210:11210 couchbase:community-6.5.0
#
#Wait for it
sleep 20s
#
#setup the couchbase server installation and buckets
curl -f -w '\n%{http_code}\n' -X POST http://localhost:8091/nodes/self/controller/settings -H 'Content-Type: application/x-www-form-urlencoded' -d 'path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fdata&index_path=%2Fopt%2Fcouchbase%2Fvar%2Flib%2Fcouchbase%2Fdata'
curl -f -w '\n%{http_code}\n' -X POST http://localhost:8091/pools/default -H 'Content-Type: application/x-www-form-urlencoded' -d memoryQuota=2048
curl -f -w '\n%{http_code}\n' -X POST http://localhost:8091/settings/stats -H 'Content-Type: application/x-www-form-urlencoded' -d sendStats=false
curl -f -w '\n%{http_code}\n' -X POST http://localhost:8091/settings/web -H 'Content-Type: application/x-www-form-urlencoded' -d "password=${COUCHBASE_ADMIN_PASSWORD}&username=${COUCHBASE_ADMIN_USERNAME}&port=SAME"
curl -c /tmp/cookie -w '\n%{http_code}\n' -f -X POST http://localhost:8091/uilogin -H 'Content-Type: application/x-www-form-urlencoded' -d "user=${COUCHBASE_ADMIN_USERNAME}&password=${COUCHBASE_ADMIN_PASSWORD}"
curl -b /tmp/cookie -w '\n%{http_code}\n' 'http://localhost:8091/pools/default/buckets' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-CA,en-US;q=0.7,en;q=0.3' --compressed -H 'invalid-auth-response: on' -H 'Cache-Control: no-cache' -H 'Pragma: no-cache' -H 'ns-server-ui: yes' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Origin: http://localhost:8091' -H 'Connection: keep-alive' -H 'Referer: http://localhost:8091/ui/index.html' --data 'authType=sasl&autoCompactionDefined=false&bucketType=membase&evictionPolicy=fullEviction&flushEnabled=0&name=default&ramQuotaMB=512&replicaIndex=0&replicaNumber=0&saslPassword=&threadsNumber=3'
curl -b /tmp/cookie -w '\n%{http_code}\n' 'http://localhost:8091/pools/default/buckets' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-CA,en-US;q=0.7,en;q=0.3' --compressed -H 'invalid-auth-response: on' -H 'Cache-Control: no-cache' -H 'Pragma: no-cache' -H 'ns-server-ui: yes' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Origin: http://localhost:8091' -H 'Connection: keep-alive' -H 'Referer: http://localhost:8091/ui/index.html' --data 'authType=sasl&autoCompactionDefined=false&bucketType=membase&evictionPolicy=fullEviction&flushEnabled=0&name=oauth2Server&ramQuotaMB=512&replicaIndex=0&replicaNumber=0&saslPassword=&threadsNumber=3'
curl -b /tmp/cookie -w '\n%{http_code}\n' 'http://localhost:8091/pools/default/buckets' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-CA,en-US;q=0.7,en;q=0.3' --compressed -H 'invalid-auth-response: on' -H 'Cache-Control: no-cache' -H 'Pragma: no-cache' -H 'ns-server-ui: yes' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Origin: http://localhost:8091' -H 'Connection: keep-alive' -H 'Referer: http://localhost:8091/ui/index.html' --data 'authType=sasl&autoCompactionDefined=false&bucketType=membase&evictionPolicy=fullEviction&flushEnabled=0&name=openmoney_global&ramQuotaMB=512&replicaIndex=0&replicaNumber=0&saslPassword=&threadsNumber=3'
curl -b /tmp/cookie -w '\n%{http_code}\n' 'http://localhost:8091/pools/default/buckets' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-CA,en-US;q=0.7,en;q=0.3' --compressed -H 'invalid-auth-response: on' -H 'Cache-Control: no-cache' -H 'Pragma: no-cache' -H 'ns-server-ui: yes' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' -H 'Origin: http://localhost:8091' -H 'Connection: keep-alive' -H 'Referer: http://localhost:8091/ui/index.html' --data 'authType=sasl&autoCompactionDefined=false&bucketType=membase&evictionPolicy=fullEviction&flushEnabled=0&name=openmoney_stewards&ramQuotaMB=512&replicaIndex=0&replicaNumber=0&saslPassword=&threadsNumber=3'
#
#wait for it
sleep 30s
#
#verify installation was correct
sudo docker run couchbase:community-6.5.0 /bin/sh -c "cd /opt/couchbase/bin; couchbase-cli bucket-list -c ${COUCHBASE_IP} -u ${COUCHBASE_ADMIN_USERNAME} -p ${COUCHBASE_ADMIN_PASSWORD} -d"
#
#install dependencies
npm install
#
#install seed data into couchbase server buckets
npm run install:db
#
#start the server and run in the foreground
npm run start &
#
#wait for it
sleep 7s
#
#run the tests and make sure they pass
npm run test
#
#kill the server
kill -STOP %1
#bring to foreground it it's not dead yet.
fg