-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare.sh
113 lines (102 loc) · 2.91 KB
/
prepare.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
#!/bin/bash
function printHelp() {
echo "Usage: "
echo " prepare.sh <mode> [-u <user name>] [-S | -s <size>]"
echo " <mode> - One of 'all', 'light', 'webapp', 'fabric', 'setenv', 'check'"
echo " - 'all' - Prepare all prerequisites and install fabric"
echo " - 'light' - Prepare fabric prerequisites and install fabric"
echo " - 'webapp' - Prepare webapp prerequisites"
echo " - 'fabric' - Install only fabric"
echo " - 'envfile' - Make fabric environment file for user"
echo " - 'check' - Check version of prerequisites"
echo " -u <user name> - Owner of the home directory to which the fabric-samples will be installed (defaults to current user)"
echo " -S - Add 2GB swap partition with swapfile"
echo " -s <size> - Add # size swap partition with swapfile"
echo " prepare.sh -h (print this message)"
}
function installFabricPrereqs() {
set -x
apt-get update
# install golang
wget https://dl.google.com/go/go1.11.linux-amd64.tar.gz
tar -xvf go1.11.linux-amd64.tar.gz
mv go /usr/local
rm -rf go1.11.linux-amd64.tar.gz
# install docker and docker-compose
apt-get install -y docker.io docker-compose
set +x
}
function checkPrereqs() {
set -x
node -v
npm -v
go version
docker -v
docker-compose -v
set +x
}
function installFabric() {
# install fabric binary and fabric-samples directory in user home
curl -sSL http:https://bit.ly/2ysbOFE | bash -s 1.4.6
mv fabric-samples/ $USER_HOME
}
function makeEnvironment() {
export GOROOT=/usr/local/go
export GOPATH=$USER_HOME/go
export PATH=$USER_HOME/go/bin:/usr/local/go/bin:$USER_HOME/fabric-samples/bin:$PATH
export PUBLIC_IP=$(curl ifconfig.me)
touch $ENV_FILE
echo "export GOROOT=$GOROOT" >>$ENV_FILE
echo "export GOPATH=$GOPATH" >>$ENV_FILE
echo "export PATH=$PATH" >>$ENV_FILE
echo "" >>$ENV_FILE
echo "export PUBLIC_IP=$PUBLIC_IP" >>$ENV_FILE
echo "alias sudo=\"sudo env PATH=$PATH PUBLIC_IP=$PUBLIC_IP\"" >>$ENV_FILE
}
SWAP_SIZE="2GB"
USER_HOME=$HOME
ENV_FILE="environment"
# Parse commandline args
MODE=$1
shift
while getopts "h?s:Su:" opt; do
case "$opt" in
h | \?)
printHelp
exit 1
;;
u)
USER_HOME=/home/$OPTARG
;;
S)
allocateSwap
;;
s)
SWAP_SIZE=$OPTARG
allocateSwap
;;
esac
done
if [ $MODE == "all" ]; then
installFabricPrereqs
installFabric
makeEnvironment
checkPrereqs
elif [ $MODE == "light" ]; then
installFabricPrereqs
installFabric
makeEnvironment
checkPrereqs
elif [ $MODE == "webapp" ]; then
installWebAppPrereqs
checkPrereqs
elif [ $MODE == "fabric" ]; then
installFabric
elif [ $MODE == "envfile" ]; then
makeEnvironment
elif [ $MODE == "check" ]; then
checkPrereqs
else
printHelp
exit 1
fi