-
Notifications
You must be signed in to change notification settings - Fork 924
/
setup_OSX.sh
executable file
·334 lines (317 loc) · 13.9 KB
/
setup_OSX.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/bin/bash
YELLOW='\033[1;33m'
RED='\033[1;31m'
GREEN='\033[1;32m'
RESET='\033[0m'
GREY='\033[2m'
# 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 "${GREY}=====================================================" | indent
echo -e "${RESET}-----> $*" | indent
echo -e "${GREY}=====================================================${RESET}" | indent
}
# Grab the current directory
function getCurrent()
{
showStep "getting current directory"
DIR="$( pwd )"
echo "DIR in getCurrent is: ${DIR}"
THIS_SCRIPT=`basename "$0"`
showStep "Running '${THIS_SCRIPT}'"
showStep "Checking to make sure Docker daemon is available"
docker_up=$(pgrep -f com.docker.supervisor)
if [[ ${docker_up} = "" ]]; then
showStep "${RED}Docker daemon is not running, please start it before running this script${RESET}"
exit -1
else
showStep "Docker daemon is running"
fi
}
# check to see if Brew is installed. Install it if it's not already present
# then update and upgrade
function check4Brew ()
{
if [[ $BREW_INSTALL == "true" ]]; then
which brew
if [ "$?" -ne 0 ]; then
showStep "${RED}brew not found. installing brew, please accept the installation recommendations"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
showStep "${GREEN}brew already installed"
fi
else
showStep "${RED}skipping BREW install"
fi
showStep "updating brew to latest version"
brew update
showStep "upgrading your installed brew packages"
brew upgrade
brew cleanup
brew install dos2unix
}
# check to see if nodev8 is installed. install it if it's not already there.
function check4node ()
{
if [[ $NODE_INSTALL == "true" ]]; then
which node
if [ "$?" -ne 0 ]; then
showStep "${RED}node not installed. installing Node V8"
brew install node@8
brew link --overwrite --force node@8
brew postinstall node@8
npm i npm@latest -g
else
if [[ `brew search /node@8/` != "node@8" ]]; then
showStep "${RED}found node $? installed, but not V8. installing Node V8"
brew install node@8
brew link --overwrite --force node@8
brew postinstall node@8
npm i npm@latest -g
echo "PATH=/usr/local/opt/node@8/bin:"'$PATH' >>~/.bash_profile
else
showStep "${GREEN}Node V8 already installed"
npm i npm@latest -g
fi
fi
else
showStep "${RED}skipping NODE install"
fi
showStep "installing jsdoc globally"
npm install -g jsdoc
showStep "installing node-gyp globally"
npm install -g node-gyp
}
# check to see if git is installed. install it if it's not already there.
function check4git ()
{
if [[ $GITHUB_INSTALL == "true" ]]; then
which git
if [ "$?" -ne 0 ]; then
showStep "${RED}git not installed. installing git"
brew install git
else
git_version=$(git --version | awk '{print $3}')
IFS=. components=(${git_version##*-})
version=${components[0]}
major=${components[1]}
if ((($version < 2)) || ((major<18))); then
showStep "${YELLOW}Upgrading git"
brew install git
brew link --force git
brew unlink git && brew link git
else
showStep "${GREEN}git already installed and current"
fi
fi
showStep "downloading GitHub Desktop for OSX"
curl -O https://mac-installer.github.com/mac/GitHub%20Desktop%20223.zip
showStep "unzipping GitHub Desktop"
unzip -o -q 'GitHub%20Desktop%20223.zip'
showStep "Installing GitHub Desktop"
yes | cp -rf 'Github Desktop.app' /Applications
showStep "removing intermediate files"
rm -r 'Github Desktop.app'
rm -r 'GitHub%20Desktop%20223.zip'
else
showStep "${RED}skipping git install"
fi
}
# Install the node modules required to work with hyperledger composer
function installNodeDev ()
{
if [[ $SDK_INSTALL == "true" ]]; then
showStep "The composer-cli contains all the command line operations for developing business networks."
npm uninstall -g composer-cli
npm install -g [email protected]
showStep "The generator-hyperledger-composer is a Yeoman plugin that creates bespoke applications for your business network."
npm uninstall -g generator-hyperledger-composer
npm install -g [email protected]
showStep "The composer-rest-server uses the Hyperledger Composer LoopBack Connector to connect to a business network, extract the models and then present a page containing the REST APIs that have been generated for the model."
npm uninstall -g composer-rest-server
npm install -g [email protected]
showStep "Yeoman is a tool for generating applications. When combined with the generator-hyperledger-composer component, it can interpret business networks and generate applications based on them."
npm install -g yo
else
showStep "${RED}skipping NODE SDK for HyperLedger install"
fi
}
# create a folder for the hyperledger fabric images and get them from the server
function install_hlf ()
{
if [[ $HLF_INSTALL == "true" ]]; then
echo $HLF_INSTALL_PATH
if [ -d $HLF_INSTALL_PATH ]; then
showStep "removing $HLF_INSTALL_PATH"
rm -R "$HLF_INSTALL_PATH"
fi
if [ -d ~/.composer ]; then
showStep "removing .composer"
rm -R ~/.composer
fi
if [ -d ~/.composer-credentials ]; then
showStep "removing .composer-credentials"
rm -R ~/.composer-credentials
fi
if [ -d ~/.composer-connection-profiles ]; then
showStep "removing .composer-connection-profiles"
rm -R ~/.composer-connection-profiles
fi
showStep "creating hlf tools folder $HLF_INSTALL_PATH "
mkdir -p "$HLF_INSTALL_PATH"
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
#
# can no longer use V 0.2.2 with Composer v0.15
# curl -O https://raw.githubusercontent.com/hyperledger/composer-tools/v0.2.2/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
echo 'FABRIC_VERSION="hlfv1"' >> ~/.bash_profile
# the following line is here to ensure that the subsequent echos start on a new line.
echo ' ' >> ~/.bash_profile
echo 'FABRIC_VERSION is ${FABRIC_VERSION}'
cd $HLF_INSTALL_PATH
./downloadFabric.sh
showStep "installing platform specific binaries for OSX"
#
# v0.12-v0.14
# curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/v1.0.4/scripts/bootstrap-1.0.1.sh | bash
#
# v0.15
# curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap-1.0.1.sh | bash
#
# v 0.16
#
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
showStep "updating .bash_profile with new paths"
echo "export HLF_INSTALL_PATH=${HLF_INSTALL_PATH}" >>~/.bash_profile
echo "PATH=${HLF_INSTALL_PATH}/bin:"'$PATH' >>~/.bash_profile
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}-g ${RESET}defaults to ${GREEN}true${RESET}. use ${YELLOW}-g false ${RESET}if you do not want to have git installation checked" | indent
echo -e "${GREEN}-b ${RESET}defaults to ${GREEN}true${RESET}. use ${YELLOW}-b false ${RESET}if you do not want to have brew installation checked" | indent
echo -e "${GREEN}-n ${RESET}defaults to ${GREEN}true${RESET}. use ${YELLOW}-n false ${RESET}if you do not want to have node installation checked" | indent
echo -e "${GREEN}-s ${RESET}defaults to ${GREEN}true${RESET}. use ${YELLOW}-s false ${RESET}if you do not want to have node SDK installation checked" | indent
echo -e "${GREEN}-d ${RESET}defaults to ${GREEN}true${RESET}. use ${YELLOW}-d false ${RESET}if you do not want to have hypleledger node 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 -d 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 Mac OSX ONLY" | indent
echo -e "${RED}Please ensure that you have already installed Docker on your system before running this script" | indent
echo -e "${YELLOW}Docker for OSX can be found here: https://www.docker.com/community-edition#/download${RESET}" | indent
read -n1 -r -p "Press enter to continue or press CTRL-C to cancel if you need to install Docker" key
echo -e "${YELLOW}This script will check to see if HomeBrew is installed" | indent
echo -e "${YELLOW} and install it if it's not already present. " | indent
echo -e "${YELLOW}It will then execute a brew update and brew upgrade to ensure" | indent
echo -e "${YELLOW} that you are at the latest release of your brew installed packages" | indent
echo -e "${YELLOW}dos2unix is installed by brew to correct scripts from hyperledger and composer" | indent
echo -e "${YELLOW}The exec will proceed with checking to ensure you are at Node V8" | indent
echo -e "${YELLOW} which is required for working with HyperLedger Composer" | indent
echo -e "${YELLOW}The script will then install the nodejs SDK for hyperledger and composer" | indent
echo -e "${YELLOW}The script will finish by downloading the docker images for hyperledger${RESET}" | indent
echo ""
}
# get the command line options
GITHUB_INSTALL="true"
BREW_INSTALL="true"
NODE_INSTALL="true"
SDK_INSTALL="true"
HLF_INSTALL="true"
HLF_INSTALL_PATH="${HOME}/fabric-tools"
while getopts "h:g:b:n:d:p:s:" opt;
do
case "$opt" in
h|\?)
printHelp
exit 0
;;
g) showStep "option passed for github is: '$OPTARG'"
if [[ $OPTARG != "" ]]; then
GITHUB_INSTALL=$OPTARG
fi
;;
b) showStep "option passed for brew is: '$OPTARG'"
if [[ $OPTARG != "" ]]; then
BREW_INSTALL=$OPTARG
fi
;;
n) showStep "option passed for node is: '$OPTARG'"
if [[ $OPTARG != "" ]]; then
NODE_INSTALL=$OPTARG
fi
;;
s) showStep "option passed for node SDK is: '$OPTARG'"
if [[ $OPTARG != "" ]]; then
SDK_INSTALL=$OPTARG
fi
;;
d) showStep "option passed for hyperledger docker 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 github? ${GREEN}$GITHUB_INSTALL${RESET}" | indent
echo -e "Install brew? ${GREEN} $BREW_INSTALL ${RESET}" | indent
echo -e "Install nodejs? ${GREEN} $NODE_INSTALL ${RESET}" | indent
echo -e "Install nodejs SDK? ${GREEN} $SDK_INSTALL ${RESET}" | indent
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 xCode command line tools"
xcode-select --install
showStep "checking Brew"
check4Brew
showStep "checking git"
check4git
showStep "checking nodejs"
check4node
showStep "installing nodejs SDK for hyperledger composer"
installNodeDev
showStep "installing hyperledger docker images"
install_hlf
showStep "copying peeradmin key to .hfc-key-store"
cp -Rv "${HLF_INSTALL_PATH}/fabric-scripts/hlfv1/composer/creds/" "${HOME}/.hfc-key-store"
showStep "installation complete"