forked from droboports/openssh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·209 lines (188 loc) · 5.29 KB
/
build.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
#!/usr/bin/env bash
### bash best practices ###
# exit on error code
set -o errexit
# exit on unset variable
set -o nounset
# return error of last failed command in pipe
set -o pipefail
# expand aliases
shopt -s expand_aliases
# print trace
set -o xtrace
### logfile ###
timestamp="$(date +%Y-%m-%d_%H-%M-%S)"
logfile="logfile_${timestamp}.txt"
echo "${0} ${@}" > "${logfile}"
if [ -z "${CONTINUOUS_INTEGRATION:-}" ]; then
# save stdout to logfile
exec 1> >(tee -a "${logfile}")
# redirect errors to stdout
exec 2> >(tee -a "${logfile}" >&2)
else
exec 1> "${logfile}"
exec 2> >(tee -a "${logfile}" >&2)
fi
### environment setup ###
. crosscompile.sh
export NAME="$(basename ${PWD})"
export DEST="${BUILD_DEST:-/mnt/DroboFS/Shares/DroboApps/${NAME}}"
export DEPS="${PWD}/target/install"
export CFLAGS="${CFLAGS:-} -Os -fPIC"
export CXXFLAGS="${CXXFLAGS:-} ${CFLAGS}"
export CPPFLAGS="-I${DEPS}/include"
export LDFLAGS="${LDFLAGS:-} -Wl,-rpath,${DEST}/lib -L${DEST}/lib"
alias make="make -j4 V=1 VERBOSE=1"
_wget() {
if [ -z "${CONTINUOUS_INTEGRATION:-}" ]; then
wget "$@"
else
wget --no-check-certificate "$@"
fi
}
### support functions ###
# Download a TAR file and unpack it, removing old files.
# $1: file
# $2: url
# $3: folder
_download_tar() {
[[ ! -d "download" ]] && mkdir -p "download"
[[ ! -d "target" ]] && mkdir -p "target"
[[ ! -f "download/${1}" ]] && _wget -O "download/${1}" "${2}"
[[ -d "target/${3}" ]] && rm -vfr "target/${3}"
[[ ! -d "target/${3}" ]] && tar -xvf "download/${1}" -C target
return 0
}
# Download a TGZ file and unpack it, removing old files.
# $1: file
# $2: url
# $3: folder
_download_tgz() {
[[ ! -d "download" ]] && mkdir -p "download"
[[ ! -d "target" ]] && mkdir -p "target"
[[ ! -f "download/${1}" ]] && _wget -O "download/${1}" "${2}"
[[ -d "target/${3}" ]] && rm -vfr "target/${3}"
[[ ! -d "target/${3}" ]] && tar -zxvf "download/${1}" -C target
return 0
}
# Download a BZ2 file and unpack it, removing old files.
# $1: file
# $2: url
# $3: folder
_download_bz2() {
[[ ! -d "download" ]] && mkdir -p "download"
[[ ! -d "target" ]] && mkdir -p "target"
[[ ! -f "download/${1}" ]] && _wget -O "download/${1}" "${2}"
[[ -d "target/${3}" ]] && rm -vfr "target/${3}"
[[ ! -d "target/${3}" ]] && tar -jxvf "download/${1}" -C target
return 0
}
# Download a XZ file and unpack it, removing old files.
# $1: file
# $2: url
# $3: folder
_download_xz() {
[[ ! -d "download" ]] && mkdir -p "download"
[[ ! -d "target" ]] && mkdir -p "target"
[[ ! -f "download/${1}" ]] && _wget -O "download/${1}" "${2}"
[[ -d "target/${3}" ]] && rm -vfr "target/${3}"
[[ ! -d "target/${3}" ]] && tar -Jxvf "download/${1}" -C target
return 0
}
# Download a ZIP file and unpack it, removing old files.
# $1: file
# $2: url
# $3: folder
_download_zip() {
[[ ! -d "download" ]] && mkdir -p "download"
[[ ! -d "target" ]] && mkdir -p "target"
[[ ! -f "download/${1}" ]] && _wget -O "download/${1}" "${2}"
[[ -d "target/${3}" ]] && rm -vfr "target/${3}"
[[ ! -d "target/${3}" ]] && unzip -d "target" "download/${1}"
return 0
}
# Download a DroboApp and unpack it, removing old files.
# $1: file
# $2: url
# $3: folder
_download_app() {
[[ ! -d "download" ]] && mkdir -p "download"
[[ ! -d "target" ]] && mkdir -p "target"
[[ ! -f "download/${1}" ]] && _wget -O "download/${1}" "${2}"
[[ -d "target/${3}" ]] && rm -vfr "target/${3}"
mkdir -p "target/${3}"
tar -zxvf "download/${1}" -C "target/${3}"
return 0
}
# Clone last commit of a single branch from git, removing old files.
# $1: branch
# $2: folder
# $3: url
_download_git() {
[[ ! -d "target" ]] && mkdir -p "target"
[[ -d "target/${2}" ]] && rm -vfr "target/${2}"
[[ ! -d "target/${2}" ]] && git clone --branch "${1}" --single-branch --depth 1 "${3}" "target/${2}"
return 0
}
# Download a file, overwriting existing.
# $1: file
# $2: url
_download_file() {
[[ ! -d "download" ]] && mkdir -p "download"
[[ ! -f "download/${1}" ]] && _wget -O "download/${1}" "${2}"
return 0
}
# Download a file in a specific folder, overwriting existing.
# $1: file
# $2: url
# $3: folder
_download_file_in_folder() {
[[ ! -d "download/${3}" ]] && mkdir -p "download/${3}"
[[ ! -f "download/${3}/${1}" ]] && _wget -O "download/${3}/${1}" "${2}"
return 0
}
# Create the DroboApp tgz file.
_create_tgz() {
local FILE="${PWD}/${NAME}.tgz"
if [[ -f "${FILE}" ]]; then
rm -v "${FILE}"
fi
pushd "${DEST}"
tar --verbose --create --numeric-owner --owner=0 --group=0 --gzip --file "${FILE}" *
popd
}
# Package the DroboApp
_package() {
mkdir -p "${DEST}"
[[ -d "src/dest" ]] && cp -vafR "src/dest"/* "${DEST}"/
find "${DEST}" -name "._*" -print -delete
_create_tgz
}
# Remove all compiled files.
_clean() {
rm -vfr "${DEPS}"
rm -vfr "${DEST}"
rm -vfr target/*
}
# Removes all files created during the build.
_dist_clean() {
_clean
rm -vf logfile*
rm -vfr download/*
}
### application-specific functions ###
. app.sh
if [ -n "${1:-}" ]; then
while [ -n "${1:-}" ]; do
case "${1}" in
clean) _clean ;;
distclean) _dist_clean ;;
all) _build ;;
package) _package ;;
*) _build_${1} ;;
esac
shift
done
else
_build
fi