Skip to content

Commit de020a8

Browse files
committed
Add prepare.sh
1 parent 549b195 commit de020a8

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

prepare.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
3+
function printHelp() {
4+
echo "Usage: "
5+
echo " prepare.sh <mode> [-u <user name>] [-S | -s <size>]"
6+
echo " <mode> - One of 'all', 'light', 'webapp', 'fabric', 'setenv', 'check'"
7+
echo " - 'all' - Prepare all prerequisites and install fabric"
8+
echo " - 'light' - Prepare fabric prerequisites and install fabric"
9+
echo " - 'webapp' - Prepare webapp prerequisites"
10+
echo " - 'fabric' - Install only fabric"
11+
echo " - 'envfile' - Make fabric environment file for user"
12+
echo " - 'check' - Check version of prerequisites"
13+
echo " -u <user name> - Owner of the home directory to which the fabric-samples will be installed (defaults to current user)"
14+
echo " -S - Add 2GB swap partition with swapfile"
15+
echo " -s <size> - Add # size swap partition with swapfile"
16+
echo " prepare.sh -h (print this message)"
17+
}
18+
19+
function installFabricPrereqs() {
20+
set -x
21+
apt-get update
22+
# install golang
23+
wget https://dl.google.com/go/go1.11.linux-amd64.tar.gz
24+
tar -xvf go1.11.linux-amd64.tar.gz
25+
mv go /usr/local
26+
rm -rf go1.11.linux-amd64.tar.gz
27+
# install docker and docker-compose
28+
apt-get install -y docker.io docker-compose
29+
set +x
30+
}
31+
32+
33+
34+
function checkPrereqs() {
35+
set -x
36+
node -v
37+
npm -v
38+
go version
39+
docker -v
40+
docker-compose -v
41+
set +x
42+
}
43+
44+
function installFabric() {
45+
# install fabric binary and fabric-samples directory in user home
46+
curl -sSL http://bit.ly/2ysbOFE | bash -s 1.4.6
47+
mv fabric-samples/ $USER_HOME
48+
}
49+
50+
function makeEnvironment() {
51+
export GOROOT=/usr/local/go
52+
export GOPATH=$USER_HOME/go
53+
export PATH=$USER_HOME/go/bin:/usr/local/go/bin:$USER_HOME/fabric-samples/bin:$PATH
54+
export PUBLIC_IP=$(curl ifconfig.me)
55+
56+
touch $ENV_FILE
57+
echo "export GOROOT=$GOROOT" >>$ENV_FILE
58+
echo "export GOPATH=$GOPATH" >>$ENV_FILE
59+
echo "export PATH=$PATH" >>$ENV_FILE
60+
echo "" >>$ENV_FILE
61+
echo "export PUBLIC_IP=$PUBLIC_IP" >>$ENV_FILE
62+
echo "alias sudo=\"sudo env PATH=$PATH PUBLIC_IP=$PUBLIC_IP\"" >>$ENV_FILE
63+
}
64+
65+
SWAP_SIZE="2GB"
66+
USER_HOME=$HOME
67+
ENV_FILE="environment"
68+
# Parse commandline args
69+
MODE=$1
70+
shift
71+
72+
while getopts "h?s:Su:" opt; do
73+
case "$opt" in
74+
h | \?)
75+
printHelp
76+
exit 1
77+
;;
78+
u)
79+
USER_HOME=/home/$OPTARG
80+
;;
81+
S)
82+
allocateSwap
83+
;;
84+
s)
85+
SWAP_SIZE=$OPTARG
86+
allocateSwap
87+
;;
88+
esac
89+
done
90+
91+
if [ $MODE == "all" ]; then
92+
installFabricPrereqs
93+
installFabric
94+
makeEnvironment
95+
checkPrereqs
96+
elif [ $MODE == "light" ]; then
97+
installFabricPrereqs
98+
installFabric
99+
makeEnvironment
100+
checkPrereqs
101+
elif [ $MODE == "webapp" ]; then
102+
installWebAppPrereqs
103+
checkPrereqs
104+
elif [ $MODE == "fabric" ]; then
105+
installFabric
106+
elif [ $MODE == "envfile" ]; then
107+
makeEnvironment
108+
elif [ $MODE == "check" ]; then
109+
checkPrereqs
110+
else
111+
printHelp
112+
exit 1
113+
fi

0 commit comments

Comments
 (0)