deployNetwork.sh 1.63 KB
Newer Older
Krystian Gaus's avatar
Krystian Gaus committed
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

#!/bin/bash

NEW_REST_SERVER_PID=$(ps -o pid= | head -n 1)

installedNetworkVersion=$(composer network ping -c admin@trackntrace-network | head -n 2 | tail -1 | cut -d':' -f2 | tr -d ' ')
version=$(cat ../package.json | jq .version | tr -d \")

echo "Installed Business Network version:" $installedNetworkVersion
echo "Latest found Business Network version:" $version

if [ $installedNetworkVersion == 'Commandfailed' ]
then
	# The Business Network must be installed and started for the first time
	composer network install -a ../trackntrace-network.bna -c PeerAdmin@hlfv1
	composer network start -n trackntrace-network -V $version -c PeerAdmin@hlfv1 -A admin -S adminpw
else
	if [ $installedNetworkVersion == $version ]
	then
		echo "Skipping installation and start/upgrade of Business Network because latest version is already installed."
	else
		# The installedNetworkVersion and the latest found version differ, thus the Business Network has to be upgraded
		composer network install -a ../trackntrace-network.bna -c PeerAdmin@hlfv1
		composer network upgrade -c PeerAdmin@hlfv1 -n trackntrace-network -V $version
	fi	
	echo "Killing process of running Composer REST Server..."
	kill -9 $(head -1 REST_SERVER_PID)	
fi

echo "Writing new process number" $NEW_REST_SERVER_PID "of terminal to REST_SERVER_PID file..."
echo $NEW_REST_SERVER_PID > REST_SERVER_PID
echo "Process number saved successfully."

echo "Starting Composer REST Server..."
composer-rest-server -c admin@trackntrace-network -n required -w true
#use the following line if a api key is needed 
#composer-rest-server -c admin@trackntrace-network -n required -y u4nyxpcrc3frPjszkjgxunu3wqmiBiyz -w true