]>
Commit | Line | Data |
---|---|---|
8d876415 DK |
1 | #!/bin/sh -- # no runable script, just for vi |
2 | ||
5d76cee1 | 3 | EXIT_CODE=0 |
8c1dd12c | 4 | |
68042532 DK |
5 | while [ -n "$1" ]; do |
6 | if [ "$1" = "-q" ]; then | |
7 | export MSGLEVEL=2 | |
8 | elif [ "$1" = "-v" ]; then | |
9 | export MSGLEVEL=4 | |
10 | elif [ "$1" = '--color=no' ]; then | |
11 | export MSGCOLOR='NO' | |
61e92778 DK |
12 | elif [ "$1" = '--color=yes' ]; then |
13 | export MSGCOLOR='YES' | |
14 | elif [ "$1" = '--color' ]; then | |
15 | export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')" | |
16 | shift | |
17 | elif [ "$1" = '--level' ]; then | |
18 | export MSGLEVEL=$2 | |
19 | shift | |
68042532 DK |
20 | else |
21 | echo >&2 "WARNING: Unknown parameter »$1« will be ignored" | |
22 | fi | |
23 | shift | |
24 | done | |
25 | export MSGLEVEL="${MSGLEVEL:-3}" | |
26 | ||
8d876415 | 27 | # we all like colorful messages |
61e92778 | 28 | if [ "${MSGCOLOR:-YES}" = 'YES' ]; then |
27cb4f6c | 29 | if [ ! -t 1 ]; then # but check that we output to a terminal |
1290422a DK |
30 | export MSGCOLOR='NO' |
31 | fi | |
32 | fi | |
33 | ||
34 | ||
35 | if [ "$MSGCOLOR" != 'NO' ]; then | |
36 | CERROR="\033[1;31m" # red | |
37 | CWARNING="\033[1;33m" # yellow | |
38 | CMSG="\033[1;32m" # green | |
39 | CINFO="\033[1;96m" # light blue | |
40 | CDEBUG="\033[1;94m" # blue | |
41 | CNORMAL="\033[0;39m" # default system console color | |
42 | CDONE="\033[1;32m" # green | |
43 | CPASS="\033[1;32m" # green | |
44 | CFAIL="\033[1;31m" # red | |
45 | CCMD="\033[1;35m" # pink | |
682a3bf7 | 46 | fi |
8d876415 | 47 | |
de81b2e2 DK |
48 | msgprintf() { |
49 | local START="$1" | |
50 | local MIDDLE="$2" | |
51 | local END="$3" | |
52 | shift 3 | |
53 | if [ -n "$1" ]; then | |
54 | printf "$START " "$1" | |
d73840dc | 55 | shift |
de81b2e2 | 56 | while [ -n "$1" ]; do |
bc8f83a5 | 57 | printf "$MIDDLE " "$(echo "$1" | sed -e 's#^apt\([cfghks]\)#apt-\1#')" |
de81b2e2 DK |
58 | shift |
59 | done | |
60 | fi | |
61 | printf "${END}" | |
2a2a7ef4 | 62 | } |
de81b2e2 DK |
63 | msgdie() { msgprintf "${CERROR}E: %s" '%s' "${CNORMAL}\n" "$@" >&2; exit 1; } |
64 | msgwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}\n" "$@" >&2; } | |
65 | msgmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}\n" "$@"; } | |
66 | msginfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}\n" "$@"; } | |
67 | msgdebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}\n" "$@"; } | |
68 | msgdone() { msgprintf "${CDONE}DONE" '%s' "${CNORMAL}\n" "$@"; } | |
69 | msgnwarn() { msgprintf "${CWARNING}W: %s" '%s' "${CNORMAL}" "$@" >&2; } | |
70 | msgnmsg() { msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@"; } | |
71 | msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; } | |
72 | msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; } | |
73 | msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; } | |
3c528b91 | 74 | msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; } |
1501a2c9 | 75 | msgreportheader() { |
68042532 | 76 | if [ -n "$MSGTEST_MSG" ]; then |
1501a2c9 | 77 | test "$1" != 'msgfailoutput' || echo |
ae7fce5a DK |
78 | if [ -n "$MSGTEST_MSGMSG" ]; then |
79 | echo "$MSGTEST_MSGMSG" | |
80 | fi | |
22ac12b2 | 81 | if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then |
1501a2c9 | 82 | echo "${CFAIL}Part of the test group: $MSGTEST_GRP" |
22ac12b2 | 83 | fi |
68042532 DK |
84 | echo -n "$MSGTEST_MSG" |
85 | unset MSGTEST_MSG | |
86 | fi | |
1501a2c9 DK |
87 | } |
88 | msgskip() { | |
89 | msgreportheader 'msgskip' | |
68ba0b7f DK |
90 | if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2; |
91 | else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi | |
92 | } | |
5229b285 | 93 | msgfail() { |
1501a2c9 | 94 | msgreportheader 'msgfail' |
68042532 | 95 | if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2; |
3c528b91 | 96 | else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi |
03aa0847 | 97 | if [ -n "$APT_DEBUG_TESTS" ]; then |
896f0ae8 | 98 | runapt $SHELL |
03aa0847 | 99 | fi |
5229b285 DK |
100 | EXIT_CODE=$((EXIT_CODE+1)); |
101 | } | |
9beb11aa DK |
102 | MSGGROUP_LEVEL=0 |
103 | msggroup() { | |
104 | if [ -n "$1" ]; then | |
105 | if [ $MSGGROUP_LEVEL = 0 ]; then | |
106 | MSGTEST_GRP='NEXT' | |
107 | fi | |
108 | MSGGROUP_LEVEL=$((MSGGROUP_LEVEL+1)); | |
109 | else | |
110 | MSGGROUP_LEVEL=$((MSGGROUP_LEVEL-1)); | |
111 | if [ $MSGGROUP_LEVEL = 0 ]; then | |
112 | unset MSGTEST_GRP | |
113 | fi | |
114 | fi | |
115 | } | |
8d876415 DK |
116 | |
117 | # enable / disable Debugging | |
fc89263e DK |
118 | if [ $MSGLEVEL -le 0 ]; then |
119 | msgdie() { true; } | |
120 | fi | |
121 | if [ $MSGLEVEL -le 1 ]; then | |
122 | msgwarn() { true; } | |
123 | msgnwarn() { true; } | |
124 | fi | |
125 | if [ $MSGLEVEL -le 2 ]; then | |
ae7fce5a DK |
126 | msgmsg() { |
127 | MSGTEST_MSGMSG="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")" | |
128 | } | |
fc89263e | 129 | msgnmsg() { true; } |
9beb11aa DK |
130 | msgtest() { |
131 | MSGTEST_MSG="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")" | |
132 | if [ "$MSGTEST_GRP" = 'NEXT' ]; then | |
133 | MSGTEST_GRP="$MSGTEST_MSG" | |
134 | fi | |
135 | } | |
3c528b91 | 136 | msgpass() { printf " ${CPASS}P${CNORMAL}"; } |
fc89263e DK |
137 | fi |
138 | if [ $MSGLEVEL -le 3 ]; then | |
139 | msginfo() { true; } | |
140 | msgninfo() { true; } | |
141 | fi | |
142 | if [ $MSGLEVEL -le 4 ]; then | |
143 | msgdebug() { true; } | |
144 | msgndebug() { true; } | |
145 | fi | |
146 | msgdone() { | |
147 | if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] || | |
148 | [ "$1" = "info" -a $MSGLEVEL -le 3 ] || | |
149 | [ "$1" = "msg" -a $MSGLEVEL -le 2 ] || | |
150 | [ "$1" = "warn" -a $MSGLEVEL -le 1 ] || | |
151 | [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then | |
152 | true; | |
153 | else | |
3c528b91 | 154 | printf "${CDONE}DONE${CNORMAL}\n"; |
fc89263e DK |
155 | fi |
156 | } | |
e43a426e MV |
157 | getaptconfig() { |
158 | if [ -f ./aptconfig.conf ]; then | |
5465192b | 159 | echo "$(readlink -f ./aptconfig.conf)" |
e43a426e | 160 | elif [ -f ../aptconfig.conf ]; then |
5465192b DK |
161 | echo "$(readlink -f ../aptconfig.conf)" |
162 | elif [ -f ../../aptconfig.conf ]; then | |
163 | echo "$(readlink -f ../../aptconfig.conf)" | |
164 | elif [ -f "${TMPWORKINGDIRECTORY}/aptconfig.conf" ]; then | |
165 | echo "$(readlink -f "${TMPWORKINGDIRECTORY}/aptconfig.conf")" | |
166 | fi | |
e43a426e | 167 | } |
8d876415 DK |
168 | runapt() { |
169 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
846856f4 DK |
170 | local CMD="$1" |
171 | shift | |
3abb6a6a | 172 | case "$CMD" in |
a311fb96 | 173 | sh|aptitude|*/*|command) ;; |
3b8eb3bc DK |
174 | *) CMD="${BUILDDIRECTORY}/$CMD";; |
175 | esac | |
896f0ae8 | 176 | MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@" |
8d876415 | 177 | } |
0390edd5 | 178 | runpython3() { runapt command python3 "$@"; } |
846856f4 DK |
179 | aptconfig() { runapt apt-config "$@"; } |
180 | aptcache() { runapt apt-cache "$@"; } | |
181 | aptcdrom() { runapt apt-cdrom "$@"; } | |
182 | aptget() { runapt apt-get "$@"; } | |
183 | aptftparchive() { runapt apt-ftparchive "$@"; } | |
184 | aptkey() { runapt apt-key "$@"; } | |
185 | aptmark() { runapt apt-mark "$@"; } | |
4f6d26b4 | 186 | aptsortpkgs() { runapt apt-sortpkgs "$@"; } |
796673c3 | 187 | apt() { runapt apt "$@"; } |
3b8eb3bc DK |
188 | apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; } |
189 | aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; } | |
190 | aptitude() { runapt aptitude "$@"; } | |
8d50b63f | 191 | aptextracttemplates() { runapt apt-extracttemplates "$@"; } |
3082603f | 192 | aptinternalsolver() { runapt "${APTINTERNALSOLVER}" "$@"; } |
ad7e0941 | 193 | aptdumpsolver() { runapt "${APTDUMPSOLVER}" "$@"; } |
8e99b22c | 194 | aptinternalplanner() { runapt "${APTINTERNALPLANNER}" "$@"; } |
3b8eb3bc | 195 | |
158fda31 | 196 | dpkg() { |
b0be0e09 | 197 | "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "$@" |
158fda31 | 198 | } |
ce7f128c | 199 | dpkgcheckbuilddeps() { |
63c71412 | 200 | command dpkg-checkbuilddeps --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" "$@" |
b6b5a542 | 201 | } |
3fa950f1 | 202 | gdb() { |
b07aeb1a DK |
203 | local CMD |
204 | case "$1" in | |
205 | aptget) CMD="apt-get";; | |
206 | aptcache) CMD="apt-cache";; | |
5465192b DK |
207 | aptcdrom) CMD="apt-cdrom";; |
208 | aptconfig) CMD="apt-config";; | |
b07aeb1a DK |
209 | aptmark) CMD="apt-mark";; |
210 | apthelper) CMD="apt-helper";; | |
3d8232bf | 211 | aptftparchive) CMD="apt-ftparchive";; |
63c71412 | 212 | dpkg) shift; runapt "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" "$@"; return;; |
b07aeb1a DK |
213 | *) CMD="$1";; |
214 | esac | |
ce928105 | 215 | shift |
921a9626 DK |
216 | if [ "${CMD##*/}" = "$CMD" ]; then |
217 | CMD="${BUILDDIRECTORY}/${CMD}" | |
218 | fi | |
219 | runapt command gdb --quiet -ex run "$CMD" --args "$CMD" "$@" | |
ae99ce2e | 220 | } |
0340069c | 221 | lastmodification() { |
0b45b6e5 | 222 | date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" -R |
0340069c DK |
223 | } |
224 | releasefiledate() { | |
0b45b6e5 | 225 | grep "^${2:-Date}:" "$1" | cut -d' ' -f 2- |
0340069c | 226 | } |
8d876415 | 227 | |
8c1dd12c | 228 | exitwithstatus() { |
f91bd741 MV |
229 | # error if we about to overflow, but ... |
230 | # "255 failures ought to be enough for everybody" | |
5d76cee1 MV |
231 | if [ $EXIT_CODE -gt 255 ]; then |
232 | msgdie "Total failure count $EXIT_CODE too big" | |
f91bd741 | 233 | fi |
5d76cee1 | 234 | exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255)); |
8c1dd12c MV |
235 | } |
236 | ||
804d4a0d DK |
237 | shellsetedetector() { |
238 | local exit_status=$? | |
239 | if [ "$exit_status" != '0' ]; then | |
3c528b91 | 240 | printf >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}\n" |
804d4a0d DK |
241 | if [ "$EXIT_CODE" = '0' ]; then |
242 | EXIT_CODE="$exit_status" | |
243 | fi | |
244 | fi | |
245 | } | |
246 | ||
b720d0bd | 247 | addtrap() { |
8437b7d4 DK |
248 | if [ "$1" = 'prefix' ]; then |
249 | CURRENTTRAP="$2 $CURRENTTRAP" | |
250 | else | |
251 | CURRENTTRAP="$CURRENTTRAP $1" | |
252 | fi | |
804d4a0d | 253 | trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM |
b720d0bd | 254 | } |
8d876415 | 255 | |
bc8f83a5 DK |
256 | escape_shell() { |
257 | echo "$@" | sed -e "s#'#'\"'\"'#g" | |
258 | } | |
259 | ||
8d876415 | 260 | setupenvironment() { |
0d303f17 DK |
261 | # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir) |
262 | if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then | |
263 | unset TMPDIR | |
264 | fi | |
63c71412 | 265 | TMPWORKINGDIRECTORY="$(mktemp -d)" |
bc8f83a5 DK |
266 | addtrap "cd /; rm -rf '$(escape_shell "$TMPWORKINGDIRECTORY")';" |
267 | if [ -n "$TMPDIR_ADD" ]; then | |
268 | TMPWORKINGDIRECTORY="${TMPWORKINGDIRECTORY}/${TMPDIR_ADD}" | |
269 | mkdir -p "$TMPWORKINGDIRECTORY" | |
270 | unset TMPDIR_ADD | |
271 | export TMPDIR="$TMPWORKINGDIRECTORY" | |
272 | fi | |
63c71412 | 273 | msgninfo "Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…" |
5c0dd6fc | 274 | |
03aa0847 | 275 | mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded" |
68ba0b7f DK |
276 | if [ "$(id -u)" = '0' ]; then |
277 | # relax permissions so that running as root with user switching works | |
278 | umask 022 | |
03aa0847 DK |
279 | chmod 711 "$TMPWORKINGDIRECTORY" |
280 | chown _apt:root "${TMPWORKINGDIRECTORY}/downloaded" | |
68ba0b7f DK |
281 | fi |
282 | ||
63c71412 | 283 | TESTDIRECTORY="$(readlink -f "$(dirname $0)")" |
5c0dd6fc | 284 | # allow overriding the default BUILDDIR location |
63c71412 DK |
285 | SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}" |
286 | BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"}" | |
287 | LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"}" | |
288 | METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"}" | |
289 | APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}" | |
290 | APTWEBSERVERBINDIR="${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"}" | |
291 | APTINTERNALSOLVER="${APT_INTEGRATION_TESTS_INTERNAL_SOLVER:-"${BUILDDIRECTORY}/apt-internal-solver"}" | |
292 | APTDUMPSOLVER="${APT_INTEGRATION_TESTS_DUMP_SOLVER:-"${BUILDDIRECTORY}/apt-dump-solver"}" | |
8e99b22c | 293 | APTINTERNALPLANNER="${APT_INTEGRATION_TESTS_INTERNAL_PLANNER:-"${BUILDDIRECTORY}/apt-internal-planner"}" |
8d876415 | 294 | test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" |
5c0dd6fc MV |
295 | # ----- |
296 | ||
63c71412 | 297 | cd "$TMPWORKINGDIRECTORY" |
cd725954 | 298 | mkdir rootdir aptarchive keys |
8d876415 | 299 | cd rootdir |
b29c3712 | 300 | mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d |
8fe964f1 | 301 | mkdir -p usr/bin var/cache var/lib var/log tmp |
cffea9af | 302 | mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers |
cd725954 | 303 | touch var/lib/dpkg/available |
8d876415 | 304 | mkdir -p usr/lib/apt |
63c71412 | 305 | ln -s "${METHODSDIR}" usr/lib/apt/methods |
1f6cf9e7 | 306 | if [ "$BUILDDIRECTORY" = "$LIBRARYPATH" ]; then |
8e99b22c | 307 | mkdir -p usr/lib/apt/solvers usr/lib/apt/planners |
1f6cf9e7 | 308 | ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/solvers/dump |
8e99b22c | 309 | ln -s "${BUILDDIRECTORY}/apt-dump-solver" usr/lib/apt/planners/dump |
1f6cf9e7 | 310 | ln -s "${BUILDDIRECTORY}/apt-internal-solver" usr/lib/apt/solvers/apt |
8e99b22c | 311 | ln -s "${BUILDDIRECTORY}/apt-internal-planner" usr/lib/apt/planners/apt |
b4f91d4d | 312 | echo "Dir::Bin::Solvers \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/solvers\";" >> ../aptconfig.conf |
8e99b22c | 313 | echo "Dir::Bin::Planners \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/planners\";" >> ../aptconfig.conf |
1f6cf9e7 | 314 | fi |
291a386f MV |
315 | # use the autoremove from the BUILDDIRECTORY if its there, otherwise |
316 | # system | |
63c71412 DK |
317 | if [ -e "${BUILDDIRECTORY}/../../debian/apt.conf.autoremove" ]; then |
318 | ln -s "${BUILDDIRECTORY}/../../debian/apt.conf.autoremove" etc/apt/apt.conf.d/01autoremove | |
291a386f MV |
319 | else |
320 | ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove | |
321 | fi | |
8d876415 | 322 | cd .. |
63c71412 DK |
323 | local BASENAME="${0##*/}" |
324 | local PACKAGESFILE="Packages-${BASENAME#*-}" | |
53ea1b56 DK |
325 | if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then |
326 | cp "${TESTDIRECTORY}/${PACKAGESFILE}" aptarchive/Packages | |
8f8169ac | 327 | fi |
63c71412 | 328 | local SOURCESSFILE="Sources-${BASENAME#*-}" |
53ea1b56 DK |
329 | if [ -f "${TESTDIRECTORY}/${SOURCESSFILE}" ]; then |
330 | cp "${TESTDIRECTORY}/${SOURCESSFILE}" aptarchive/Sources | |
8f8169ac | 331 | fi |
3abb6a6a DK |
332 | find "$TESTDIRECTORY" \( -name '*.pub' -o -name '*.sec' \) -exec cp '{}' keys/ \; |
333 | chmod 644 keys/* | |
63c71412 | 334 | ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg |
d6cf2345 | 335 | |
b4f91d4d | 336 | echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf |
94eb3bee | 337 | echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf |
8d876415 | 338 | echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf |
9d2a8a73 | 339 | echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf |
23e64f6d DK |
340 | # either store apt-key were we can access it, even if we run it as a different user |
341 | #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/" | |
342 | #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key" | |
343 | #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf | |
344 | # destroys coverage reporting though, so we disable changing user for the calling gpgv | |
345 | echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf | |
68ba0b7f | 346 | if [ "$(id -u)" = '0' ]; then |
007d8b48 DK |
347 | echo 'Binary::gpgv::APT::Sandbox::User "root";' >> aptconfig.conf |
348 | # same for the solver executables | |
349 | echo 'APT::Solver::RunAsUser "root";' >> aptconfig.conf | |
8e99b22c | 350 | echo 'APT::Planner::RunAsUser "root";' >> aptconfig.conf |
68ba0b7f | 351 | fi |
b0be0e09 | 352 | |
63c71412 | 353 | cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF |
b0be0e09 DK |
354 | #!/bin/sh |
355 | set -e | |
3abb6a6a | 356 | if [ -r '${TMPWORKINGDIRECTORY}/noopchroot.so' ]; then |
63c71412 | 357 | if [ -n "\$LD_LIBRARY_PATH" ]; then |
3abb6a6a | 358 | export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}:'"\${LD_LIBRARY_PATH}" |
b0be0e09 | 359 | else |
3abb6a6a | 360 | export LD_LIBRARY_PATH='${TMPWORKINGDIRECTORY}' |
b0be0e09 | 361 | fi |
921a9626 | 362 | if [ -n "\$LD_PRELOAD" ]; then |
63c71412 | 363 | export LD_PRELOAD="noopchroot.so \${LD_PRELOAD}" |
921a9626 | 364 | else |
63c71412 | 365 | export LD_PRELOAD="noopchroot.so" |
921a9626 DK |
366 | fi |
367 | fi | |
63c71412 DK |
368 | EOF |
369 | cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" | |
370 | cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF | |
3abb6a6a DK |
371 | exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\ |
372 | --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\ | |
63c71412 DK |
373 | --force-not-root --force-bad-path "\$@" |
374 | EOF | |
375 | cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF | |
3abb6a6a DK |
376 | exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\ |
377 | --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\ | |
b0be0e09 DK |
378 | --force-not-root --force-bad-path "\$@" |
379 | EOF | |
921a9626 | 380 | chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" |
b0be0e09 DK |
381 | echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg |
382 | ||
533fe3d1 DK |
383 | { |
384 | if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then | |
385 | echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it… | |
386 | fi | |
87d6947d | 387 | echo 'quiet "0";' |
533fe3d1 DK |
388 | echo 'quiet::NoUpdate "true";' |
389 | echo 'quiet::NoStatistic "true";' | |
390 | # too distracting for users, but helpful to detect changes | |
391 | echo 'Acquire::Progress::Ignore::ShowErrorText "true";' | |
392 | echo 'Acquire::Progress::Diffpercent "true";' | |
393 | # in testcases, it can appear as if localhost has a rotation setup, | |
394 | # hide this as we can't really deal with it properly | |
395 | echo 'Acquire::Failure::ShowIP "false";' | |
ebca2f25 DK |
396 | # fakeroot can't fake everything, so disabled in production but good for tests |
397 | echo 'APT::Sandbox::Verify "true";' | |
533fe3d1 | 398 | } >> aptconfig.conf |
d6cf2345 | 399 | |
68ba0b7f DK |
400 | cp "${TESTDIRECTORY}/apt.pem" "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" |
401 | if [ "$(id -u)" = '0' ]; then | |
402 | chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem" | |
403 | fi | |
404 | echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https | |
d6cf2345 | 405 | echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary |
08fcf962 | 406 | export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=no |
23d35ec1 | 407 | echo 'Acquire::Connect::AddrConfig "false";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig |
493a813e | 408 | |
276e51dd | 409 | configcompression '.' 'gz' #'bz2' 'lzma' 'xz' |
51c04562 | 410 | confighashes 'SHA256' # these are tests, not security best-practices |
77a45beb | 411 | |
4bb006d1 | 412 | # create some files in /tmp and look at user/group to get what this means |
eab57e08 | 413 | TEST_DEFAULT_USER="$(id -un)" |
4bb006d1 DK |
414 | if [ "$(uname)" = 'GNU/kFreeBSD' ]; then |
415 | TEST_DEFAULT_GROUP='root' | |
416 | else | |
eab57e08 | 417 | TEST_DEFAULT_GROUP="$(id -gn)" |
4bb006d1 DK |
418 | fi |
419 | ||
ce7f128c | 420 | # cleanup the environment a bit |
995a4bf6 | 421 | # prefer our apt binaries over the system apt binaries |
8c617819 | 422 | export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin" |
be233796 | 423 | export LC_ALL=C.UTF-8 |
3b8eb3bc | 424 | unset LANGUAGE APT_CONFIG |
ce7f128c | 425 | unset GREP_OPTIONS DEB_BUILD_PROFILES |
59f57473 | 426 | unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy |
0cbb7e29 JAK |
427 | |
428 | # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1 | |
429 | if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then | |
430 | echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1"; };' > rootdir/etc/apt/apt.conf.d/no-sha1 | |
431 | fi | |
432 | ||
5a23c56d DK |
433 | # most tests just need one signed Release file, not both |
434 | export APT_DONT_SIGN='Release.gpg' | |
435 | ||
8d876415 DK |
436 | msgdone "info" |
437 | } | |
438 | ||
ea65d079 DK |
439 | getarchitecture() { |
440 | if [ "$1" = "native" -o -z "$1" ]; then | |
441 | eval `aptconfig shell ARCH APT::Architecture` | |
442 | if [ -n "$ARCH" ]; then | |
443 | echo $ARCH | |
444 | else | |
5834d7a1 | 445 | dpkg --print-architecture |
ea65d079 DK |
446 | fi |
447 | else | |
448 | echo $1 | |
449 | fi | |
450 | } | |
451 | ||
53ea1b56 | 452 | getarchitectures() { |
081c9d44 | 453 | aptconfig dump --no-empty --format '%v%n' APT::Architecture APT::Architectures | sort -u | tr '\n' ' ' |
53ea1b56 DK |
454 | } |
455 | ||
3dcdc1f9 DK |
456 | getarchitecturesfromcommalist() { |
457 | echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/" | |
458 | } | |
459 | ||
8d876415 | 460 | configarchitecture() { |
18908589 DK |
461 | { |
462 | echo "APT::Architecture \"$(getarchitecture $1)\";" | |
463 | while [ -n "$1" ]; do | |
464 | echo "APT::Architectures:: \"$(getarchitecture $1)\";" | |
465 | shift | |
466 | done | |
467 | } >rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
53ea1b56 DK |
468 | configdpkg |
469 | } | |
470 | ||
471 | configdpkg() { | |
472 | if [ ! -e rootdir/var/lib/dpkg/status ]; then | |
63c71412 DK |
473 | local BASENAME="${0##*/}" |
474 | local STATUSFILE="status-${BASENAME#*-}" | |
53ea1b56 DK |
475 | if [ -f "${TESTDIRECTORY}/${STATUSFILE}" ]; then |
476 | cp "${TESTDIRECTORY}/${STATUSFILE}" rootdir/var/lib/dpkg/status | |
477 | else | |
478 | echo -n > rootdir/var/lib/dpkg/status | |
479 | fi | |
480 | fi | |
18908589 | 481 | rm -f rootdir/etc/apt/apt.conf.d/00foreigndpkg |
846856f4 | 482 | if command dpkg --assert-multi-arch >/dev/null 2>&1 ; then |
53ea1b56 DK |
483 | local ARCHS="$(getarchitectures)" |
484 | if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then | |
485 | DPKGARCH="$(dpkg --print-architecture)" | |
486 | for ARCH in ${ARCHS}; do | |
feae193b | 487 | if [ "${ARCH}" != "${DPKGARCH}" ]; then |
18908589 | 488 | if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then |
feae193b | 489 | # old-style used e.g. in Ubuntu-P – and as it seems travis |
18908589 DK |
490 | echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg |
491 | echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg | |
feae193b DK |
492 | fi |
493 | fi | |
53ea1b56 DK |
494 | done |
495 | if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then | |
05343a22 DK |
496 | # dpkg doesn't really check the version as long as it is fully installed, |
497 | # but just to be sure we choose one above the required version | |
498 | insertinstalledpackage 'dpkg' "all" '1.16.2+fake' | |
53ea1b56 DK |
499 | fi |
500 | fi | |
501 | fi | |
8d876415 DK |
502 | } |
503 | ||
0c787570 DK |
504 | configdpkgnoopchroot() { |
505 | # create a library to noop chroot() and rewrite maintainer script executions | |
506 | # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown | |
507 | # chroot directory dpkg could chroot into to execute the maintainer scripts | |
508 | msgtest 'Building library to preload to make maintainerscript work in' 'dpkg' | |
63c71412 | 509 | cat > noopchroot.c << EOF |
0c787570 DK |
510 | #define _GNU_SOURCE |
511 | #include <stdio.h> | |
512 | #include <stdlib.h> | |
513 | #include <string.h> | |
514 | #include <dlfcn.h> | |
515 | ||
516 | static char * chrootdir = NULL; | |
517 | ||
518 | int chroot(const char *path) { | |
519 | printf("WARNING: CHROOTing to %s was ignored!\n", path); | |
520 | free(chrootdir); | |
521 | chrootdir = strdup(path); | |
522 | return 0; | |
523 | } | |
524 | int execvp(const char *file, char *const argv[]) { | |
525 | static int (*func_execvp) (const char *, char * const []) = NULL; | |
526 | if (func_execvp == NULL) | |
527 | func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp"); | |
528 | if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0) | |
529 | return func_execvp(file, argv); | |
530 | printf("REWRITE execvp call %s into %s\n", file, chrootdir); | |
950733c9 JAK |
531 | char *newfile; |
532 | if (asprintf(&newfile, "%s%s", chrootdir, file) == -1) { | |
533 | perror("asprintf"); | |
534 | return -1; | |
535 | } | |
b0be0e09 | 536 | char const * const baseadmindir = "/var/lib/dpkg"; |
950733c9 JAK |
537 | char *admindir; |
538 | if (asprintf(&admindir, "%s%s", chrootdir, baseadmindir) == -1) { | |
539 | perror("asprintf"); | |
540 | return -1; | |
541 | } | |
b0be0e09 | 542 | setenv("DPKG_ADMINDIR", admindir, 1); |
0c787570 DK |
543 | return func_execvp(newfile, argv); |
544 | } | |
545 | EOF | |
a66e1837 | 546 | testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl |
0c787570 | 547 | } |
276e51dd | 548 | configcompression() { |
bdc42211 DK |
549 | if [ "$1" = 'ALL' ]; then |
550 | configcompression '.' $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Extension \.\(.*\)$#\1#p') | |
551 | return | |
552 | fi | |
abec2980 | 553 | local CMD='apthelper cat-file -C' |
276e51dd DK |
554 | while [ -n "$1" ]; do |
555 | case "$1" in | |
3c528b91 | 556 | '.') printf ".\t.\tcat\n";; |
abec2980 DK |
557 | 'gz') printf "gzip\tgz\t$CMD $1\n";; |
558 | 'bz2') printf "bzip2\tbz2\t$CMD $1\n";; | |
559 | *) printf "$1\t$1\t$CMD $1\n";; | |
276e51dd DK |
560 | esac |
561 | shift | |
63c71412 | 562 | done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" |
276e51dd | 563 | } |
c5ede4ca DK |
564 | confighashes() { |
565 | { | |
566 | echo 'APT::FTPArchive {' | |
567 | { | |
568 | while [ -n "$1" ]; do | |
569 | printf "$1" | tr 'a-z' 'A-Z' | |
570 | printf "\t\"true\";\n" | |
571 | shift | |
572 | done | |
573 | for h in 'MD5' 'SHA1' 'SHA256' 'SHA512'; do | |
574 | printf "$h\t\"false\";\n" | |
575 | done | |
576 | } | awk '!x[$1]++' | |
577 | echo '};' | |
578 | } >> "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/ftparchive-hashes.conf" | |
579 | } | |
5f982b9d DK |
580 | forcecompressor() { |
581 | COMPRESSOR="$1" | |
912a6131 | 582 | COMPRESS="$1" |
abec2980 | 583 | COMPRESSOR_CMD="apthelper cat-file -C $1" |
5f982b9d DK |
584 | case $COMPRESSOR in |
585 | gzip) COMPRESS='gz';; | |
586 | bzip2) COMPRESS='bz2';; | |
5f982b9d DK |
587 | esac |
588 | local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor" | |
589 | echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; }; | |
912a6131 | 590 | Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE" |
b2fd8524 DK |
591 | for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do |
592 | if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi | |
593 | echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE" | |
594 | echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE" | |
595 | done | |
5f982b9d DK |
596 | } |
597 | ||
b8242321 | 598 | _setupsimplenativepackage() { |
75954ae2 DK |
599 | local NAME="$1" |
600 | local ARCH="$2" | |
601 | local VERSION="$3" | |
602 | local RELEASE="${4:-unstable}" | |
603 | local DEPENDENCIES="$5" | |
14109555 | 604 | local DESCRIPTION="${6:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} |
18908589 DK |
605 | If you find such a package installed on your system, |
606 | something went horribly wrong! They are autogenerated | |
3d284148 | 607 | und used only by testcases and serve no other purpose…"}" |
18908589 | 608 | |
75954ae2 | 609 | local SECTION="${7:-others}" |
d67004e0 | 610 | local PRIORITY="${8:-optional}" |
63c71412 DK |
611 | local FILE_TREE="$9" |
612 | local COMPRESS_TYPE="${10:-gzip}" | |
75954ae2 | 613 | local DISTSECTION |
63c71412 | 614 | if [ "$SECTION" = "${SECTION#*/}" ]; then |
75954ae2 DK |
615 | DISTSECTION="main" |
616 | else | |
63c71412 | 617 | DISTSECTION="${SECTION%/*}" |
75954ae2 | 618 | fi |
63c71412 | 619 | local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}" |
b761356f | 620 | |
63c71412 DK |
621 | mkdir -p "$BUILDDIR/debian/source" |
622 | echo "* most suckless software product ever" > "${BUILDDIR}/FEATURES" | |
b761356f | 623 | echo "#!/bin/sh |
63c71412 | 624 | echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}" |
b761356f | 625 | |
0340069c | 626 | echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright" |
b761356f DK |
627 | echo "$NAME ($VERSION) $RELEASE; urgency=low |
628 | ||
629 | * Initial release | |
630 | ||
0340069c | 631 | -- Joe Sixpack <joe@example.org> $(date -u -R)" > "${BUILDDIR}/debian/changelog" |
63c71412 DK |
632 | { |
633 | echo "Source: $NAME | |
d67004e0 | 634 | Priority: $PRIORITY |
b761356f | 635 | Maintainer: Joe Sixpack <joe@example.org> |
63c71412 DK |
636 | Standards-Version: 3.9.3" |
637 | if [ "$SECTION" != '<none>' ]; then | |
638 | echo "Section: $SECTION" | |
639 | fi | |
640 | local BUILDDEPS="$(echo "$DEPENDENCIES" | grep '^Build-')" | |
641 | test -z "$BUILDDEPS" || echo "$BUILDDEPS" | |
642 | echo " | |
643 | Package: $NAME" | |
b761356f | 644 | |
63c71412 DK |
645 | if [ "$ARCH" = 'all' ]; then |
646 | echo "Architecture: all" | |
647 | else | |
648 | echo "Architecture: any" | |
649 | fi | |
650 | local DEPS="$(echo "$DEPENDENCIES" | grep -v '^Build-')" | |
651 | test -z "$DEPS" || echo "$DEPS" | |
652 | echo "Description: $DESCRIPTION" | |
653 | } > "${BUILDDIR}/debian/control" | |
01f520ce | 654 | |
63c71412 | 655 | echo '3.0 (native)' > "${BUILDDIR}/debian/source/format" |
b8242321 DK |
656 | } |
657 | ||
658 | setupsimplenativepackage() { | |
659 | _setupsimplenativepackage "$@" | |
660 | local NAME="$1" | |
661 | local VERSION="$3" | |
662 | local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}" | |
663 | test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat" | |
664 | test -e "${BUILDDIR}/debian/rules" || cp /usr/share/doc/debhelper/examples/rules.tiny "${BUILDDIR}/debian/rules" | |
665 | } | |
666 | ||
667 | buildsimplenativepackage() { | |
668 | local NAME="$1" | |
669 | local ARCH="$2" | |
670 | local VERSION="$3" | |
671 | local RELEASE="${4:-unstable}" | |
672 | local DEPENDENCIES="$5" | |
673 | local DESCRIPTION="$6" | |
674 | local SECTION="${7:-others}" | |
675 | local PRIORITY="${8:-optional}" | |
676 | local FILE_TREE="$9" | |
677 | local COMPRESS_TYPE="${10:-gzip}" | |
678 | local DISTSECTION | |
679 | if [ "$SECTION" = "${SECTION#*/}" ]; then | |
680 | DISTSECTION="main" | |
681 | else | |
682 | DISTSECTION="${SECTION%/*}" | |
683 | fi | |
684 | local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}" | |
685 | msgtest "Build source package in version ${VERSION} for ${RELEASE} in ${DISTSECTION}" "$NAME" | |
686 | _setupsimplenativepackage "$@" | |
63c71412 | 687 | cd "${BUILDDIR}/.." |
0c787570 DK |
688 | testsuccess --nomsg dpkg-source -b ${NAME}-${VERSION} |
689 | cd - >/dev/null | |
63c71412 | 690 | sed -n 's#^dpkg-source: info: building [^ ]\+ in ##p' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" \ |
f1828b69 | 691 | | while read SRC; do |
63c71412 | 692 | echo "pool/${SRC}" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist" |
f1828b69 | 693 | # if expr match "${SRC}" '.*\.dsc' >/dev/null 2>&1; then |
33a22672 | 694 | # aptkey --keyring ./keys/joesixpack.pub --secret-keyring ./keys/joesixpack.sec --quiet --readonly \ |
bd7fb5aa | 695 | # adv --yes --default-key 'Joe Sixpack' \ |
f1828b69 DK |
696 | # --clearsign -o "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC" |
697 | # mv "${BUILDDIR}/../${SRC}.sign" "${BUILDDIR}/../$SRC" | |
698 | # fi | |
b761356f | 699 | done |
84aa13f4 | 700 | |
3dcdc1f9 | 701 | for arch in $(getarchitecturesfromcommalist "$ARCH"); do |
0c787570 | 702 | msgtest "Build binary package for ${RELEASE} in ${SECTION}" "$NAME" |
63c71412 DK |
703 | rm -rf "${BUILDDIR}/debian/tmp" |
704 | mkdir -p "${BUILDDIR}/debian/tmp/DEBIAN" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin" | |
705 | cp "${BUILDDIR}/debian/copyright" "${BUILDDIR}/debian/changelog" "${BUILDDIR}/FEATURES" "${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}" | |
706 | cp "${BUILDDIR}/${NAME}" "${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch}" | |
42c1513b | 707 | if [ -n "$FILE_TREE" ]; then |
63c71412 | 708 | cp -ar "$FILE_TREE" "${BUILDDIR}/debian/tmp" |
42c1513b | 709 | fi |
42c1513b | 710 | |
63c71412 DK |
711 | (cd "${BUILDDIR}"; dpkg-gencontrol -DArchitecture=$arch) |
712 | (cd "${BUILDDIR}/debian/tmp"; md5sum $(find usr/ -type f) > DEBIAN/md5sums) | |
846856f4 | 713 | local LOG="${BUILDDIR}/../${NAME}_${VERSION}_${arch}.dpkg-deb.log" |
d56e2917 | 714 | # ensure the right permissions as dpkg-deb insists |
63c71412 DK |
715 | chmod 755 "${BUILDDIR}/debian/tmp/DEBIAN" |
716 | testsuccess --nomsg dpkg-deb -Z${COMPRESS_TYPE} --build "${BUILDDIR}/debian/tmp" "${BUILDDIR}/.." | |
717 | echo "pool/${NAME}_${VERSION}_${arch}.deb" >> "${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist" | |
84aa13f4 DK |
718 | done |
719 | ||
b8242321 DK |
720 | local NM |
721 | if [ "$(echo "$NAME" | cut -c 1-3)" = 'lib' ]; then | |
722 | NM="$(echo "$NAME" | cut -c 1-4)" | |
723 | else | |
724 | NM="$(echo "$NAME" | cut -c 1)" | |
725 | fi | |
d56e2917 | 726 | local CHANGEPATH="${BUILDDIR}/../${DISTSECTION}/${NM}/${NAME}/${NAME}_${VERSION}" |
63c71412 DK |
727 | mkdir -p "$CHANGEPATH" |
728 | cp "${BUILDDIR}/debian/changelog" "$CHANGEPATH" | |
5a635ee4 | 729 | rm -rf "${BUILDDIR}" |
b761356f | 730 | msgdone "info" |
75954ae2 DK |
731 | } |
732 | ||
733 | buildpackage() { | |
734 | local BUILDDIR=$1 | |
735 | local RELEASE=$2 | |
736 | local SECTION=$3 | |
ea65d079 | 737 | local ARCH=$(getarchitecture $4) |
846856f4 DK |
738 | local PKGNAME="$(echo "$BUILDDIR" | grep -o '[^/]*$')" |
739 | local BUILDLOG="$(readlink -f "${BUILDDIR}/../${PKGNAME}_${RELEASE}_${SECTION}.dpkg-bp.log")" | |
0c787570 | 740 | msgtest "Build package for ${RELEASE} in ${SECTION}" "$PKGNAME" |
63c71412 | 741 | cd "$BUILDDIR" |
75954ae2 DK |
742 | if [ "$ARCH" = "all" ]; then |
743 | ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" | |
744 | fi | |
0c787570 | 745 | testsuccess --nomsg dpkg-buildpackage -uc -us -a$ARCH |
63c71412 DK |
746 | cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$BUILDLOG" |
747 | local PKGS="$(grep '^dpkg-deb: building package' "$BUILDLOG" | cut -d'/' -f 2 | sed -e "s#'\.##")" | |
748 | local SRCS="$(grep '^dpkg-source: info: building' "$BUILDLOG" | grep -o '[a-z0-9._+~-]*$')" | |
ce9864a8 | 749 | cd - > /dev/null |
b7899b00 | 750 | for PKG in $PKGS; do |
63c71412 | 751 | echo "pool/${PKG}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist" |
b7899b00 DK |
752 | done |
753 | for SRC in $SRCS; do | |
63c71412 | 754 | echo "pool/${SRC}" >> "${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist" |
b7899b00 | 755 | done |
ce9864a8 DK |
756 | } |
757 | ||
758 | buildaptarchive() { | |
ce9864a8 | 759 | if [ -d incoming ]; then |
846856f4 | 760 | buildaptarchivefromincoming "$@" |
ce9864a8 | 761 | else |
846856f4 | 762 | buildaptarchivefromfiles "$@" |
ce9864a8 DK |
763 | fi |
764 | } | |
765 | ||
766 | createaptftparchiveconfig() { | |
63c71412 | 767 | local COMPRESSORS="$(cut -d' ' -f 1 "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" | tr '\n' ' ')" |
016bea82 DK |
768 | local COMPRESSORS="${COMPRESSORS%* }" |
769 | local ARCHS="$(getarchitectures)" | |
c5ede4ca DK |
770 | cat > ftparchive.conf <<EOF |
771 | Dir { | |
772 | ArchiveDir "$(readlink -f .)"; | |
773 | CacheDir "$(readlink -f ..)"; | |
774 | FileListDir "$(readlink -f pool/)"; | |
b7899b00 DK |
775 | }; |
776 | Default { | |
c5ede4ca DK |
777 | Packages::Compress "$COMPRESSORS"; |
778 | Sources::Compress "$COMPRESSORS"; | |
779 | Contents::Compress "$COMPRESSORS"; | |
780 | Translation::Compress "$COMPRESSORS"; | |
18331adf | 781 | LongDescription "false"; |
ce9864a8 DK |
782 | }; |
783 | TreeDefault { | |
784 | Directory "pool/"; | |
785 | SrcDirectory "pool/"; | |
786 | }; | |
c5ede4ca | 787 | EOF |
b7899b00 | 788 | for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do |
63c71412 DK |
789 | cat <<EOF |
790 | tree "dists/$DIST" { | |
1dd20368 | 791 | Architectures "$ARCHS all source"; |
63c71412 DK |
792 | FileList "${DIST}.\$(SECTION).pkglist"; |
793 | SourceFileList "${DIST}.\$(SECTION).srclist"; | |
794 | Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')"; | |
795 | }; | |
796 | EOF | |
797 | done >> ftparchive.conf | |
ce9864a8 DK |
798 | } |
799 | ||
800 | buildaptftparchivedirectorystructure() { | |
b7899b00 DK |
801 | local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')" |
802 | for DIST in $DISTS; do | |
803 | local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)" | |
804 | for SECTION in $SECTIONS; do | |
805 | local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')" | |
806 | for ARCH in $ARCHS; do | |
63c71412 | 807 | mkdir -p "dists/${DIST}/${SECTION}/binary-${ARCH}" |
b7899b00 | 808 | done |
63c71412 DK |
809 | mkdir -p "dists/${DIST}/${SECTION}/source" |
810 | mkdir -p "dists/${DIST}/${SECTION}/i18n" | |
b7899b00 | 811 | done |
ce9864a8 | 812 | done |
ce9864a8 DK |
813 | } |
814 | ||
9b78cda6 | 815 | insertpackage() { |
10e100e5 | 816 | local RELEASES="$1" |
9b78cda6 DK |
817 | local NAME="$2" |
818 | local ARCH="$3" | |
819 | local VERSION="$4" | |
820 | local DEPENDENCIES="$5" | |
d67004e0 | 821 | local PRIORITY="${6:-optional}" |
10e100e5 | 822 | local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/${RELEASES} |
18908589 DK |
823 | If you find such a package installed on your system, |
824 | something went horribly wrong! They are autogenerated | |
3d284148 | 825 | und used only by testcases and serve no other purpose…"}" |
d67004e0 | 826 | local ARCHS="" |
10e100e5 DK |
827 | for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do |
828 | if [ "$RELEASE" = 'installed' ]; then | |
829 | insertinstalledpackage "$2" "$3" "$4" "$5" "$6" "$7" | |
830 | continue | |
d67004e0 | 831 | fi |
10e100e5 | 832 | for arch in $(getarchitecturesfromcommalist "$ARCH"); do |
1dd20368 | 833 | if [ "$arch" = 'none' ]; then |
10e100e5 DK |
834 | ARCHS="$(getarchitectures)" |
835 | else | |
836 | ARCHS="$arch" | |
837 | fi | |
838 | for BUILDARCH in $ARCHS; do | |
839 | local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}" | |
63c71412 DK |
840 | mkdir -p "$PPATH" |
841 | { | |
842 | echo "Package: $NAME | |
d67004e0 | 843 | Priority: $PRIORITY |
9b78cda6 | 844 | Section: other |
2c085486 | 845 | Installed-Size: 42 |
63c71412 DK |
846 | Maintainer: Joe Sixpack <joe@example.org>" |
847 | test "$arch" = 'none' || echo "Architecture: $arch" | |
848 | echo "Version: $VERSION | |
849 | Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" | |
850 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" | |
851 | echo "Description: $(printf '%s' "$DESCRIPTION" | head -n 1)" | |
852 | echo "Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1)" | |
853 | echo | |
854 | } >> "${PPATH}/Packages" | |
10e100e5 | 855 | done |
d67004e0 | 856 | done |
63c71412 DK |
857 | mkdir -p "aptarchive/dists/${RELEASE}/main/source" "aptarchive/dists/${RELEASE}/main/i18n" |
858 | touch "aptarchive/dists/${RELEASE}/main/source/Sources" | |
10e100e5 | 859 | echo "Package: $NAME |
0e0d9919 DK |
860 | Description-md5: $(printf '%s' "$DESCRIPTION" | md5sum | cut -d' ' -f 1) |
861 | Description-en: $DESCRIPTION | |
63c71412 | 862 | " >> "aptarchive/dists/${RELEASE}/main/i18n/Translation-en" |
10e100e5 | 863 | done |
9b78cda6 DK |
864 | } |
865 | ||
234675b7 | 866 | insertsource() { |
07aca07a | 867 | local RELEASES="$1" |
234675b7 DK |
868 | local NAME="$2" |
869 | local ARCH="$3" | |
870 | local VERSION="$4" | |
871 | local DEPENDENCIES="$5" | |
07aca07a | 872 | local BINARY="${6:-$NAME}" |
234675b7 | 873 | local ARCHS="" |
07aca07a DK |
874 | for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do |
875 | local SPATH="aptarchive/dists/${RELEASE}/main/source" | |
876 | mkdir -p $SPATH | |
877 | local FILE="${SPATH}/Sources" | |
878 | local DSCFILE="${NAME}_${VERSION}.dsc" | |
879 | local TARFILE="${NAME}_${VERSION}.tar.gz" | |
880 | echo "Package: $NAME | |
a8275acf | 881 | Binary: $BINARY |
234675b7 DK |
882 | Version: $VERSION |
883 | Maintainer: Joe Sixpack <joe@example.org> | |
884 | Architecture: $ARCH" >> $FILE | |
07aca07a DK |
885 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE" |
886 | echo "Files: | |
63c71412 DK |
887 | $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE" |
888 | $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE" | |
55ae7a51 | 889 | Checksums-Sha256: |
63c71412 DK |
890 | $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE" |
891 | $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE" | |
892 | " >> "$FILE" | |
07aca07a | 893 | done |
234675b7 DK |
894 | } |
895 | ||
dfc2b1be DK |
896 | insertinstalledpackage() { |
897 | local NAME="$1" | |
898 | local ARCH="$2" | |
899 | local VERSION="$3" | |
900 | local DEPENDENCIES="$4" | |
d67004e0 | 901 | local PRIORITY="${5:-optional}" |
d4b4e5ea | 902 | local STATUS="${6:-install ok installed}" |
14109555 | 903 | local DESCRIPTION="${7:-"an autogenerated dummy ${NAME}=${VERSION}/installed |
18908589 DK |
904 | If you find such a package installed on your system, |
905 | something went horribly wrong! They are autogenerated | |
3d284148 | 906 | und used only by testcases and serve no other purpose…"}" |
18908589 | 907 | |
53ea1b56 DK |
908 | local FILE='rootdir/var/lib/dpkg/status' |
909 | local INFO='rootdir/var/lib/dpkg/info' | |
3dcdc1f9 | 910 | for arch in $(getarchitecturesfromcommalist "$ARCH"); do |
d67004e0 | 911 | echo "Package: $NAME |
d4b4e5ea | 912 | Status: $STATUS |
d67004e0 | 913 | Priority: $PRIORITY |
dfc2b1be DK |
914 | Section: other |
915 | Installed-Size: 42 | |
916 | Maintainer: Joe Sixpack <joe@example.org> | |
63c71412 DK |
917 | Version: $VERSION" >> "$FILE" |
918 | test "$arch" = 'none' || echo "Architecture: $arch" >> "$FILE" | |
919 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE" | |
920 | echo "Description: $DESCRIPTION" >> "$FILE" | |
921 | echo >> "$FILE" | |
53ea1b56 | 922 | if [ "$(dpkg-query -W --showformat='${Multi-Arch}')" = 'same' ]; then |
63c71412 | 923 | echo -n > "${INFO}/${NAME}:${arch}.list" |
53ea1b56 | 924 | else |
63c71412 | 925 | echo -n > "${INFO}/${NAME}.list" |
53ea1b56 | 926 | fi |
d67004e0 | 927 | done |
dfc2b1be DK |
928 | } |
929 | ||
930 | ||
ce9864a8 | 931 | buildaptarchivefromincoming() { |
63c71412 | 932 | msginfo "Build APT archive for ${CCMD}${0##*/}${CINFO} based on incoming packages…" |
ce9864a8 DK |
933 | cd aptarchive |
934 | [ -e pool ] || ln -s ../incoming pool | |
935 | [ -e ftparchive.conf ] || createaptftparchiveconfig | |
936 | [ -e dists ] || buildaptftparchivedirectorystructure | |
b7899b00 | 937 | msgninfo "\tGenerate Packages, Sources and Contents files… " |
31be38d2 | 938 | testsuccess aptftparchive generate ftparchive.conf |
ce9864a8 DK |
939 | cd - > /dev/null |
940 | msgdone "info" | |
4dbfe436 | 941 | generatereleasefiles "$@" |
ce9864a8 DK |
942 | } |
943 | ||
944 | buildaptarchivefromfiles() { | |
63c71412 | 945 | msginfo "Build APT archive for ${CCMD}${0##*/}${CINFO} based on prebuild files…" |
8d041b4f DK |
946 | local DIR='aptarchive' |
947 | if [ -d "${DIR}/dists" ]; then DIR="${DIR}/dists"; fi | |
948 | find "$DIR" -name 'Packages' -o -name 'Sources' -o -name 'Translation-*' | while read line; do | |
9b78cda6 | 949 | msgninfo "\t${line} file… " |
276e51dd | 950 | compressfile "$line" "$1" |
8d876415 | 951 | msgdone "info" |
9b78cda6 | 952 | done |
e3c62328 | 953 | generatereleasefiles "$@" |
9b78cda6 DK |
954 | } |
955 | ||
276e51dd | 956 | compressfile() { |
bdc42211 | 957 | while read compressor extension command; do |
276e51dd DK |
958 | if [ "$compressor" = '.' ]; then |
959 | if [ -n "$2" ]; then | |
960 | touch -d "$2" "$1" | |
961 | fi | |
962 | continue | |
963 | fi | |
964 | cat "$1" | $command > "${1}.${extension}" | |
965 | if [ -n "$2" ]; then | |
966 | touch -d "$2" "${1}.${extension}" | |
967 | fi | |
bdc42211 | 968 | done < "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf" |
276e51dd DK |
969 | } |
970 | ||
a3bbbab7 | 971 | # can be overridden by testcases for their pleasure |
bf9e7447 DK |
972 | getcodenamefromsuite() { |
973 | case "$1" in | |
974 | unstable) echo 'sid';; | |
975 | *) echo -n "$1";; | |
976 | esac | |
977 | } | |
a3bbbab7 | 978 | getreleaseversionfromsuite() { true; } |
718f797c | 979 | getlabelfromsuite() { true; } |
d56e2917 | 980 | getoriginfromsuite() { true; } |
1dd20368 | 981 | getarchitecturesfromreleasefile() { echo "all $(getarchitectures)"; } |
a3bbbab7 | 982 | |
c5ede4ca DK |
983 | aptftparchiverelease() { |
984 | aptftparchive -qq release "$@" | sed -e '/0 Release$/ d' # remove the self reference | |
985 | } | |
9b78cda6 | 986 | generatereleasefiles() { |
884a4c0a DK |
987 | # $1 is the Date header and $2 is the ValidUntil header to be set |
988 | # both should be given in notation date/touch can understand | |
1dd20368 DK |
989 | local DATE="$1" |
990 | local VALIDUNTIL="$2" | |
9b78cda6 | 991 | if [ -e aptarchive/dists ]; then |
87d6947d | 992 | msgninfo "\tGenerate Release files for dists… " |
9b78cda6 | 993 | for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do |
1dd20368 | 994 | local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")" |
a3bbbab7 DK |
995 | local SUITE="$(echo "$dir" | cut -d'/' -f 4)" |
996 | local CODENAME="$(getcodenamefromsuite $SUITE)" | |
997 | local VERSION="$(getreleaseversionfromsuite $SUITE)" | |
718f797c | 998 | local LABEL="$(getlabelfromsuite $SUITE)" |
d56e2917 | 999 | local ORIGIN="$(getoriginfromsuite $SUITE)" |
63c71412 | 1000 | aptftparchiverelease "$dir" \ |
884a4c0a DK |
1001 | -o APT::FTPArchive::Release::Suite="${SUITE}" \ |
1002 | -o APT::FTPArchive::Release::Codename="${CODENAME}" \ | |
bc7a59dd DK |
1003 | -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \ |
1004 | -o APT::FTPArchive::Release::Label="${LABEL}" \ | |
1005 | -o APT::FTPArchive::Release::Origin="${ORIGIN}" \ | |
1006 | -o APT::FTPArchive::Release::Version="${VERSION}" \ | |
63c71412 | 1007 | > "$dir/Release" |
a3bbbab7 | 1008 | if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then |
35faae11 | 1009 | sed -i '/^Date: / a\ |
63c71412 | 1010 | NotAutomatic: yes' "$dir/Release" |
35faae11 | 1011 | fi |
9b78cda6 DK |
1012 | done |
1013 | else | |
87d6947d | 1014 | msgninfo "\tGenerate Release files for flat… " |
c5ede4ca | 1015 | aptftparchiverelease ./aptarchive > aptarchive/Release |
8d876415 | 1016 | fi |
1dd20368 | 1017 | if [ -n "$DATE" -a "$DATE" != "now" ]; then |
fe0f7911 | 1018 | for release in $(find ./aptarchive -name 'Release'); do |
0b45b6e5 | 1019 | sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" -R)/" "$release" |
1dd20368 | 1020 | touch -d "$DATE" "$release" |
fe0f7911 | 1021 | done |
8d876415 | 1022 | fi |
1dd20368 | 1023 | if [ -n "$VALIDUNTIL" ]; then |
c5ede4ca | 1024 | sed -i "/^Date: / a\ |
0b45b6e5 | 1025 | Valid-Until: $(date -u -d "$VALIDUNTIL" -R)" $(find ./aptarchive -name 'Release') |
c5ede4ca | 1026 | fi |
b7899b00 | 1027 | msgdone "info" |
8d876415 DK |
1028 | } |
1029 | ||
b7899b00 | 1030 | setupdistsaptarchive() { |
63c71412 | 1031 | local APTARCHIVE="$(readlink -f ./aptarchive | sed 's# #%20#g')" |
b7899b00 DK |
1032 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list |
1033 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list | |
1034 | for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do | |
63c71412 | 1035 | SECTIONS=$(find "./aptarchive/dists/${DISTS}/" -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ') |
b7899b00 | 1036 | msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… " |
63c71412 DK |
1037 | echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list" |
1038 | echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > "rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list" | |
b7899b00 DK |
1039 | msgdone "info" |
1040 | done | |
1041 | } | |
1042 | ||
1043 | setupflataptarchive() { | |
63c71412 DK |
1044 | local APTARCHIVE="$(readlink -f ./aptarchive)" |
1045 | local APTARCHIVEURI="$(readlink -f ./aptarchive | sed 's# #%20#g')" | |
1046 | if [ -f "${APTARCHIVE}/Packages" ]; then | |
8d876415 | 1047 | msgninfo "\tadd deb sources.list line… " |
63c71412 DK |
1048 | echo "deb file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list' |
1049 | msgdone 'info' | |
8d876415 | 1050 | else |
63c71412 | 1051 | rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list' |
8d876415 | 1052 | fi |
63c71412 | 1053 | if [ -f "${APTARCHIVE}/Sources" ]; then |
8d876415 | 1054 | msgninfo "\tadd deb-src sources.list line… " |
63c71412 DK |
1055 | echo "deb-src file://$APTARCHIVEURI /" > 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list' |
1056 | msgdone 'info' | |
8d876415 | 1057 | else |
63c71412 | 1058 | rm -f 'rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list' |
8d876415 | 1059 | fi |
b7899b00 DK |
1060 | } |
1061 | ||
1062 | setupaptarchive() { | |
4dbfe436 DK |
1063 | local NOUPDATE=0 |
1064 | if [ "$1" = '--no-update' ]; then | |
1065 | NOUPDATE=1 | |
1066 | shift | |
1067 | fi | |
1068 | buildaptarchive "$@" | |
b7899b00 DK |
1069 | if [ -e aptarchive/dists ]; then |
1070 | setupdistsaptarchive | |
1071 | else | |
1072 | setupflataptarchive | |
1073 | fi | |
9d653a6d | 1074 | signreleasefiles 'Joe Sixpack' |
4dbfe436 | 1075 | if [ "1" != "$NOUPDATE" ]; then |
5684f71f | 1076 | testsuccess aptget update -o Debug::pkgAcquire::Worker=true -o Debug::Acquire::gpgv=true |
b2ea1a47 | 1077 | fi |
8d876415 DK |
1078 | } |
1079 | ||
f213b6ea | 1080 | signreleasefiles() { |
fb7b11eb | 1081 | local SIGNERS="${1:-Joe Sixpack}" |
07cb47e7 | 1082 | local REPODIR="${2:-aptarchive}" |
1af227c2 DK |
1083 | if [ -n "$1" ]; then shift; fi |
1084 | if [ -n "$1" ]; then shift; fi | |
fb7b11eb DK |
1085 | local KEY="keys/$(echo "$SIGNERS" | tr 'A-Z' 'a-z' | tr -d ' ,')" |
1086 | msgninfo "\tSign archive with $SIGNERS key $KEY… " | |
29a59c46 DK |
1087 | local REXKEY='keys/rexexpired' |
1088 | local SECEXPIREBAK="${REXKEY}.sec.bak" | |
1089 | local PUBEXPIREBAK="${REXKEY}.pub.bak" | |
fb7b11eb DK |
1090 | local SIGUSERS="" |
1091 | while [ -n "${SIGNERS%%,*}" ]; do | |
1092 | local SIGNER="${SIGNERS%%,*}" | |
1093 | if [ "${SIGNERS}" = "${SIGNER}" ]; then | |
1094 | SIGNERS="" | |
1095 | fi | |
1096 | SIGNERS="${SIGNERS#*,}" | |
1097 | # FIXME: This should be the full name, but we can't encode the space properly currently | |
1098 | SIGUSERS="${SIGUSERS} -u ${SIGNER#* }" | |
1099 | if [ "${SIGNER}" = 'Rex Expired' ]; then | |
1100 | # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time | |
1101 | # option doesn't exist anymore (and using faketime would add a new obscure dependency) | |
1102 | # therefore we 'temporary' make the key not expired and restore a backup after signing | |
1103 | cp "${REXKEY}.sec" "$SECEXPIREBAK" | |
1104 | cp "${REXKEY}.pub" "$PUBEXPIREBAK" | |
1105 | local SECUNEXPIRED="${REXKEY}.sec.unexpired" | |
1106 | local PUBUNEXPIRED="${REXKEY}.pub.unexpired" | |
1107 | if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then | |
1108 | cp "$SECUNEXPIRED" "${REXKEY}.sec" | |
1109 | cp "$PUBUNEXPIRED" "${REXKEY}.pub" | |
1110 | else | |
1111 | if ! printf "expire\n1w\nsave\n" | aptkey --quiet --keyring "${REXKEY}.pub" --secret-keyring "${REXKEY}.sec" \ | |
1112 | --readonly adv --batch --yes --digest-algo "${APT_TESTS_DIGEST_ALGO:-SHA512}" \ | |
1113 | --default-key "$SIGNER" --command-fd 0 --edit-key "${SIGNER}" >setexpire.gpg 2>&1; then | |
1114 | cat setexpire.gpg | |
1115 | exit 1 | |
1116 | fi | |
1117 | cp "${REXKEY}.sec" "$SECUNEXPIRED" | |
1118 | cp "${REXKEY}.pub" "$PUBUNEXPIRED" | |
f1e1abd8 | 1119 | fi |
29a59c46 | 1120 | fi |
fb7b11eb DK |
1121 | if [ ! -e "${KEY}.pub" ]; then |
1122 | local K="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | tr -d ' ,')" | |
1123 | cat "${K}.pub" >> "${KEY}.new.pub" | |
1124 | cat "${K}.sec" >> "${KEY}.new.sec" | |
1125 | fi | |
1126 | done | |
1127 | if [ ! -e "${KEY}.pub" ]; then | |
1128 | mv "${KEY}.new.pub" "${KEY}.pub" | |
1129 | mv "${KEY}.new.sec" "${KEY}.sec" | |
29a59c46 | 1130 | fi |
fb7b11eb | 1131 | local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}" |
63c71412 | 1132 | for RELEASE in $(find "${REPODIR}/" -name Release); do |
e3c62328 | 1133 | # we might have set a specific date for the Release file, so copy it |
761a5ad2 DK |
1134 | local DATE="$(stat --format "%y" "${RELEASE}")" |
1135 | if [ "$APT_DONT_SIGN" = 'Release.gpg' ]; then | |
1136 | rm -f "${RELEASE}.gpg" | |
1137 | else | |
1138 | testsuccess $GPG "$@" $SIGUSERS --armor --detach-sign --sign --output "${RELEASE}.gpg" "${RELEASE}" | |
1139 | touch -d "$DATE" "${RELEASE}.gpg" | |
1140 | fi | |
1141 | local INRELEASE="${RELEASE%/*}/InRelease" | |
1142 | if [ "$APT_DONT_SIGN" = 'InRelease' ]; then | |
1143 | rm -f "$INRELEASE" | |
1144 | else | |
1145 | testsuccess $GPG "$@" $SIGUSERS --clearsign --output "$INRELEASE" "$RELEASE" | |
1146 | touch -d "$DATE" "${INRELEASE}" | |
1147 | fi | |
f213b6ea | 1148 | done |
29a59c46 | 1149 | if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then |
63c71412 DK |
1150 | mv -f "$SECEXPIREBAK" "${REXKEY}.sec" |
1151 | mv -f "$PUBEXPIREBAK" "${REXKEY}.pub" | |
29a59c46 | 1152 | fi |
63c71412 | 1153 | msgdone 'info' |
f213b6ea DK |
1154 | } |
1155 | ||
8eafc759 | 1156 | redatereleasefiles() { |
0b45b6e5 | 1157 | local DATE="$(date -u -d "$1" -R)" |
8eafc759 | 1158 | for release in $(find aptarchive/ -name 'Release'); do |
63c71412 DK |
1159 | sed -i "s/^Date: .*$/Date: ${DATE}/" "$release" |
1160 | touch -d "$DATE" "$release" | |
8eafc759 DK |
1161 | done |
1162 | signreleasefiles "${2:-Joe Sixpack}" | |
1163 | } | |
1164 | ||
f2c0ec8b | 1165 | webserverconfig() { |
6c0765c0 | 1166 | local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}" |
b0314abb DK |
1167 | local NOCHECK=false |
1168 | if [ "$1" = '--no-check' ]; then | |
1169 | NOCHECK=true | |
1170 | shift | |
1171 | fi | |
0d58c26a | 1172 | local DOWNLOG='rootdir/tmp/download-testfile.log' |
b0314abb | 1173 | local STATUS='downloaded/webserverconfig.status' |
0d58c26a | 1174 | rm -f "$STATUS" "$DOWNLOG" |
6c0765c0 | 1175 | # very very basic URI encoding |
b0314abb DK |
1176 | local URI |
1177 | if [ -n "$2" ]; then | |
1178 | msgtest "Set webserver config option '${1}' to" "$2" | |
6c0765c0 | 1179 | URI="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')" |
b0314abb DK |
1180 | else |
1181 | msgtest 'Clear webserver config option' "${1}" | |
6c0765c0 | 1182 | URI="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')" |
b0314abb DK |
1183 | fi |
1184 | if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then | |
f2c0ec8b DK |
1185 | msgpass |
1186 | else | |
68042532 DK |
1187 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.output" |
1188 | cat "$DOWNLOG" "$STATUS" >"$OUTPUT" 2>&1 || true | |
1189 | msgfailoutput '' "$OUTPUT" | |
f2c0ec8b | 1190 | fi |
b0314abb | 1191 | $NOCHECK || testwebserverlaststatuscode '200' |
f2c0ec8b DK |
1192 | } |
1193 | ||
fd46d305 | 1194 | rewritesourceslist() { |
63c71412 | 1195 | local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')" |
af9e40c9 | 1196 | local APTARCHIVE2="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')" |
fd46d305 | 1197 | for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do |
af9e40c9 | 1198 | sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \ |
28b2efcb DK |
1199 | -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \ |
1200 | -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#" | |
fd46d305 DK |
1201 | done |
1202 | } | |
1203 | ||
5572f6bd MV |
1204 | # wait for up to 10s for a pid file to appear to avoid possible race |
1205 | # when a helper is started and dosn't write the PID quick enough | |
1206 | waitforpidfile() { | |
1207 | local PIDFILE="$1" | |
1208 | for i in $(seq 10); do | |
1209 | if test -s "$PIDFILE"; then | |
1210 | return 0 | |
1211 | fi | |
1212 | sleep 1 | |
1213 | done | |
1214 | msgdie "waiting for $PIDFILE failed" | |
1215 | return 1 | |
1216 | } | |
1217 | ||
f213b6ea | 1218 | changetowebserver() { |
6c0765c0 | 1219 | local REWRITE='no' |
23af9f40 | 1220 | if [ "$1" != '--no-rewrite' ]; then |
6c0765c0 | 1221 | REWRITE='yes' |
23af9f40 DK |
1222 | else |
1223 | shift | |
1224 | fi | |
63c71412 | 1225 | if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then |
fbd29dd6 | 1226 | cd aptarchive |
a0db467c | 1227 | local LOG="webserver.log" |
6c0765c0 | 1228 | if ! aptwebserver --port 0 -o aptwebserver::fork=1 -o aptwebserver::portfile='aptwebserver.port' "$@" >$LOG 2>&1 ; then |
3abb6a6a | 1229 | cat "$LOG" |
bee0670b DK |
1230 | false |
1231 | fi | |
6c0765c0 | 1232 | waitforpidfile aptwebserver.pid |
e3c62328 DK |
1233 | local PID="$(cat aptwebserver.pid)" |
1234 | if [ -z "$PID" ]; then | |
1235 | msgdie 'Could not fork aptwebserver successfully' | |
1236 | fi | |
1237 | addtrap "kill $PID;" | |
6c0765c0 DK |
1238 | waitforpidfile aptwebserver.port |
1239 | APTHTTPPORT="$(cat aptwebserver.port)" | |
1240 | if [ -z "$APTHTTPPORT" ]; then | |
1241 | msgdie 'Could not get port for aptwebserver successfully' | |
1242 | fi | |
fbd29dd6 | 1243 | cd - > /dev/null |
c5bcc607 | 1244 | else |
3d284148 | 1245 | msgdie 'You have to build apt from source to have test/interactive-helper/aptwebserver available for tests requiring a webserver' |
f213b6ea | 1246 | fi |
6c0765c0 DK |
1247 | if [ "$REWRTE" != 'yes' ]; then |
1248 | rewritesourceslist "http://localhost:${APTHTTPPORT}/" | |
1249 | fi | |
fd46d305 DK |
1250 | } |
1251 | ||
1252 | changetohttpswebserver() { | |
e75e5879 | 1253 | if ! command -v stunnel4 >/dev/null 2>&1; then |
fd46d305 DK |
1254 | msgdie 'You need to install stunnel4 for https testcases' |
1255 | fi | |
1256 | if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then | |
dc95fee1 | 1257 | changetowebserver --no-rewrite "$@" |
fd46d305 DK |
1258 | fi |
1259 | echo "pid = ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid | |
68ba0b7f | 1260 | cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem |
23af9f40 | 1261 | output = /dev/null |
fd46d305 DK |
1262 | |
1263 | [https] | |
6c0765c0 DK |
1264 | accept = 0 |
1265 | connect = $APTHTTPPORT | |
63c71412 | 1266 | " > "${TMPWORKINGDIRECTORY}/stunnel.conf" |
fd46d305 | 1267 | stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf" |
5572f6bd | 1268 | waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid" |
63c71412 | 1269 | local PID="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")" |
5572f6bd MV |
1270 | if [ -z "$PID" ]; then |
1271 | msgdie 'Could not fork stunnel4 successfully' | |
1272 | fi | |
fd46d305 | 1273 | addtrap 'prefix' "kill ${PID};" |
6970f6e6 | 1274 | APTHTTPSPORT="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)" |
6c0765c0 DK |
1275 | webserverconfig 'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}" |
1276 | rewritesourceslist "https://localhost:${APTHTTPSPORT}/" | |
f213b6ea DK |
1277 | } |
1278 | ||
c45233ea DK |
1279 | changetocdrom() { |
1280 | mkdir -p rootdir/media/cdrom/.disk | |
1281 | local CD="$(readlink -f rootdir/media/cdrom)" | |
63c71412 DK |
1282 | cat > rootdir/etc/apt/apt.conf.d/00cdrom <<EOF |
1283 | acquire::cdrom::mount "${CD}"; | |
1284 | acquire::cdrom::"${CD}/"::mount "mv ${CD}-unmounted ${CD}"; | |
1285 | acquire::cdrom::"${CD}/"::umount "mv ${CD} ${CD}-unmounted"; | |
1286 | acquire::cdrom::autodetect 0; | |
1287 | EOF | |
1288 | echo -n "$1" > "${CD}/.disk/info" | |
c45233ea DK |
1289 | if [ ! -d aptarchive/dists ]; then |
1290 | msgdie 'Flat file archive cdroms can not be created currently' | |
1291 | return 1 | |
1292 | fi | |
a0975c8d | 1293 | mv aptarchive/dists "$CD" |
63c71412 | 1294 | ln -s "$(readlink -f ./incoming)" "$CD/pool" |
c45233ea | 1295 | find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete |
a0975c8d DK |
1296 | # start with an unmounted disk |
1297 | mv "${CD}" "${CD}-unmounted" | |
1298 | # we don't want the disk to be modifiable | |
bc8f83a5 | 1299 | addtrap 'prefix' "chmod -f -R +w '$(escape_shell "$PWD/rootdir/media/cdrom/dists/")' '$(escape_shell "$PWD/rootdir/media/cdrom-unmounted/dists/")' || true;" |
b0314abb | 1300 | chmod -R 555 rootdir/media/cdrom-unmounted/dists |
c45233ea DK |
1301 | } |
1302 | ||
fd46d305 | 1303 | downloadfile() { |
ed793a19 | 1304 | local PROTO="${1%%:*}" |
27925d82 | 1305 | if ! apthelper -o Debug::Acquire::${PROTO}=1 -o Debug::pkgAcquire::Worker=1 \ |
dcbb364f | 1306 | download-file "$1" "$2" "$3" 2>&1 ; then |
27925d82 DK |
1307 | return 1 |
1308 | fi | |
fd46d305 | 1309 | # only if the file exists the download was successful |
b0314abb | 1310 | if [ -r "$2" ]; then |
fd46d305 DK |
1311 | return 0 |
1312 | else | |
1313 | return 1 | |
1314 | fi | |
1315 | } | |
1316 | ||
f213b6ea | 1317 | checkdiff() { |
03aa0847 | 1318 | local DIFFTEXT="$(command diff -u "$@" 2>&1 | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" |
8d876415 | 1319 | if [ -n "$DIFFTEXT" ]; then |
0d58c26a DK |
1320 | echo >&2 |
1321 | echo >&2 "$DIFFTEXT" | |
8d876415 DK |
1322 | return 1 |
1323 | else | |
1324 | return 0 | |
1325 | fi | |
1326 | } | |
1327 | ||
22ac12b2 DK |
1328 | testoutputequal() { |
1329 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output" | |
1330 | local COMPAREFILE="$1" | |
1331 | shift | |
63c71412 | 1332 | if "$@" 2>&1 | checkdiff "$COMPAREFILE" - >"$OUTPUT" 2>&1; then |
22ac12b2 DK |
1333 | msgpass |
1334 | else | |
1335 | echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}" | |
1336 | cat "$COMPAREFILE" >>"${OUTPUT}" | |
1337 | msgfailoutput '' "$OUTPUT" "$@" | |
1338 | fi | |
1339 | } | |
1340 | ||
75954ae2 | 1341 | testfileequal() { |
1501a2c9 | 1342 | msggroup 'testfileequal' |
e6a12ff7 DK |
1343 | local MSG='Test for correctness of file' |
1344 | if [ "$1" = '--nomsg' ]; then | |
1345 | MSG='' | |
1346 | shift | |
1347 | fi | |
75954ae2 DK |
1348 | local FILE="$1" |
1349 | shift | |
e6a12ff7 DK |
1350 | if [ -n "$MSG" ]; then |
1351 | msgtest "$MSG" "$FILE" | |
1352 | fi | |
68042532 | 1353 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output" |
75954ae2 | 1354 | if [ -z "$*" ]; then |
22ac12b2 | 1355 | testoutputequal "$FILE" echo -n '' |
75954ae2 | 1356 | else |
22ac12b2 | 1357 | testoutputequal "$FILE" echo "$*" |
75954ae2 | 1358 | fi |
9beb11aa | 1359 | msggroup |
75954ae2 DK |
1360 | } |
1361 | ||
b855a400 | 1362 | testempty() { |
1501a2c9 | 1363 | msggroup 'testempty' |
a66e1837 DK |
1364 | if [ "$1" = '--nomsg' ]; then |
1365 | shift | |
1366 | else | |
1367 | msgtest "Test for no output of" "$*" | |
1368 | fi | |
859093da | 1369 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile" |
a66e1837 | 1370 | if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then |
859093da DK |
1371 | msgpass |
1372 | else | |
22ac12b2 | 1373 | msgfailoutput '' "$COMPAREFILE" "$@" |
859093da | 1374 | fi |
ab25bf1f | 1375 | aptautotest 'testempty' "$@" |
9beb11aa | 1376 | msggroup |
b855a400 | 1377 | } |
63c71412 DK |
1378 | testnotempty() { |
1379 | msggroup 'testnotempty' | |
1380 | msgtest "Test for some output of" "$*" | |
1381 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnotempty.comparefile" | |
1382 | if ("$@" >"$COMPAREFILE" 2>&1 || true) && test -s "$COMPAREFILE"; then | |
1383 | msgpass | |
1384 | else | |
1385 | msgfailoutput '' "$COMPAREFILE" "$@" | |
1386 | fi | |
1387 | aptautotest 'testnotempty' "$@" | |
1388 | msggroup | |
1389 | } | |
b855a400 | 1390 | |
f74a6fa1 | 1391 | testequal() { |
1501a2c9 | 1392 | msggroup 'testequal' |
f74a6fa1 DK |
1393 | local MSG='Test of equality of' |
1394 | if [ "$1" = '--nomsg' ]; then | |
1395 | MSG='' | |
1396 | shift | |
1397 | fi | |
1398 | ||
03938280 | 1399 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.comparefile" |
63c71412 | 1400 | echo "$1" > "$COMPAREFILE" |
8d876415 | 1401 | shift |
d2d68aaf | 1402 | |
f74a6fa1 DK |
1403 | if [ -n "$MSG" ]; then |
1404 | msgtest "$MSG" "$*" | |
1405 | fi | |
22ac12b2 | 1406 | testoutputequal "$COMPAREFILE" "$@" |
ab25bf1f | 1407 | aptautotest 'testequal' "$@" |
9beb11aa | 1408 | msggroup |
8d876415 DK |
1409 | } |
1410 | ||
685625bd | 1411 | testequalor2() { |
1501a2c9 | 1412 | msggroup 'testequalor2' |
03938280 DK |
1413 | local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1" |
1414 | local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2" | |
1415 | local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst" | |
63c71412 DK |
1416 | echo "$1" > "$COMPAREFILE1" |
1417 | echo "$2" > "$COMPAREFILE2" | |
685625bd DK |
1418 | shift 2 |
1419 | msgtest "Test for equality OR of" "$*" | |
63c71412 DK |
1420 | "$@" >"$COMPAREAGAINST" 2>&1 || true |
1421 | if checkdiff "$COMPAREFILE1" "$COMPAREAGAINST" >/dev/null 2>&1 || \ | |
1422 | checkdiff "$COMPAREFILE2" "$COMPAREAGAINST" >/dev/null 2>&1 | |
0d58c26a | 1423 | then |
0caa5a4c DK |
1424 | msgpass |
1425 | else | |
68042532 DK |
1426 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output" |
1427 | echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" >"$OUTPUT" 2>&1 | |
1428 | checkdiff "$COMPAREFILE1" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true | |
1429 | echo -n "${CINFO}Diff against OR 2${CNORMAL}" >"$OUTPUT" 2>&1 | |
1430 | checkdiff "$COMPAREFILE2" "$COMPAREAGAINST" >"$OUTPUT" 2>&1 || true | |
1431 | msgfailoutput '' "$OUTPUT" | |
0caa5a4c | 1432 | fi |
ab25bf1f | 1433 | aptautotest 'testequalor2' "$@" |
9beb11aa | 1434 | msggroup |
685625bd DK |
1435 | } |
1436 | ||
8d876415 | 1437 | testshowvirtual() { |
1501a2c9 | 1438 | msggroup 'testshowvirtual' |
edc0ef10 | 1439 | local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
1440 | local PACKAGE="$1" |
1441 | shift | |
1442 | while [ -n "$1" ]; do | |
1443 | VIRTUAL="${VIRTUAL} | |
edc0ef10 | 1444 | N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
1445 | PACKAGE="${PACKAGE} $1" |
1446 | shift | |
1447 | done | |
1448 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
1449 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 1450 | N: No packages found" |
03938280 | 1451 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.comparefile" |
ea65d079 | 1452 | local ARCH="$(getarchitecture 'native')" |
68042532 DK |
1453 | echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE" |
1454 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output" | |
87d6947d | 1455 | testoutputequal "$COMPAREFILE" aptcache show "$PACKAGE" |
9beb11aa | 1456 | msggroup |
8d876415 DK |
1457 | } |
1458 | ||
1459 | testnopackage() { | |
1501a2c9 | 1460 | msggroup 'testnopackage' |
8d876415 | 1461 | msgtest "Test for non-existent packages" "apt-cache show $*" |
846856f4 | 1462 | local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')" |
8d876415 | 1463 | if [ -n "$SHOWPKG" ]; then |
68042532 DK |
1464 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" |
1465 | echo "$SHOWPKG" >"$OUTPUT" | |
1466 | msgfailoutput '' "$OUTPUT" | |
0d58c26a DK |
1467 | else |
1468 | msgpass | |
8d876415 | 1469 | fi |
9beb11aa | 1470 | msggroup |
8d876415 | 1471 | } |
bd4a8f51 DK |
1472 | testnosrcpackage() { |
1473 | msggroup 'testnosrcpackage' | |
1474 | msgtest "Test for non-existent source packages" "apt-cache showsrc $*" | |
1475 | local SHOWPKG="$(aptcache showsrc "$@" 2>&1 | grep '^Package: ')" | |
1476 | if [ -n "$SHOWPKG" ]; then | |
1477 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnosrcpackage.output" | |
1478 | echo "$SHOWPKG" >"$OUTPUT" | |
1479 | msgfailoutput '' "$OUTPUT" | |
1480 | else | |
1481 | msgpass | |
1482 | fi | |
1483 | msggroup | |
1484 | } | |
01a6e24c | 1485 | |
ecb777dd | 1486 | testdpkgstatus() { |
1501a2c9 | 1487 | msggroup 'testdpkgstatus' |
ecb777dd DK |
1488 | local STATE="$1" |
1489 | local NR="$2" | |
1490 | shift 2 | |
1491 | msgtest "Test that $NR package(s) are in state $STATE with" "dpkg -l $*" | |
1492 | local PKGS="$(dpkg -l "$@" 2>/dev/null | grep "^${STATE}" | wc -l)" | |
1493 | if [ "$PKGS" != $NR ]; then | |
68042532 DK |
1494 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testnopackage.output" |
1495 | echo "$PKGS" >"$OUTPUT" | |
1496 | dpkg -l "$@" | grep '^[a-z]' >"$OUTPUT" >&2 || true | |
1497 | msgfailoutput '' "$OUTPUT" | |
0d58c26a DK |
1498 | else |
1499 | msgpass | |
01a6e24c | 1500 | fi |
9beb11aa | 1501 | msggroup |
01a6e24c DK |
1502 | } |
1503 | ||
ecb777dd | 1504 | testdpkginstalled() { |
1501a2c9 | 1505 | msggroup 'testdpkginstalled' |
ecb777dd | 1506 | testdpkgstatus 'ii' "$#" "$@" |
9beb11aa | 1507 | msggroup |
ecb777dd DK |
1508 | } |
1509 | ||
5cf733e1 | 1510 | testdpkgnotinstalled() { |
1501a2c9 | 1511 | msggroup 'testdpkgnotinstalled' |
ecb777dd | 1512 | testdpkgstatus 'ii' '0' "$@" |
9beb11aa | 1513 | msggroup |
01a6e24c | 1514 | } |
ec7f904e DK |
1515 | |
1516 | testmarkedauto() { | |
1501a2c9 | 1517 | msggroup 'testmarkedauto' |
03938280 | 1518 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile" |
ec7f904e DK |
1519 | if [ -n "$1" ]; then |
1520 | msgtest 'Test for correctly marked as auto-installed' "$*" | |
63c71412 | 1521 | while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE" |
ec7f904e DK |
1522 | else |
1523 | msgtest 'Test for correctly marked as auto-installed' 'no package' | |
63c71412 | 1524 | echo -n > "$COMPAREFILE" |
ec7f904e | 1525 | fi |
22ac12b2 | 1526 | testoutputequal "$COMPAREFILE" aptmark showauto |
9beb11aa | 1527 | msggroup |
ec7f904e | 1528 | } |
7c2cc4a7 | 1529 | testmarkedmanual() { |
1501a2c9 | 1530 | msggroup 'testmarkedmanual' |
7c2cc4a7 DK |
1531 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile" |
1532 | if [ -n "$1" ]; then | |
1533 | msgtest 'Test for correctly marked as manually installed' "$*" | |
63c71412 | 1534 | while [ -n "$1" ]; do echo "$1"; shift; done | sort > "$COMPAREFILE" |
7c2cc4a7 DK |
1535 | else |
1536 | msgtest 'Test for correctly marked as manually installed' 'no package' | |
63c71412 | 1537 | echo -n > "$COMPAREFILE" |
7c2cc4a7 | 1538 | fi |
22ac12b2 | 1539 | testoutputequal "$COMPAREFILE" aptmark showmanual |
9beb11aa | 1540 | msggroup |
7c2cc4a7 | 1541 | } |
89a1aa5d | 1542 | |
742f67ea DK |
1543 | catfile() { |
1544 | if [ "${1##*.}" = 'deb' ]; then | |
1545 | stat >&2 "$1" || true | |
1546 | file >&2 "$1" || true | |
1547 | else | |
1548 | cat >&2 "$1" || true | |
1549 | fi | |
1550 | } | |
e52aad52 | 1551 | msgfailoutput() { |
1501a2c9 | 1552 | msgreportheader 'msgfailoutput' |
e52aad52 DK |
1553 | local MSG="$1" |
1554 | local OUTPUT="$2" | |
1555 | shift 2 | |
b4f91d4d DK |
1556 | local CMD="$1" |
1557 | if [ "$1" = 'grep' -o "$1" = 'tail' -o "$1" = 'head' ]; then | |
68042532 | 1558 | echo >&2 |
e52aad52 DK |
1559 | while [ -n "$2" ]; do shift; done |
1560 | echo "#### Complete file: $1 ####" | |
742f67ea | 1561 | catfile "$1" |
b4f91d4d | 1562 | echo "#### $CMD output ####" |
e52aad52 | 1563 | elif [ "$1" = 'test' ]; then |
68042532 | 1564 | echo >&2 |
e52aad52 DK |
1565 | # doesn't support ! or non-file flags |
1566 | msgfailoutputstatfile() { | |
1567 | local FILEFLAGS='^-[bcdefgGhkLOprsStuwx]$' | |
1568 | if expr match "$1" "$FILEFLAGS" >/dev/null; then | |
1569 | echo "#### stat(2) of file: $2 ####" | |
1570 | stat "$2" || true | |
dffc17ba DK |
1571 | if test -d "$2"; then |
1572 | echo "#### The directory contains: $2 ####" | |
1573 | ls >&2 "$2" || true | |
1574 | elif test -e "$2"; then | |
3196dae8 | 1575 | echo "#### Complete file: $2 ####" |
742f67ea | 1576 | catfile "$2" |
3196dae8 | 1577 | fi |
e52aad52 DK |
1578 | fi |
1579 | } | |
1580 | msgfailoutputstatfile "$2" "$3" | |
1581 | while [ -n "$5" ] && [ "$4" = '-o' -o "$4" = '-a' ]; do | |
1582 | shift 3 | |
1583 | msgfailoutputstatfile "$2" "$3" | |
1584 | done | |
1585 | echo '#### test output ####' | |
6fc2e030 DK |
1586 | elif [ "$1" = 'cmp' ]; then |
1587 | echo >&2 | |
1588 | while [ -n "$2" ]; do | |
1589 | echo "#### Complete file: $2 ####" | |
742f67ea | 1590 | catfile "$2" |
6fc2e030 DK |
1591 | shift |
1592 | done | |
1593 | echo '#### cmp output ####' | |
e52aad52 | 1594 | fi |
742f67ea | 1595 | catfile "$OUTPUT" |
e52aad52 DK |
1596 | msgfail "$MSG" |
1597 | } | |
1598 | ||
671a55ba DK |
1599 | testsuccesswithglobalerror() { |
1600 | local TYPE="$1" | |
1601 | local ERRORS="$2" | |
1602 | shift 2 | |
1603 | msggroup "$TYPE" | |
0440d936 DK |
1604 | if [ "$1" = '--nomsg' ]; then |
1605 | shift | |
1606 | else | |
1607 | msgtest 'Test for successful execution of' "$*" | |
1608 | fi | |
671a55ba | 1609 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output" |
63c71412 | 1610 | if "$@" >"${OUTPUT}" 2>&1; then |
4fa34122 | 1611 | if expr match "$1" '^apt.*' >/dev/null; then |
e52aad52 DK |
1612 | if grep -q -E ' runtime error: ' "$OUTPUT"; then |
1613 | msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@" | |
671a55ba | 1614 | elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then |
3261271e DK |
1615 | if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then |
1616 | if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \ | |
1617 | | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then | |
1618 | msgpass | |
1619 | else | |
1620 | msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@" | |
1621 | fi | |
1622 | else | |
1623 | msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@" | |
1624 | fi | |
671a55ba DK |
1625 | elif [ "$TYPE" = 'testsuccesswithnotice' ]; then |
1626 | if grep -q -E "^N: " "$OUTPUT"; then | |
1627 | msgpass | |
1628 | else | |
1629 | msgfailoutput 'successful run, but output had no notices' "$OUTPUT" "$@" | |
1630 | fi | |
4fa34122 DK |
1631 | else |
1632 | msgpass | |
1633 | fi | |
1634 | else | |
1635 | msgpass | |
1636 | fi | |
1637 | else | |
1638 | local EXITCODE=$? | |
e52aad52 | 1639 | msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@" |
4fa34122 | 1640 | fi |
671a55ba | 1641 | aptautotest "$TYPE" "$@" |
9beb11aa | 1642 | msggroup |
4fa34122 | 1643 | } |
671a55ba DK |
1644 | testsuccesswithnotice() { |
1645 | testsuccesswithglobalerror 'testsuccesswithnotice' 'WE' "$@" | |
1646 | } | |
1647 | testsuccess() { | |
1648 | testsuccesswithglobalerror 'testsuccess' 'NWE' "$@" | |
1649 | } | |
4fa34122 | 1650 | testwarning() { |
1501a2c9 | 1651 | msggroup 'testwarning' |
4fa34122 DK |
1652 | if [ "$1" = '--nomsg' ]; then |
1653 | shift | |
1654 | else | |
1655 | msgtest 'Test for successful execution with warnings of' "$*" | |
1656 | fi | |
25b86db1 | 1657 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" |
63c71412 | 1658 | if "$@" >"${OUTPUT}" 2>&1; then |
1df24acf | 1659 | if expr match "$1" '^apt.*' >/dev/null; then |
e52aad52 DK |
1660 | if grep -q -E ' runtime error: ' "$OUTPUT"; then |
1661 | msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@" | |
1662 | elif grep -q -E '^E: ' "$OUTPUT"; then | |
1663 | msgfailoutput 'successful run, but output contains errors' "$OUTPUT" "$@" | |
4fa34122 | 1664 | elif ! grep -q -E '^W: ' "$OUTPUT"; then |
e52aad52 | 1665 | msgfailoutput 'successful run, but output contains no warnings' "$OUTPUT" "$@" |
1df24acf DK |
1666 | else |
1667 | msgpass | |
1668 | fi | |
1669 | else | |
1670 | msgpass | |
1671 | fi | |
0440d936 | 1672 | else |
07cb47e7 | 1673 | local EXITCODE=$? |
68042532 | 1674 | msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@" |
0440d936 | 1675 | fi |
4fa34122 | 1676 | aptautotest 'testwarning' "$@" |
9beb11aa | 1677 | msggroup |
0440d936 | 1678 | } |
0440d936 | 1679 | testfailure() { |
1501a2c9 | 1680 | msggroup 'testfailure' |
0440d936 DK |
1681 | if [ "$1" = '--nomsg' ]; then |
1682 | shift | |
1683 | else | |
889b0072 | 1684 | msgtest 'Test for failure in execution of' "$*" |
0440d936 | 1685 | fi |
03938280 | 1686 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" |
63c71412 | 1687 | if "$@" >"${OUTPUT}" 2>&1; then |
07cb47e7 | 1688 | local EXITCODE=$? |
e52aad52 | 1689 | msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@" |
0440d936 | 1690 | else |
1df24acf DK |
1691 | local EXITCODE=$? |
1692 | if expr match "$1" '^apt.*' >/dev/null; then | |
b0d40854 | 1693 | if [ "$1" = 'aptkey' ]; then |
2fac0dd5 DK |
1694 | if grep -q " Can't check signature: |
1695 | BAD signature from | |
1696 | signature could not be verified" "$OUTPUT"; then | |
b0d40854 DK |
1697 | msgpass |
1698 | else | |
1699 | msgfailoutput "run failed with exitcode ${EXITCODE}, but no signature error" "$OUTPUT" "$@" | |
1700 | fi | |
1df24acf | 1701 | else |
b0d40854 DK |
1702 | if grep -q -E ' runtime error: ' "$OUTPUT"; then |
1703 | msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@" | |
1704 | elif grep -q -E '==ERROR' "$OUTPUT"; then | |
1705 | msgfailoutput 'compiler sanitizers reported errors' "$OUTPUT" "$@" | |
1706 | elif ! grep -q -E '^E: ' "$OUTPUT"; then | |
1707 | msgfailoutput "run failed with exitcode ${EXITCODE}, but with no errors" "$OUTPUT" "$@" | |
1708 | else | |
1709 | msgpass | |
1710 | fi | |
1df24acf DK |
1711 | fi |
1712 | else | |
1713 | msgpass | |
1714 | fi | |
0440d936 | 1715 | fi |
ab25bf1f | 1716 | aptautotest 'testfailure' "$@" |
9beb11aa | 1717 | msggroup |
0440d936 DK |
1718 | } |
1719 | ||
7414af7f DK |
1720 | testreturnstateequal() { |
1721 | local STATE="$1" | |
671a55ba DK |
1722 | if [ "$STATE" = 'testsuccesswithglobalerror' ]; then |
1723 | local STATE="$2" | |
1724 | local TYPE="$3" | |
7414af7f | 1725 | shift 3 |
671a55ba DK |
1726 | msggroup "${STATE}equal" |
1727 | if [ "$1" != '--nomsg' ]; then | |
1728 | local CMP="$1" | |
1729 | shift | |
1730 | testsuccesswithglobalerror "$STATE" "$TYPE" "$@" | |
1731 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1732 | else | |
1733 | local CMP="$2" | |
1734 | shift 2 | |
1735 | testsuccesswithglobalerror "$STATE" "$TYPE" "$@" | |
1736 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1737 | fi | |
1738 | else | |
1739 | msggroup "${STATE}equal" | |
1740 | if [ "$2" != '--nomsg' ]; then | |
1741 | local CMP="$2" | |
1742 | shift 2 | |
1743 | "$STATE" "$@" | |
1744 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1745 | else | |
1746 | local CMP="$3" | |
1747 | shift 3 | |
1748 | "$STATE" --nomsg "$@" | |
1749 | testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP" | |
1750 | fi | |
7414af7f | 1751 | fi |
9beb11aa | 1752 | msggroup |
25b86db1 | 1753 | } |
7414af7f | 1754 | testsuccessequal() { |
671a55ba DK |
1755 | # we compare output, so we know perfectly well about N: |
1756 | testreturnstateequal 'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@" | |
7414af7f | 1757 | } |
25b86db1 | 1758 | testwarningequal() { |
7414af7f | 1759 | testreturnstateequal 'testwarning' "$@" |
25b86db1 DK |
1760 | } |
1761 | testfailureequal() { | |
7414af7f | 1762 | testreturnstateequal 'testfailure' "$@" |
25b86db1 DK |
1763 | } |
1764 | ||
27925d82 | 1765 | testfailuremsg() { |
1501a2c9 | 1766 | msggroup 'testfailuremsg' |
27925d82 DK |
1767 | local CMP="$1" |
1768 | shift | |
1769 | testfailure "$@" | |
1770 | msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings' | |
68042532 | 1771 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile" |
002b1bc4 | 1772 | grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true |
22ac12b2 | 1773 | testoutputequal "$COMPAREFILE" echo "$CMP" |
9beb11aa | 1774 | msggroup |
27925d82 | 1775 | } |
f18f2338 DK |
1776 | testwarningmsg() { |
1777 | msggroup 'testwarningmsg' | |
1778 | local CMP="$1" | |
1779 | shift | |
1780 | testwarning "$@" | |
1781 | msgtest 'Check that the output of the previous warned command has expected' 'warnings' | |
1782 | local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile" | |
002b1bc4 | 1783 | grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true |
f18f2338 DK |
1784 | testoutputequal "$COMPAREFILE" echo "$CMP" |
1785 | msggroup | |
1786 | } | |
25b86db1 | 1787 | |
de81b2e2 | 1788 | testfilestats() { |
1501a2c9 | 1789 | msggroup 'testfilestats' |
de81b2e2 DK |
1790 | msgtest "Test that file $1 has $2 $3" "$4" |
1791 | if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then | |
5684f71f DK |
1792 | msgpass |
1793 | else | |
68042532 DK |
1794 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfilestats.output" |
1795 | { | |
1796 | ls -ld "$1" || true | |
1797 | echo -n "stat(1) reports for $2: " | |
1798 | stat --format "$2" "$1" || true | |
1799 | } >"$OUTPUT" 2>&1 | |
1800 | msgfailoutput '' "$OUTPUT" | |
5684f71f | 1801 | fi |
9beb11aa | 1802 | msggroup |
5684f71f | 1803 | } |
de81b2e2 | 1804 | testaccessrights() { |
1501a2c9 | 1805 | msggroup 'testaccessrights' |
de81b2e2 | 1806 | testfilestats "$1" '%a' '=' "$2" |
9beb11aa | 1807 | msggroup |
de81b2e2 | 1808 | } |
5684f71f | 1809 | |
0d58c26a | 1810 | testwebserverlaststatuscode() { |
1501a2c9 | 1811 | msggroup 'testwebserverlaststatuscode' |
0d58c26a | 1812 | local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log' |
03aa0847 | 1813 | local STATUS='downloaded/webserverstatus-statusfile.log' |
0d58c26a DK |
1814 | rm -f "$DOWNLOG" "$STATUS" |
1815 | msgtest 'Test last status code from the webserver was' "$1" | |
6c0765c0 | 1816 | if downloadfile "http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then |
0d58c26a DK |
1817 | msgpass |
1818 | else | |
68042532 DK |
1819 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output" |
1820 | { | |
1821 | if [ -n "$2" ]; then | |
1822 | shift | |
1823 | echo >&2 '#### Additionally provided output files contain:' | |
1824 | cat >&2 "$@" | |
1825 | fi | |
1826 | echo >&2 '#### Download log of the status code:' | |
1827 | cat >&2 "$DOWNLOG" | |
1828 | } >"$OUTPUT" 2>&1 | |
1829 | msgfailoutput "Status was $(cat "$STATUS")" "$OUTPUT" | |
0d58c26a | 1830 | fi |
9beb11aa | 1831 | msggroup |
0d58c26a DK |
1832 | } |
1833 | ||
785cb6fc DK |
1834 | createlistofkeys() { |
1835 | local OUTPUT="$1" | |
1836 | shift | |
1837 | while [ -n "$1" ]; do | |
eb5113c4 JAK |
1838 | # gpg 2.1.something starts printing [SC] at some point |
1839 | if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then | |
1840 | case "$1" in | |
1841 | *Joe*|*Sixpack*) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';; | |
1842 | *Rex*|*Expired*) echo 'pub rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';; | |
1843 | *Marvin*|*Paranoid*) echo 'pub rsa2048/528144E2 2011-01-16 [SC]';; | |
1844 | oldarchive) echo 'pub rsa1024/F68C85A3 2013-12-19 [SC]';; | |
1845 | newarchive) echo 'pub rsa2048/DBAC8DAE 2010-08-18 [SC]';; | |
1846 | *) echo 'UNKNOWN KEY';; | |
1847 | esac | |
785cb6fc | 1848 | # gpg 2.1 has a slightly different output format |
eb5113c4 | 1849 | elif grep -q ' rsa2048/' "$OUTPUT"; then |
785cb6fc DK |
1850 | case "$1" in |
1851 | *Joe*|*Sixpack*) echo 'pub rsa2048/DBAC8DAE 2010-08-18';; | |
1852 | *Rex*|*Expired*) echo 'pub rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';; | |
1853 | *Marvin*|*Paranoid*) echo 'pub rsa2048/528144E2 2011-01-16';; | |
1854 | oldarchive) echo 'pub rsa1024/F68C85A3 2013-12-19';; | |
1855 | newarchive) echo 'pub rsa2048/DBAC8DAE 2010-08-18';; | |
1856 | *) echo 'UNKNOWN KEY';; | |
1857 | esac | |
1858 | else | |
1859 | case "$1" in | |
1860 | *Joe*|*Sixpack*) echo 'pub 2048R/DBAC8DAE 2010-08-18';; | |
1861 | *Rex*|*Expired*) echo 'pub 2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';; | |
1862 | *Marvin*|*Paranoid*) echo 'pub 2048R/528144E2 2011-01-16';; | |
1863 | oldarchive) echo 'pub 1024R/F68C85A3 2013-12-19';; | |
1864 | newarchive) echo 'pub 2048R/DBAC8DAE 2010-08-18';; | |
1865 | *) echo 'UNKNOWN KEY';; | |
1866 | esac | |
1867 | fi | |
1868 | shift | |
1869 | done | |
1870 | } | |
1871 | testaptkeys() { | |
1872 | local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output" | |
1873 | if ! aptkey list | grep '^pub' > "$OUTPUT"; then | |
1874 | echo -n > "$OUTPUT" | |
1875 | fi | |
1876 | testfileequal "$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")" | |
1877 | } | |
1878 | ||
89a1aa5d DK |
1879 | pause() { |
1880 | echo "STOPPED execution. Press enter to continue" | |
1881 | local IGNORE | |
1882 | read IGNORE | |
1883 | } | |
ab25bf1f | 1884 | |
846bc058 | 1885 | listcurrentlistsdirectory() { |
ba6b79bd DK |
1886 | { |
1887 | find rootdir/var/lib/apt/lists -maxdepth 1 -type d | while read line; do | |
1888 | stat --format '%U:%G:%a:%n' "$line" | |
1889 | done | |
1890 | find rootdir/var/lib/apt/lists -maxdepth 1 \! -type d | while read line; do | |
1891 | stat --format '%U:%G:%a:%s:%y:%n' "$line" | |
1892 | done | |
1893 | } | sort | |
846bc058 | 1894 | } |
912a6131 | 1895 | forallsupportedcompressors() { |
b2fd8524 | 1896 | rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor" |
912a6131 | 1897 | for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do |
0179cfa8 | 1898 | if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi |
912a6131 DK |
1899 | "$@" "$COMP" |
1900 | done | |
1901 | } | |
846bc058 | 1902 | |
3a8776a3 | 1903 | ### convenience hacks ### |
8fe964f1 DK |
1904 | mkdir() { |
1905 | # creating some directories by hand is a tedious task, so make it look simple | |
6aef1942 DK |
1906 | local PARAMS="$*" |
1907 | if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then | |
8fe964f1 DK |
1908 | # only the last directory created by mkdir is effected by the -m ! |
1909 | command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" | |
1910 | command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" | |
1911 | command mkdir -m 700 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" | |
1912 | touch "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/lock" | |
1913 | if [ "$(id -u)" = '0' ]; then | |
1914 | chown _apt:root "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" | |
1915 | fi | |
1916 | else | |
1917 | command mkdir "$@" | |
1918 | fi | |
1919 | } | |
1920 | ||
ab25bf1f DK |
1921 | ### The following tests are run by most test methods automatically to check |
1922 | ### general things about commands executed without writing the test every time. | |
1923 | ||
1924 | aptautotest() { | |
1925 | local TESTCALL="$1" | |
1926 | local CMD="$2" | |
1927 | local FIRSTOPT="$3" | |
896f0ae8 | 1928 | local AUTOTEST="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')" |
ab25bf1f DK |
1929 | if command -v $AUTOTEST >/dev/null; then |
1930 | shift 3 | |
1931 | # save and restore the *.output files from other tests | |
1932 | # as we might otherwise override them in these automatic tests | |
63c71412 DK |
1933 | rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" |
1934 | mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" | |
1935 | mkdir "${TMPWORKINGDIRECTORY}/rootdir/tmp" | |
ab25bf1f | 1936 | $AUTOTEST "$TESTCALL" "$@" |
63c71412 DK |
1937 | rm -rf "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest" |
1938 | mv "${TMPWORKINGDIRECTORY}/rootdir/tmp" "${TMPWORKINGDIRECTORY}/rootdir/tmp-aptautotest" | |
1939 | mv "${TMPWORKINGDIRECTORY}/rootdir/tmp-before" "${TMPWORKINGDIRECTORY}/rootdir/tmp" | |
ab25bf1f DK |
1940 | fi |
1941 | } | |
1942 | ||
1943 | aptautotest_aptget_update() { | |
59148d96 DK |
1944 | local TESTCALL="$1" |
1945 | while [ -n "$2" ]; do | |
1946 | if [ "$2" = '--print-uris' ]; then return; fi # simulation mode | |
1947 | shift | |
1948 | done | |
ab25bf1f | 1949 | if ! test -d "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"; then return; fi |
4bb006d1 DK |
1950 | testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" |
1951 | testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:755" | |
ab25bf1f | 1952 | # all copied files are properly chmodded |
63c71412 DK |
1953 | local backupIFS="$IFS" |
1954 | IFS="$(printf "\n\b")" | |
146f7715 | 1955 | for file in $(find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" -type f ! -name 'lock'); do |
4bb006d1 | 1956 | testfilestats "$file" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:644" |
ab25bf1f | 1957 | done |
63c71412 | 1958 | IFS="$backupIFS" |
59148d96 | 1959 | if [ "$TESTCALL" = 'testsuccess' ]; then |
146f7715 DK |
1960 | # failure cases can retain partial files and such |
1961 | testempty find "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" -mindepth 1 ! \( -name 'lock' -o -name '*.FAILED' \) | |
1962 | fi | |
ab25bf1f DK |
1963 | } |
1964 | aptautotest_apt_update() { aptautotest_aptget_update "$@"; } | |
d84da499 | 1965 | aptautotest_aptcdrom_add() { aptautotest_aptget_update "$@"; } |
016bea82 DK |
1966 | |
1967 | testaptautotestnodpkgwarning() { | |
1968 | local TESTCALL="$1" | |
1969 | while [ -n "$2" ]; do | |
6bf93605 DK |
1970 | if expr match "$2" '^-[a-z]*s' >/dev/null 2>&1; then return; fi # simulation mode |
1971 | if expr match "$2" '^-dy\?' >/dev/null 2>&1; then return; fi # download-only mode | |
016bea82 DK |
1972 | shift |
1973 | done | |
1974 | testfailure grep '^dpkg: warning:.*ignor.*' "${TMPWORKINGDIRECTORY}/rootdir/tmp-before/${TESTCALL}.output" | |
1975 | } | |
1976 | ||
1977 | aptautotest_aptget_install() { testaptautotestnodpkgwarning "$@"; } | |
1978 | aptautotest_aptget_remove() { testaptautotestnodpkgwarning "$@"; } | |
1979 | aptautotest_aptget_purge() { testaptautotestnodpkgwarning "$@"; } | |
1980 | aptautotest_apt_install() { testaptautotestnodpkgwarning "$@"; } | |
1981 | aptautotest_apt_remove() { testaptautotestnodpkgwarning "$@"; } | |
1982 | aptautotest_apt_purge() { testaptautotestnodpkgwarning "$@"; } |