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