/
build_linux.sh
executable file
·337 lines (296 loc) · 8.95 KB
/
build_linux.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
335
336
337
#!/bin/bash
function help ()
{
echo "Peachy Printer Build Script"
echo "Recommened Usage: build_linux.sh -dij"
echo "-h | --help Displayes this message and exits"
echo "-r | --remove-venv Removes Virtual Environment"
echo "-n | --no_setup Ignores enviroment setup"
echo "-p | --pull Pulls from git before running setup"
echo "-c | --clean Performs a git reset and clean"
echo "-i | --install_dep Install the linux dependancies (sudo required)"
echo "-s | --setup_only Setups the enviroment only and does not package"
echo "-j | --build_runner Creates the rules and files required to run peachy printer(sudo required)"
echo "-d | --build_driver Creates libPeachyUSB driver"
}
function remove_venv ()
{
echo "------------------------------------"
echo "Removing Virtual Environment"
echo "------------------------------------"
rm -rf venv
echo -e "${FGRN}Complete${RS}"
echo""
}
function clean ()
{
read -p "Are you sure? " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
git reset --hard HEAD
git clean -e api.source
fi
}
function clean_workspace ()
{
echo "------------------------------------"
echo "Cleaning workspace"
echo "------------------------------------"
rm -rf src/build
rm -rf *.deb
rm -f src/VERSION.py
rm -f version.properties
echo -e "${FGRN}Complete${RS}"
echo""
}
function enable_venv ()
{
echo "------------------------------------"
echo "Upgrading / Starting Virtual Environment"
echo "------------------------------------"
if [ ! -f venv/bin/activate ]; then
virtualenv --system-site-packages -p python2.7 venv
if [ $? != 0 ]; then
echo "${FRED}FAILED Setting up virtual enviroment${RS}"
EXIT_CODE=59
failed_exit
fi
fi
source venv/bin/activate
echo -e "${FGRN}Complete${RS}"
echo""
}
function setup_venv ()
{
echo "------------------------------------"
echo "Setting up virtual env"
echo "------------------------------------"
echo "--------Setting up cython----"
python -m pip install -I -U cython==0.23
if [ $? != 0 ]; then
echo "${FRED}FAILURE: cython failed installing${RS}"
EXIT_CODE=666
failed_exit
fi
echo "--------Setting up kivy----"
python -m pip install -I -U git+https://github.com/kivy/kivy.git@master
if [ $? != 0 ]; then
echo "${FRED}FAILURE: kivy failed installing${RS}"
EXIT_CODE=666
failed_exit
fi
yum -h > /dev/null
if [ $? == 0 ]; then
sudo pip install -I pygments
fi
python -m pip install --upgrade -r requirements.txt
if [ $? != 0 ]; then
echo -e "${FRED}FAILED TO INSTALL REQUIREMENTS{RS}"
exit 59
fi
echo -e "${FGRN}Complete${RS}"
echo""
}
function find_version_number ()
{
echo "------------------------------------"
echo "Extracting Git Revision Number"
echo "------------------------------------"
SEMANTIC=`cat symantic.version`
function trim() { echo $1; }
if [ -z $GIT_HOME ]; then
if [ -f "/usr/local/bin/git" ]; then
export GIT_HOME=/usr/local/bin/git
elif [ -f "/usr/bin/git" ]; then
export GIT_HOME=/usr/bin/git
elif [ -f "/bin/git" ]; then
export GIT_HOME=/bin/git
else
${FRED}GIT Could not be located${RS}
EXIT_CODE=55
failed_exit
fi
fi
git status
if [ $? == 0 ]; then
export GIT_REV_COUNT_RAW=`$GIT_HOME log --pretty=oneline | wc -l`
export GIT_REV_COUNT=`trim $GIT_REV_COUNT_RAW`
export GIT_REV=`$GIT_HOME rev-parse HEAD`
VERSION=$SEMANTIC.$TAG$GIT_REV_COUNT
else
export GIT_REV_COUNT='release'
export GIT_REV='release'
VERSION=$SEMANTIC.r
fi
echo "Version: $VERSION"
echo "# THIS IS A GENERATED FILE " > version.properties
echo "version='$VERSION'" >> version.properties
echo "revision='$GIT_REV'" >> version.properties
echo "Git Revision Number is $GIT_REV_COUNT"
cp version.properties src/VERSION.py
echo ""
}
function run_tests ()
{
echo "------------------------------------"
echo "Running Tests"
echo "------------------------------------"
python test/test-all.py
if [ $? != 0 ]; then
echo -e "${FRED}FAILED Running tests${RS}"
EXIT_CODE=91
failed_exit
fi
echo -e "${FGRN}Complete${RS}"
echo""
}
function dependancies ()
{
apt-get -h > /dev/null
if [ $? == 0 ]; then
echo "${FGRN}APT detected using APT${RS}"
echo "You will be prompted to elevate permissions"
sudo apt-get install $DEBIAN_DEP
sudo pip install -I --upgrade virtualenv
return
fi
yum -h > /dev/null
if [ $? == 0 ]; then
echo "${FGRN}YUM detected using YUM${RS}"
echo "Assumes the EPEL repos are available"
echo "You will be prompted to elevate permissions"
sudo yum install $REDHAT_DEP
sudo pip install -I --upgrade virtualenv
return
fi
echo "${FRED}APT or YUM not found aborting${RS}"
EXIT_CODE=12
failed_exit
}
function build_driver_now ()
{
echo "------------------------------------"
echo "Building libPeachyUSB"
echo "------------------------------------"
pushd .
cd /tmp
rm -rf c-usb-module
git clone https://github.com/PeachyPrinter/c-usb-module.git
cd c-usb-module
git checkout tags/0.0.1.47
./build_linux.sh
popd
echo pwd
cp /tmp/c-usb-module/linux64/libPeachyUSB.so venv/local/lib/python2.7/site-packages/peachyprinter/dependancies/linux/amd64/libPeachyUSB.so
if [ $? != 0 ]; then
echo -e "${FRED}Building libPeachyUSB FAILED${RS}"
exit 59
fi
}
function build ()
{
echo "------------------------------------"
echo "Building Deistribution"
echo "------------------------------------"
echo "--------Build Media---------------"
python build_media.py
if [ $? != 0 ]; then
echo -e "${FRED}MEDIA BUILD FAILED${RS}"
exit 59
fi
}
function update ()
{
echo "------------------------------------"
echo "Getting latest "
echo "------------------------------------"
git pull
if [ $? != 0 ]; then
echo -e "${FRED}Pull failed${RS}"
exit 134
fi
}
function ensure_no_active_venv ()
{
echo "------------------------------------"
echo "Checking for already running Virtual Environment"
echo "------------------------------------"
if [[ "$VIRTUAL_ENV" != "" ]]; then
echo "Deactivitate the existing virtual enviroment before running this script."
echo "This can be done with the \"deactivate\" command."
EXIT_CODE=89
failed_exit
fi
echo -e "${FGRN}Complete${RS}"
echo""
}
function build_runner () {
echo "------------------------------------"
echo "Creating Rules and Runner Script"
echo "------------------------------------"
echo "You will be prompted to elevate permissions"
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="16d0", ATTR{idProduct}=="0af3", MODE="0666"' > 99-peachy.rules
echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="df11", MODE="0666"' >> 99-peachy.rules
sudo cp -rf 99-peachy.rules /etc/udev/rules.d/99-peachy.rules
echo "Added rules you may be required to login again"
echo "source venv/bin/activate" > run.sh
echo "python src/main.py -tl INFO" >> run.sh
chmod +x run.sh
echo -e "${FGRN}Complete${RS}"
}
function failed_exit()
{
popd
exit $EXIT_CODE
}
if [ $# -eq 0 ]; then
help
exit 0
fi
params=`getopt -o :hdrnpcisj -l build_runner,build_driver,install_dep,remove-venv,no_setup,pull,clean,help,setup_only --name "$0" -- "$@"`
eval set -- "$params"
DEBIAN_DEP="cmake libusb-1.0-0-dev libstdc++6 python-pip python-dev libsmpeg-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev libfreetype6-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev git dfu-util"
REDHAT_DEP="gcc python-pip python-devel python-distutils-extra python-enchant python-distutils-extra python-enchant freeglut PyOpenGL SDL_ttf-devel SDL_mixer-devel pygame pygame-devel khrplatform-devel mesa-libGLES mesa-libGLES-devel gstreamer-plugins-good gstreamer gstreamer-python mtdev-devel git"
RS="\033[0m" # reset
FRED="\033[31m" # foreground red
FGRN="\033[32m" # foreground green
while true
do
case "$1" in
-h | --help ) help ; exit 0 ;;
-r | --remove-venv ) remove_venv ; shift ;;
-n | --no_setup ) no_setup="1" ; shift ;;
-p | --pull ) update ; shift ;;
-c | --clean ) clean ; shift ;;
-i | --install_dep ) dependancies ; shift ;;
-j | --build_runner ) build_runner ; shift ;;
-d | --build_driver ) build_driver="1" ; shift ;;
-s | --setup_only ) setup_only="1" ; shift ;;
-k | --kivy_source ) build_kivy="1" ; shift ;;
-- ) shift ; break ;;
* ) echo "Unexpected entry: $1" ; help ; exit 1 ;;
esac
done
pushd .
cd "$(dirname "$0")"
ensure_no_active_venv
clean_workspace
enable_venv
if [ "${no_setup}" != "1" ]; then
./run_tests
setup_venv
fi
if [ "${build_kivy}" == "1" ]; then
build_kivy_source
fi
if [ "${setup_only}" != "1" ]; then
find_version_number
run_tests
build
fi
if [ "${build_driver}" == "1" ]; then
build_driver_now
fi
echo "A computer restart is required"
popd