-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·312 lines (278 loc) · 7.32 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
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
#!/bin/bash -e
# ======================================================================
# Build script for Freifunk Marburg firmware
#
# Source: https://github.com/hackspace-marburg/ffmr-site
# Original: https://github.com/freifunk-fulda
# Contact: [email protected]
# Web: https://marburg.freifunk.net
#
# Credits:
# - Freifunk Darmstadt for your great support
# - Freifunk Fulda for the build process and their overall hospitality
# ======================================================================
# Default make options
MAKEOPTS="-j 4 V=s"
# Default to build all Gluon targets if parameter -t is not set
TARGETS="ar71xx-generic ar71xx-nand ar71xx-tiny ath79-generic brcm2708-bcm2708 brcm2708-bcm2709 ipq40xx-generic ipq806x-generic lantiq-xrx200 lantiq-xway mpc85xx-generic mpc85xx-p1020 ramips-mt7620 ramips-mt7621 ramips-mt76x8 ramips-rt305x sunxi-cortexa7 x86-generic x86-geode x86-64"
# Default is set to use current work directory
SITEDIR="$(pwd)"
# Default build identifier set to snapshot
BUILD="snapshot"
# Specify deployment server and user
DEPLOYMENT_SERVER="firmware.marburg.freifunk.net"
DEPLOYMENT_SERVER_PORT=7331
DEPLOYMENT_USER="firmware"
# Error codes
E_ILLEGAL_ARGS=126
# Help function used in error messages and -h option
usage() {
echo ""
echo "Build script for Freifunk Marburg gluon firmware."
echo ""
echo "-b: Firmware branch name (e.g. development)"
echo " Default: current git branch"
echo "-c: Build command: update | download | build | manifest | sign | upload"
echo "-d: Enable bash debug output"
echo "-h: Show this help"
echo "-m: Setting for make options (optional)"
echo " Default: \"${MAKEOPTS}\""
echo "-n: Build identifier (optional)"
echo " Default: \"${BUILD}\""
echo "-t: Gluon targets architectures to build"
echo " Default: \"${TARGETS}\""
echo "-k: Allow broken targets (optional)"
echo " Default: 0"
echo "-r: Release number (optional)"
echo " Default: fetched from release file"
echo "-w: Path to site directory"
echo " Default: current working directory"
}
# Evaluate arguments for build script.
if [[ "${#}" == 0 ]]; then
usage
exit ${E_ILLEGAL_ARGS}
fi
# Evaluate arguments for build script.
while getopts b:c:dhm:n:t:r:kw: flag; do
case ${flag} in
b)
BRANCH="${OPTARG}"
;;
c)
case "${OPTARG}" in
update)
COMMAND="${OPTARG}"
;;
download)
COMMAND="${OPTARG}"
;;
build)
COMMAND="${OPTARG}"
;;
manifest)
COMMAND="${OPTARG}"
;;
sign)
COMMAND="${OPTARG}"
;;
upload)
COMMAND="${OPTARG}"
;;
*)
echo "Error: Invalid build command set."
usage
exit ${E_ILLEGAL_ARGS}
;;
esac
;;
d)
set -x
;;
h)
usage
exit
;;
m)
MAKEOPTS="${OPTARG}"
;;
n)
BUILD="${OPTARG}"
;;
t)
TARGETS="${OPTARG}"
;;
r)
RELEASE="${OPTARG}"
;;
k)
BROKEN=1
;;
w)
# Use the root project as site-config for make commands below
SITEDIR="${OPTARG}"
;;
*)
usage
exit ${E_ILLEGAL_ARGS}
;;
esac
done
# Strip of all remaining arguments
shift $((OPTIND - 1));
# Check if there are remaining arguments
if [[ "${#}" > 0 ]]; then
echo "Error: To many arguments: ${*}"
usage
exit ${E_ILLEGAL_ARGS}
fi
# Set branch name
if [[ -z "${BRANCH}" ]]; then
BRANCH=$(git symbolic-ref -q HEAD)
BRANCH=${BRANCH##refs/heads/}
BRANCH=${BRANCH:-HEAD}
fi
# Set command
if [[ -z "${COMMAND}" ]]; then
echo "Error: Build command missing."
usage
exit ${E_ILLEGAL_ARGS}
fi
# Set release number
if [[ -z "${RELEASE}" ]]; then
RELEASE=$(cat "${SITEDIR}/release")
fi
# Normalize the branch name
BRANCH="${BRANCH#origin/}" # Use the current git branch as autoupdate branch
BRANCH="${BRANCH//\//-}" # Replace all slashes with dashes
# Add the build identifer to the release identifier.
RELEASE="${RELEASE}-${BUILD}"
# Number of days that may pass between releasing an updating
PRIORITY=1
update() {
make ${MAKEOPTS} \
GLUON_BRANCH="${BRANCH}" \
GLUON_RELEASE="${RELEASE}" \
GLUON_PRIORITY="${PRIORITY}" \
GLUON_SITEDIR="${SITEDIR}" \
BROKEN="${BROKEN}" \
update
for TARGET in ${TARGETS}; do
echo "--- Updating Gluon Dependencies for target: ${TARGET}"
make ${MAKEOPTS} \
GLUON_BRANCH="${BRANCH}" \
GLUON_RELEASE="${RELEASE}" \
GLUON_PRIORITY="${PRIORITY}" \
GLUON_SITEDIR="${SITEDIR}" \
GLUON_TARGET="${TARGET}" \
BROKEN="${BROKEN}" \
dirclean
done
}
download() {
for TARGET in ${TARGETS}; do
echo "--- Downloading Gluon Dependencies for target: ${TARGET}"
make ${MAKEOPTS} \
GLUON_BRANCH="${BRANCH}" \
GLUON_RELEASE="${RELEASE}" \
GLUON_PRIORITY="${PRIORITY}" \
GLUON_SITEDIR="${SITEDIR}" \
GLUON_TARGET="${TARGET}" \
BROKEN="${BROKEN}" \
download
done
}
build() {
for TARGET in ${TARGETS}; do
echo "--- Building Gluon Images for target: ${TARGET}"
make ${MAKEOPTS} \
GLUON_BRANCH="${BRANCH}" \
GLUON_RELEASE="${RELEASE}" \
GLUON_PRIORITY="${PRIORITY}" \
GLUON_SITEDIR="${SITEDIR}" \
GLUON_TARGET="${TARGET}" \
BROKEN="${BROKEN}" \
all
done
}
manifest() {
echo "--- Building Gluon Manifest: ${TARGET}"
[[ ! -d tmp ]] && mkdir tmp
make ${MAKEOPTS} \
GLUON_BRANCH="${BRANCH}" \
GLUON_RELEASE="${RELEASE}" \
GLUON_PRIORITY="${PRIORITY}" \
GLUON_SITEDIR="${SITEDIR}" \
BROKEN="${BROKEN}" \
manifest
}
sign() {
echo "--- Signing Gluon Firmware Build"
# Add the signature to the local manifest
contrib/sign.sh \
"${HOME}/autoupdate_secret_ci" \
"output/images/sysupgrade/${BRANCH}.manifest"
}
upload() {
echo "--- Uploading Gluon Firmware Images and Manifest"
# Build the ssh command to use
SSH="ssh"
#SSH="${SSH} -i ${HOME}/.ssh/id_rsa"
#SSH="${SSH} -o stricthostkeychecking=no"
SSH="${SSH} -p ${DEPLOYMENT_SERVER_PORT}"
# Determine upload target prefix
case "${BRANCH}" in
stable| \
snapshot| \
experimental)
TARGET="${BRANCH}"
;;
*)
TARGET="others/${BRANCH}"
;;
esac
# Create the module and target directories on server
${SSH} \
${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER} \
-- \
mkdir \
--parents \
--verbose \
"modules/" \
"firmware/${TARGET}/${RELEASE}"
# Copy packages / modules to server
rsync \
--verbose \
--recursive \
--compress \
--copy-links \
--rsh="${SSH}" \
"output/packages/" \
"${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER}:modules/"
# Copy images to server
rsync \
--verbose \
--recursive \
--compress \
--progress \
--copy-links \
--rsh="${SSH}" \
"output/images/" \
"${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER}:firmware/${TARGET}/${RELEASE}"
# Link latest upload in target to web
${SSH} \
${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER} \
-- \
ln \
--symbolic \
--force \
--no-target-directory \
"${RELEASE}" \
"firmware/${TARGET}/current"
}
(
# Change working directory to gluon tree
cd "${SITEDIR}/gluon"
# Execute the selected command
${COMMAND}
)