This repository has been archived by the owner on Jun 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.sh
115 lines (98 loc) · 3.25 KB
/
functions.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
#!/bin/bash
# Copyright (c) Rolf Jagerman, Laurens Versluis and Martijn de Vos, 2014.
# This defines all the functions needed for the build.sh script.
# As this script will be tested, functions are separated from the build.sh
red="\x1B[0;31m"
yellow="\x1B[0;33m"
green="\x1B[0;32m"
blue="\x1B[0;34m"
NC="\x1B[0m"
logfile="${CURRENTFOLDERPATH}/build.log"
function error() {
echo -e "${red}$@${NC}"
}
function warning() {
echo -e "${yellow}$@${NC}"
}
function info() {
echo -e "${blue}$@${NC}"
}
function try () {
"$@"
if [ ! $? -eq 0 ] ; then
error "Failure while running:"
echo -e "$@"
exit 1
fi
}
function checkDirectoryExist() {
# If the specified app folder does not exist, we throw an error.
if [ ! -e "${CURRENTFOLDERPATH}/${APPNAME}/" ]; then
# Throw an error since folders are missing
error "You need to have a folder ${CURRENTFOLDERPATH}/${APPNAME}/, aborting."
exit 1
fi
}
function generateFolders() {
# If the app folder in AT3 does not exist, create it.
if [ ! -e "${CURRENTFOLDERPATH}/app" ]; then
warning "${CURRENTFOLDERPATH}/app does not exist! Attempting to create it"
try mkdir -p "${CURRENTFOLDERPATH}/app"
fi
}
function checkDistFolderExist() {
# Check if destination exist
if [ -e "${PY4APATH}/dist/${DIRNAME}" ]; then
error "The distribution ${PY4APATH}/dist/${DIRNAME} already exist"
error "Press a key to remove it, or Control + C to abort."
read
try rm -rf "${PY4APATH}/dist/${DIRNAME}"
fi
}
function setSplash() {
# Sets the splash screen if it exists
if [ -f "${CURRENTFOLDERPATH}/${APPNAME}/${APPSPLASH}" ]; then
APPSPLASHFLAG="--presplash ${CURRENTFOLDERPATH}/${APPNAME}/${APPSPLASH}"
fi
}
function setIcon() {
# Sets the icon if it exists
if [ -f "${CURRENTFOLDERPATH}/${APPNAME}/${APPSPLASH}" ]; then
APPICONFLAG="--icon ${CURRENTFOLDERPATH}/${APPNAME}/${APPICON}"
fi
}
function clean() {
# Clean the environment from previously compiled files
cd ${CURRENTFOLDERPATH}
try find ${CURRENTFOLDERPATH} -iname "*.pyo" -exec rm '{}' ';'
try find ${CURRENTFOLDERPATH} -iname "*.pyc" -exec rm '{}' ';'
}
function build() {
# Build a distribute folder with all the packages now that kivy has been set
info "Building a python-for-android distribution"
PREVPATH=`pwd`
cd $PY4APATH
try ./distribute.sh -m "`cat ${CURRENTFOLDERPATH}/${APPNAME}/python-for-android.deps`" -d $DIRNAME #&> $logfile
cd $PREVPATH
# Build the .apk
cd "${PY4APATH}/dist/${DIRNAME}/"
info "Building the APK"
try ./build.py --package org.tribler.at3.${APPNAME} --name "AT3 ${APPNAME}" --version 1.0 --dir "${CURRENTFOLDERPATH}/${APPNAME}" debug --permission INTERNET $APPICONFLAG $APPSPLASHFLAG
# Copy the .apk files to our own app folder
info "Copying the APK"
try find "${PY4APATH}/dist/${DIRNAME}/bin" -type f -name '*.apk' -exec cp {} "${CURRENTFOLDERPATH}/app" \; # &> $logfile
# Delete the distribute and build now that the app has been made in the AT3 folder
#rm -rf "${PY4APATH}/dist/${DIRNAME}"
echo -e "${green}All done!${NC}"
}
# This functions first runs checks on wheter certain files and folders exist.
# If they do and all passes, the build function is run.
function main() {
try checkDirectoryExist
try checkDistFolderExist &&
try setSplash &&
try setIcon &&
try generateFolders &&
try clean &&
try build
}