forked from aws-samples/hyperledger-on-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util-prep.sh
executable file
·113 lines (106 loc) · 3.71 KB
/
util-prep.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
108
109
110
111
112
113
#!/usr/bin/env bash
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
function updateRepo {
if [ $# -ne 2 ]; then
echo "Usage: updateRepo <home-dir> <repo-name>"
exit 1
fi
local HOME=$1
local REPO=$2
echo "Updating repo $REPO at $HOME"
cd $HOME
if [ ! -d $REPO ]; then
# clone repo, if it hasn't already been cloned
git clone https://github.com/MCLDG/$REPO.git
else
# update repo, if it has already been cloned
cd $REPO
git pull
fi
cd $HOME
}
function genTemplates {
if [ $# -ne 2 ]; then
echo "Usage: genTemplates <home-dir> <repo-name>"
exit 1
fi
local HOME=$1
local REPO=$2
echo "Generating K8s YAML deployment files"
cd $HOME/$REPO/fabric-main
./gen-fabric.sh
}
function genWorkshopTemplates {
if [ $# -ne 2 ]; then
echo "Usage: genWorkshopTemplates <home-dir> <repo-name>"
exit 1
fi
local HOME=$1
local REPO=$2
echo "Generating K8s YAML Workshop deployment files"
cd $HOME/$REPO/workshop-remote-peer
./gen-workshop-remote-peer.sh
}
function makeDirs {
if [ $# -ne 1 ]; then
echo "Usage: makeDirs <data-dir - probably something like /opt/share>"
echo "input args are '$@'"
exit 1
fi
local DATA=$1
echo "Making directories at $DATA"
cd $DATA
mkdir -p rca-data
mkdir -p rca-scripts
mkdir -p orderer
}
function copyScripts {
if [ $# -ne 3 ]; then
echo "Usage: copyScripts <home-dir> <repo-name> <data-dir - probably something like /opt/share>"
exit 1
fi
local HOME=$1
local REPO=$2
local DATA=$3
echo "Copying scripts folder from $REPO to $DATA"
cd $HOME
mkdir -p $DATA/rca-scripts/
sudo cp $HOME/$REPO/scripts/* $DATA/rca-scripts/
sudo chmod 777 $DATA/rca-scripts/gen-channel-artifacts.sh
}
#merge the contents of the env.sh file
#the env.sh in $SCRIPTS will have been updated with the DNS of the various endpoints, such as ORDERER and
#ANCHOR PEER. We need to merge the contents of env-remote-peer.sh into $SCRIPTS/env.sh in order to retain
#these DNS endpoints as they are used by the remote peer
function mergeEnv {
if [ $# -ne 4 ]; then
echo "Usage: mergeEnv <home-dir> <repo-name> <data-dir - probably something like /opt/share> <filename - env file to be merged into main env.sh>"
exit 1
fi
local HOME=$1
local REPO=$2
local DATA=$3
local FILE=$4
echo "Merging the ENV files"
cd $HOME/$REPO
start='^##--BEGIN REPLACE CONTENTS--##$'
end='^##--END REPLACE CONTENTS--##$'
newfile=`sed -e "/$start/,/$end/{ /$start/{p; r $FILE
}; /$end/p; d }" $DATA/rca-scripts/env.sh`
sudo chown ec2-user $DATA/rca-scripts/env.sh
echo "$newfile" > $DATA/rca-scripts/env.sh
cp $DATA/rca-scripts/env.sh scripts/env.sh
}