forked from FreifunkBremen/gluon-site-ffhb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·159 lines (137 loc) · 4.2 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
#! /usr/bin/env sh
FIRMWARE_URL="http://downloads.bremen.freifunk.net/firmware/"
LOCAL_SUFFIX="bremen"
GLUON_DIR="gluon/"
KEYFILE="$HOME/.ecdsakey"
set -eu
export GLUON_SITEDIR="$(dirname "$(realpath "$0")")"
get_GLUON_TAG() {
if ! git --git-dir="${GLUON_DIR}/.git" describe --exact-match; then
echo 'The gluon tree is not checked out at a tag.'
echo 'Please use `git checkout <tagname>` to use an official gluon release'
echo 'or build it manually. Only with at a tag we can autogenerate the'
echo 'release string!'
exit 1
fi
}
get_last_release() {
branch="$1"
wget -q -O- "${FIRMWARE_URL}/${branch}/sysupgrade/${branch}.manifest" | \
awk 'parse == 1 { print $2; exit } /^$/ { parse=1 }'
}
is_based_on() {
[ "${1#$2}" != "${1}" ]
return $?
}
extract_local_version() {
local_version_tmp="${1#*+${LOCAL_SUFFIX}}"
echo "${local_version_tmp%~testing}"
}
if [ "$#" = 0 ]; then
cat <<USAGE
Usage: $(basename $0) [--debug] <branch>
This script takes the intended branch, "testing" or "stable", as the single
parameter. It then tries to autodetermine the correct release name, builds
gluon for the corresponding branch and all supported platforms (excluding
x86*), and optionally signs it if an ecdsutils keyfile is found (standard path:
~/.ecdsakey)
USAGE
exit 1
fi
debug=
if [ "$1" = "--debug" ]; then
debug=1
shift
fi
GLUON_BRANCH="$1"
if [ "$GLUON_BRANCH" != "testing" -a "$GLUON_BRANCH" != "stable" ]; then
echo "Branch not supported yet!"
exit 1
fi
GLUON_TAG="$(get_GLUON_TAG)"
# remove prefixed "v"
GLUON_TAG="${GLUON_TAG#v}"
statefile="${GLUON_SITEDIR}/.build.${GLUON_BRANCH}.${GLUON_TAG}"
cont=false
if [ -f "$statefile" ]; then
echo "A previous build for this version was aborted."
echo "These were the parameters:"
cat "$statefile"
echo "You can now either continue the previous build or begin a new one"
echo "and overwrite the old state file."
read -p "Do you want to continue the previous build? [Yn] " answer
case "${answer:-y}" in
[yY]*)
. "$statefile"
cont=true
;;
*)
rm "$statefile"
;;
esac
fi
if ! $cont; then
echo "Building Gluon ${GLUON_TAG} as ${GLUON_BRANCH}"
last_release_testing="$(get_last_release testing)"
last_release_stable="$(get_last_release stable)"
echo "Last release in branch testing was ${last_release_testing}"
if is_based_on "$last_release_testing" "$GLUON_TAG"; then
local_version="$(extract_local_version "$last_release_testing")"
if [ "$GLUON_BRANCH" != "stable" ]; then
local_version="$(($local_version + 1))"
fi
elif [ "$GLUON_BRANCH" = "stable" ] && is_based_on "$last_release_stable" "$GLUON_TAG"; then
local_version="$(extract_local_version "$last_release_stable")"
local_version="$(($local_version + 1))"
else
# new gluon version => reset local version number
local_version=1
fi
if [ "$GLUON_BRANCH" = "testing" ]; then
local_version="${local_version}~testing"
fi
auto_determined_release="${GLUON_TAG}+${LOCAL_SUFFIX}${local_version}"
read -p "Release name for this build [default: ${auto_determined_release}]: " GLUON_RELEASE
GLUON_RELEASE="${GLUON_RELEASE:-$auto_determined_release}"
cat > "$statefile" <<EOF
GLUON_TAG="${GLUON_TAG}"
GLUON_BRANCH="${GLUON_BRANCH}"
GLUON_RELEASE="${GLUON_RELEASE}"
EOF
fi
if [ "$GLUON_BRANCH" = "stable" ]; then
export GLUON_PRIORITY=7
fi
# calculate number of threads
if [ -z "$debug" ]; then
proc_num="$(($(grep -c '^processor\s' /proc/cpuinfo) + 1))"
else
proc_num=1
fi
cd "$GLUON_DIR"
export GLUON_BRANCH GLUON_RELEASE
if ! $cont; then
make update ${debug:+V=s}
fi
for target in ar71xx-generic ar71xx-nand mpc85xx-generic x86-generic; do
env_target="$(echo "$target" | tr '-' '_')"
set +u
if eval "[ \"\$TARGET_${env_target}_DONE\" = 1 ]"; then
continue
fi
set -u
echo "Building target ${target}"
if $cont; then
cont=false
else
make clean GLUON_TARGET="$target" ${debug:+V=s}
fi
make -j${proc_num} GLUON_TARGET="$target" ${debug:+V=s}
echo "TARGET_${env_target}_DONE=1" >> "$statefile"
done
make manifest
cd ..
if [ -n "$KEYFILE" -a -r "$KEYFILE" ]; then
"${GLUON_DIR}/contrib/sign.sh" "$KEYFILE" "${GLUON_DIR}/images/sysupgrade/${GLUON_BRANCH}.manifest"
fi
rm "$statefile"