-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-repo.sh
executable file
·234 lines (173 loc) · 6.11 KB
/
build-repo.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
#!/bin/sh
set -eu
ls -la /cache
sudo chmod o+w /cache
mkdir -p \
/cache/apk \
/cache/ccache
ALPINE_VERSION=${ALPINE_VERSION:-$(cat /etc/alpine-release | cut -d. -f1-2)}
repo_full=$1
BUILD_REPO_OPTIONS=
case "${KEEP_GOING:-no}" in
"y" | "yes" | "Yes" | "on" | "ON" ) BUILD_REPO_OPTIONS="${BUILD_REPO_OPTIONS} -k";;
esac
case "${PURGE_OBSOLETE:-no}" in
"y" | "yes" | "Yes" | "on" | "ON" ) BUILD_REPO_OPTIONS="${BUILD_REPO_OPTIONS} -p";;
esac
if [ -n "${ADDITIONAL_APK_REPO:-}" ]; then
echo "${ADDITIONAL_APK_REPO}" | sudo tee -a /etc/apk/repositories
fi
# Disable stack protection to improve performance
CFLAGS="-fomit-frame-pointer -march=x86-64 -mtune=generic -Os"
case "${STACK_PROTECTOR:-yes}" in
"n" | "no" | "No" | "off" | "OFF" )
CFLAGS="${CFLAGS} -fno-stack-protector"
echo "Stack protector is disabled"
;;
esac
echo "export CFLAGS=\"${CFLAGS}\"" | sudo tee -a /etc/abuild.conf
if [ "${ALPINE_VERSION}" != "3.17" ]; then
echo "export CXXFLAGS=\"-std=c++14\"" | sudo tee -a /etc/abuild.conf
fi
# Overwrite make setting if provided
if [ ! -z "${JOBS}" ]; then
echo "export JOBS=${JOBS}" | sudo tee -a /etc/abuild.conf
fi
echo 'export MAKEFLAGS="-j$JOBS -l$JOBS"' | sudo tee -a /etc/abuild.conf
# Copy depending repository
DEPSDIR=${HOME}/deps.rw
mkdir -p ${DEPSDIR}
repos="$(cd ${HOME}/deps 2>/dev/null && ls -1 || true)"
for r in ${repos}; do
sudo cp -r ${HOME}/deps/${r} ${DEPSDIR}/${r}
sudo chmod -R a+w ${DEPSDIR}/${r}
done
# Generate temporary private key if not present
if [ ! -f ${PACKAGER_PRIVKEY} ]; then
echo "======== WARN: PACKAGER_PRIVKEY is not present ======="
abuild-keygen -a -i -n
RESIGN=true
else
echo "Using ${PACKAGER_PRIVKEY}"
openssl rsa -in ${PACKAGER_PRIVKEY} -pubout | sudo tee ${PACKAGER_PRIVKEY}.pub
fi
sudo cp ${HOME}/.abuild/*.pub /etc/apk/keys/
if ${RESIGN:-false}
then
# Re-sign packages if private key is updated
for index in $(
find ${REPODIR} -name APKINDEX.tar.gz || true
find ${DEPSDIR} -name APKINDEX.tar.gz || true
); do
echo "Resigning ${index}"
rm -f ${index}
apk index --allow-untrusted -o ${index} $(find $(dirname ${index})/../ -name '*.apk')
abuild-sign -k /home/builder/.abuild/*.rsa ${index}
done
echo
fi
# Register local repositories
echo "Local repositories:"
for path in $(find ${DEPSDIR} -name APKINDEX.tar.gz || true); do
arch_path=$(dirname ${path})
repo_path=$(dirname ${arch_path})
echo "${repo_path}" | sudo tee -a /etc/apk/repositories
done
echo
repo=${repo_full}
if [ ${repo_full} != $(basename ${repo_full}) ]; then
repo=$(basename ${repo})
fi
repo_out=${repo}
echo "APORTSDIR: ${APORTSDIR}"
echo "REPODIR: ${REPODIR}"
echo "target repository: ${repo} ${repo_full}"
echo
if [ ! -d ${SRCDIR}/${repo_full} ]; then
echo "${repo_full} is not present. Skipping."
exit 0
fi
# Copy noarch pkgs
sudo cp -p ${REPODIR}/${repo_out}/noarch/* ${REPODIR}/${repo_out}/x86_64/ 2>/dev/null || true
# Build packages
mkdir -p ${APORTSDIR}
cp -r ${SRCDIR}/${repo_full} ${APORTSDIR}/${repo_out}
sed -e 's/arch="noarch.*"/arch="all"/' -i $(find ${APORTSDIR} -name APKBUILD)
sed -e 's/:noarch//' -i $(find ${APORTSDIR} -name APKBUILD)
# Remove python2 builds on new environments
ALPINE_VERSION_MAJOR=$(echo ${ALPINE_VERSION} | cut -f1 -d.)
ALPINE_VERSION_MINOR=$(echo ${ALPINE_VERSION} | cut -f2 -d.)
echo "ALPINE_VERSION: major(${ALPINE_VERSION_MAJOR}) minor(${ALPINE_VERSION_MINOR})"
ls ${APORTSDIR}
if [ ${ALPINE_VERSION_MAJOR} -eq 3 -a ${ALPINE_VERSION_MINOR} -ge 11 ]; then
echo "Removing py2 from >=v3.11 aports"
py_apkbuilds=$(find ${APORTSDIR}/backports/ -name APKBUILD 2> /dev/null || true)
if [ ! -z "${py_apkbuilds}" ]; then
echo "${py_apkbuilds}" | xargs -r -n1 echo "-"
sed 's/\<python2-dev\>//g' -i ${py_apkbuilds} # Remove python2-dev dep
sed 's/\<py2-${pkgname#py-}:_py2\>//g' -i ${py_apkbuilds} # Remove py2- subpackage
sed 's/\<py2-$\S*pkgname:_py2\>//g' -i ${py_apkbuilds} # Remove py2- subpackage
sed 's/^\s*python2\s/#\0/g' -i ${py_apkbuilds} # Remove python2 commands
sed '/depends/s/\<py2-\S*\>//g' -i ${py_apkbuilds} # Remove py2- dependencies
else
echo "Skipping py2 removal"
fi
fi
sudo apk update
set +e
(
set -o pipefail
echo "buildrepo ${repo_out} -d ${REPODIR} -a ${APORTSDIR} ${BUILD_REPO_OPTIONS}"
time buildrepo ${repo_out} -d ${REPODIR} -a ${APORTSDIR} ${BUILD_REPO_OPTIONS} 2>&1 \
| grep --line-buffered \
-v -e "remote: Counting objects: " \
-v -e "remote: Compressing objects: " \
-v -e "Receiving objects: " \
-v -e "Resolving deltas: "
)
exit_code=$?
set -e
# Generate package index
index=${REPODIR}/${repo_out}/x86_64/APKINDEX.tar.gz
apk index --allow-untrusted -o ${index} \
$(find $(dirname ${index}) -name '*.apk')
tmpdir=$(mktemp -d)
(cd ${tmpdir} && tar xzf ${index} && ls -la)
# Move noarch packages
mkdir -p ${REPODIR}/${repo_out}/noarch/
rm ${REPODIR}/${repo_out}/noarch/*.apk 2>/dev/null || true
cat ${tmpdir}/APKINDEX \
| sed -n '/^P:/{s/^\S:\(.*\)$/\1 ARCH/p; {:l; n; /^A:/{s/^\S://p; d;}; b l;}};' \
| sed -n '/ARCH$/{N; s/ARCH\n//p;}' \
| while read apk; do
pkg=$(echo ${apk} | cut -f1 -d" ")
arch=$(echo ${apk} | cut -f2 -d" ")
if [ "${arch}" = "noarch" ]; then
echo "${pkg} is noarch"
mv ${REPODIR}/${repo_out}/x86_64/${pkg}-* ${REPODIR}/${repo_out}/noarch/
fi
done
rm -rf ${tmpdir}
# Re-sign
rm -f ${index}
apk index --allow-untrusted -o ${index} \
$(find $(dirname ${index})/../ -name '*.apk')
abuild-sign -k /home/builder/.abuild/*.rsa ${index}
if [ ${exit_code} -ne 0 ]; then
exit ${exit_code}
fi
# Test dependencies
echo "${REPODIR}/${repo_out}" | sudo tee -a /etc/apk/repositories
touch /tmp/local_pkgs
find ${REPODIR}/${repo_out} -name APKINDEX.tar.gz | while read path; do
arch_path=$(dirname ${path})
repo_path=$(dirname ${arch_path})
tmpdir=$(mktemp -d)
(cd ${tmpdir} && tar xzfv ${path})
cat ${tmpdir}/APKINDEX | sed -n "/^P:/s/^P://p" >> /tmp/local_pkgs
rm -rf ${tmpdir}
done
echo
echo "Installing all local packages for dependency check"
sudo apk add --virtual .install-test --force-overwrite $(cat /tmp/local_pkgs)
sudo apk del .install-test