-
Notifications
You must be signed in to change notification settings - Fork 2
/
build
executable file
·208 lines (183 loc) · 6.52 KB
/
build
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
#! /bin/bash
VERSION_MAJOR=0
VERSION_MINOR=13
VERSION_PATCH=9
echo
echo "COMMAND : build $@ # build FireREST and its components"
echo "ETA : 1-30 minutes"
echo "HELP : https://github.com/firepick1/FireREST/wiki/Build-FireREST"
echo "DATE : `date`"
echo "VERSION : $VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
echo "PATH : $PATH"
echo "SHELL : $SHELL"
if [ "$SUDO_USER" != "" ]; then
echo "ERROR : This script will call sudo as required and must be run by non-root user"
echo "TRY : ./build"
exit -1
fi
echo "SUDO : requesting sudo installation permission"
sudo echo "SUDO : confirmed"
if [ $? -ne 0 ]; then echo "ERROR : cannot build"; exit -1; fi
function pull_git() {
echo "GIT : UPDATING $1"
if [ ! -e $1 ]; then
git clone git://github.com/firepick1/$1
fi
pushd $1 &> /dev/null
git pull
popd &> /dev/null
}
function build_git() {
echo "STATUS : BUILDING $1"
pushd $1 &> /dev/null
. ./build
if [ $? -ne 0 ]; then
echo "ERROR : $1 INSTALLATION FAILED"
exit -1
fi
popd &> /dev/null
}
if [ "$FIREREST_CONFIG" == "" ]; then FIREREST_CONFIG=examples/cfg-firepick-delta.json; fi
if [ "$(type -p bc)" == "" ]; then
echo "INSTALL : bc"
sudo apt-key update;
sudo apt-get update;
sudo apt-get install bc;
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
fi
echo "STATUS : bc installed"
if [ "$(type -p tmux)" == "" ]; then
echo "INSTALL : tmux"
sudo apt-get install tmux
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
fi
echo "STATUS : tmux installed"
if [ "$(type -p lsb_release)" == "" ]; then
echo "INSTALL : lsb_release"
sudo apt-get install -y lsb-release
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
fi
if [ "$(arch)" != "armv6l" ] || [ "$(lsb_release -is)" != "Debian" ] ;then
RASPBIAN=0
echo "SYSTEM : other (FireFUSE not supported)"
else
RASPBIAN=1
echo "SYSTEM : Raspberry Pi with Rasbian"
fi
if [ "$(type -p node)" == "" ]; then
echo "INSTALL : NodeJS"
if [ $RASPBIAN -eq 1 ]; then
sudo mkdir /opt/node
pushd /opt/node > /dev/null
NODE_DISTRO=http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-arm-pi.tar.gz
echo "COMMAND : sudo wget $NODE_DISTRO"
sudo wget $NODE_DISTRO
echo sudo tar xvzf node-*-linux-arm-pi.tar.gz
sudo tar xvzf node-*-linux-arm-pi.tar.gz
RC=$?; if [ $RC -ne 0 ]; then echo "ERROR : $RC"; exit -1; fi
echo sudo rm node-*-linux-arm-pi.tar.gz
sudo rm node-*-linux-arm-pi.tar.gz
RC=$?; if [ $RC -ne 0 ]; then echo "ERROR : $RC"; exit -1; fi
echo cd /usr/local/bin
cd /usr/local/bin
RC=$?; if [ $RC -ne 0 ]; then echo "ERROR : $RC"; exit -1; fi
echo sudo ln -s /opt/node/node-*pi/bin/node node
sudo ln -s /opt/node/node-*pi/bin/node node
RC=$?; if [ $RC -ne 0 ]; then echo "ERROR : $RC"; exit -1; fi
echo sudo ln -s /opt/node/node-*pi/bin/npm npm
sudo ln -s /opt/node/node-*pi/bin/npm npm
RC=$?; if [ $RC -ne 0 ]; then echo "ERROR : $RC"; exit -1; fi
popd > /dev/null
else
echo "COMMAND : sudo apt-get install -y nodejs nodejs-legacy"
sudo apt-get install -y nodejs nodejs-legacy
RC=$?; if [ $RC -ne 0 ]; then
echo "ERROR : $RC";
echo "TRY : install NodeJS manually"
exit -1
fi
fi
fi
echo "STATUS : NodeJS installed"
if [ "$(type -p npm)" == "" ]; then
echo "COMMAND : sudo apt-get install -y npm"
sudo apt-get install -y npm;
RC=$?; if [ $RC -ne 0 ]; then
echo "ERROR : $RC";
echo "TRY : install npm manually"
exit -1
fi
fi
echo "STATUS : npm installed"
if [ "$(type -p grunt)" == "" ]; then
echo "INSTALL : sudo npm install -g grunt-cli"
sudo npm install -g grunt-cli
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
echo "INSTALL : npm install [email protected]"
npm install [email protected] --save-dev
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
echo "INSTALL : npm install grunt-contrib-uglify"
npm install grunt-contrib-uglify
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
fi
if [ ! -e node_modules ]; then
echo "INSTALL : local NodeJS dependencies"
npm install
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
fi
echo "STATUS : local node_modules installed"
if [ "$(type -p express)" == "" ]; then
echo "INSTALL : express "
npm install express
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
fi
echo "STATUS : express installed"
echo "GRUNT : generating FireREST configuration files (see examples)"
grunt cfg-version:config/FireREST.json:examples/cfg-firepick1.json:$VERSION_MAJOR:$VERSION_MINOR:$VERSION_PATCH \
cfg-custom:examples/cfg-firepick1.json:config/cv.json:config/cnc-firepick1.json
grunt cfg-version:config/FireREST.json:examples/cfg-firepick-delta.json:$VERSION_MAJOR:$VERSION_MINOR:$VERSION_PATCH \
cfg-custom:examples/cfg-firepick-delta.json:config/cv.json:config/cnc-firepick-delta.json
grunt cfg-version:config/FireREST.json:examples/cfg-cnc-none.json:$VERSION_MAJOR:$VERSION_MINOR:$VERSION_PATCH \
cfg-custom:examples/cfg-cnc-none.json:config/cv.json:config/cnc-none.json
cp $FIREREST_CONFIG www/config.json
echo "CONFIG : $FIREREST_CONFIG"
echo "SUDO : SUDO_USER: $SUDO_USER"
echo "SSH : SSH_AGENT_PID: $SSH_AGENT_PID"
fire/web -k
pull_git FireSight
pull_git FireFUSE
ps -eo uid,args | grep -E firerest.js | grep node > /dev/null
if [ $? -eq 0 ]; then
echo "----------------------------------------"
echo "ERROR : FireREST is already running"
echo "TRY : Kill the existing FireREST process before proceeding with the build:"
echo "PID : `ps -e -o pid,command | grep -E "firerest.js" | grep -v grep`"
exit -1
fi
if [ "$(type -p siege)" == "" ]; then
echo "INSTALL : siege"
sudo apt-get install -y siege
if [ $? -ne 0 ]; then echo "ERROR : installation failed"; exit -1; fi
fi
echo "STATUS : siege installed"
if [ $RASPBIAN -ne 1 ]; then
echo "CONTENT : FireREST reference implementation. Static content only"
echo "SUCCESS : Build complete"
else
echo "CONTENT : Raspberry Pi FireFUSE with live content"
if [ -e version-$VERSION_MAJOR.$VERSION_MINOR ] && [ -e /dev/firefuse/status ] ; then
echo "STATUS : FireREST dependencies OK"
else
build_git FireSight
build_git FireFUSE
fi
fire/config -d
fi
rm -f version-$VERSION_MAJOR.$VERSION_MINOR
date > version-$VERSION_MAJOR.$VERSION_MINOR
echo "------------------------------------------"
echo "DATE : `date`"
echo "SUCCESS : ../FireREST/build complete"
echo "TEST : Launch FireREST web service:"
echo "TEST ; fire/web -s"
echo "TEST ; Verify FireREST web service at http://localhost:8080"