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