forked from rddill-IBM/ZeroToBlockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_Ubuntu_Part_2.sh
executable file
·173 lines (156 loc) · 6.33 KB
/
setup_Ubuntu_Part_2.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
YELLOW='\033[1;33m'
RED='\033[1;31m'
GREEN='\033[1;32m'
RESET='\033[0m'
# exit on error
# Array of supported versions
declare -a versions=('trusty' 'xenial' 'yakkety');
# check the version and extract codename of ubuntu if release codename not provided by user
lsb_release -a || (echo "Error: Release information not found, run script passing Ubuntu version codename as a parameter"; exit 1)
CODENAME=$(lsb_release -a | grep 'Codename:' | awk '{print $2}')
# check version is supported
if echo ${versions[@]} | grep -q -w ${CODENAME}; then
echo "Installing Hyperledger Composer prereqs for Ubuntu ${CODENAME}"
else
echo "Error: Ubuntu ${CODENAME} is not supported"
exit 1
fi
# indent text on echo
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
# displays where we are, uses the indent function (above) to indent each line
function showStep ()
{
echo -e "${YELLOW}=====================================================" | indent
echo -e "${RESET}-----> $*" | indent
echo -e "${YELLOW}=====================================================${RESET}" | indent
}
# Grab the current directory
function getCurrent()
{
showStep "getting current directory"
DIR="$( pwd )"
THIS_SCRIPT=`basename "$0"`
showStep "Running '${THIS_SCRIPT}'"
UBUNTU_ARCH=`uname -m`
UBUNTU_VERSION=`lsb_release -c | grep "Codename:" | awk '{print $2}'`
showStep "found Ubuntu ${UBUNTU_VERSION} as an ${UBUNTU_ARCH} system"
if [[ $UBUNTU_ARCH != "x86_64" ]]; then
showStep "Install Failed, need a 64 bit system. This is ${UBUNTU_ARCH}"
exit 1
fi
if [[ ${UBUNTU_VERSION} != "xenial" ]]; then
showStep "Install Failed, need a Ubuntu 16 LTS. This is ${UBUNTU_VERSIO}"
exit 1
fi
}
# create a folder for the hyperledger fabric images and get them from the server
function install_hlf ()
{
if [[ $HLF_INSTALL == "true" ]]; then
if [ ! -d "$HLF_INSTALL_PATH" ]; then
showStep "creating hlf tools folder $HLF_INSTALL_PATH "
mkdir -p "$HLF_INSTALL_PATH"
fi
cd "$HLF_INSTALL_PATH"
pwd
showStep "retrieving image scripts from git"
curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.zip
showStep "unzipping images"
unzip -o fabric-dev-servers.zip
showStep "making scripts executable"
dos2unix `ls *.sh`
cd fabric-scripts/hlfv1
dos2unix `ls *.sh`
showStep "getting docker images for HyperLedger Fabric V1"
export FABRIC_VERSION=hlfv1
# the following line is here to ensure that the subsequent echos start on a new line.
echo ' ' >> ~/.bashrc
echo 'FABRIC_VERSION="hlfv1"' >> ~/.bashrc
cd $HLF_INSTALL_PATH
./downloadFabric.sh
showStep "installing platform specific binaries for Ubuntu"
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/release-1.0/scripts/bootstrap-1.0.1.sh | bash
export PATH=$HLF_INSTALL_PATH/bin:$PATH
export HLF_INSTALL_PATH=$HLF_INSTALL_PATH
echo 'PATH="'"${HLF_INSTALL_PATH}/bin:$PATH"'"' >>~/.profile
echo 'HLF_INSTALL_PATH="'"${HLF_INSTALL_PATH}"'"' >>~/.bashrc
echo 'export HLF_INSTALL_PATH' >>~/.bashrc
echo 'export FABRIC_VERSION' >>~/.bashrc
if [ -d "~/.composer" ]; then
sudo chmod +rw ~/.composer
else
cd $HLF_INSTALL_PATH
./createPeerAdminCard.sh
sudo chmod +rw ~/.composer
fi
else
showStep "${RED}skipping HyperLedger Fabric install"
fi
}
function printHelp ()
{
printHeader
echo ""
echo -e "${RESET} options for this exec are: "
echo -e "${GREEN}-h ${RESET}Print this help information" | indent
echo -e "${GREEN}-f ${RESET}defaults to ${GREEN}true${RESET}. use ${YELLOW}-d false ${RESET}if you do not want to have hypleledger fabric images verified" | indent
echo -e "${GREEN}-p ${RESET}defaults to ${GREEN}${HOME}/fabric-tools${RESET}. use ${YELLOW}-p ${HOME}/your/preferred/path/fabric-tools/your/path/here ${RESET}if you want to install hyperledger fabric tools elsewhere." | indent
echo -e "\t\tonly valid with -f true, ignored otherwise" | indent
echo ""
echo ""
}
# print the header information for execution
function printHeader ()
{
echo ""
echo -e "${YELLOW}installation script for the Zero To Blockchain Series" | indent
echo -e "${RED}This is for Linux ONLY. It has been tested on Ubuntu 16.04 LTS" | indent
echo -e "${YELLOW}Other versions of Linux are not supported via this script. " | indent
echo -e "${YELLOW}The following will be downloaded by this script" | indent
echo -e "${YELLOW}The script will finish by downloading the docker images for hyperledger${RESET}" | indent
echo ""
}
# get the command line options
HLF_INSTALL="true"
HLF_INSTALL_PATH="${HOME}/fabric-tools"
while getopts "h:p:f:" opt;
do
case "$opt" in
h|\?)
printHelp
exit 0
;;
f) showStep "option passed for hyperledger fabric install is: '$OPTARG'"
if [[ $OPTARG != "" ]]; then
HLF_INSTALL=$OPTARG
fi
;;
p) showStep "option passed for fabric tools path is: '$OPTARG'"
if [[ $OPTARG != "" ]]; then
HLF_INSTALL_PATH=$OPTARG
fi
;;
esac
done
printHeader
echo "Parameters:"
echo -e "Install HyperLedger Fabric? ${GREEN} $HLF_INSTALL ${RESET}" | indent
echo -e "Hyperledger fabric tools install path? ${GREEN} $HLF_INSTALL_PATH ${RESET}" | indent
getCurrent
showStep "installing hyperledger docker images"
install_hlf
showStep "Copying PeerAdmin Credentials"
if [ -d "~/.hfc-key-store" ]; then
cp -Rv $HLF_INSTALL_PATH/fabric-scripts/hlfv1/composer/creds/* ~/.hfc-key-store
else
mkdir ~/.hfc-key-store
cp -Rv $HLF_INSTALL_PATH/fabric-scripts/hlfv1/composer/creds/* ~/.hfc-key-store
fi
showStep "installation complete"