]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
test: Explicitly pass --admindir=var/lib/dpkg to dpkg
[apt.git] / test / integration / framework
index ff0df322654f729afec23dbec434462fb51947a4..827226b7de80766746a3af04c2c684137f4c58ca 100644 (file)
@@ -31,7 +31,6 @@ if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
        fi
 fi
 
-
 if [ "$MSGCOLOR" != 'NO' ]; then
        CERROR="\033[1;31m" # red
        CWARNING="\033[1;33m" # yellow
@@ -276,8 +275,13 @@ find_project_binary_dir() {
        fi
 }
 setupenvironment() {
+       # Next check needs a gnu stat, let's figure that out early.
+       stat=stat
+       if command -v gnustat >/dev/null 2>&1; then
+               stat=gnustat
+       fi
        # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
-       if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
+       if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$($stat --format '%a' "$TMPDIR")" != '1777' ]; then
                unset TMPDIR
        fi
        TMPWORKINGDIRECTORY="$(mktemp -d)"
@@ -290,6 +294,18 @@ setupenvironment() {
        fi
        msgninfo "Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
 
+       # Setup coreutils on BSD systems
+       mkdir "${TMPWORKINGDIRECTORY}/bin"
+       for prefix in gnu g; do
+                       for command in stat touch sed cp tr sha1sum sha256sum md5sum sha512sum grep date wc chmod head readlink tar expr base64; do
+                                       if command -v $prefix$command 2>/dev/null >/dev/null; then
+                                                       [ -e "${TMPWORKINGDIRECTORY}/bin/$command" ] || ln -sf $(command -v $prefix$command)  "${TMPWORKINGDIRECTORY}/bin/$command"
+                                       fi
+                       done
+       done
+       export PATH="${TMPWORKINGDIRECTORY}/bin/:$PATH"
+
+
        mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
        if [ "$(id -u)" = '0' ]; then
                # relax permissions so that running as root with user switching works
@@ -391,11 +407,13 @@ EOF
        cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
        cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
+       --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
        --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
        --force-not-root --force-bad-path "\$@"
 EOF
        cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF
 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
+       --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
        --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
        --force-not-root --force-bad-path "\$@"
 EOF
@@ -573,7 +591,11 @@ int execvp(const char *file, char *const argv[]) {
        return func_execvp(newfile, argv);
 }
 EOF
-       testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
+       if cc -ldl 2>&1 | grep -q dl; then
+               testempty --nomsg cc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
+       else
+               testempty --nomsg cc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
+       fi
 }
 configcompression() {
        if [ "$1" = 'ALL' ]; then
@@ -685,13 +707,25 @@ Package: $NAME"
        echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
 }
 
+make_tiny_rules() {
+       local OUT="$1"
+       if command -v gmake >/dev/null 2>&1; then
+               [ -e ${TMPWORKINGDIRECTORY}/bin/make ] || ln -s $(command -v gmake) ${TMPWORKINGDIRECTORY}/bin/make
+               echo "#!${TMPWORKINGDIRECTORY}/bin/make -f" > "$OUT"
+       else
+               echo '#!/usr/bin/make -f' > "$OUT"
+       fi
+       echo '%:' >> "$OUT"
+       echo '  dh $@' >> "$OUT"
+}
+
 setupsimplenativepackage() {
        _setupsimplenativepackage "$@"
        local NAME="$1"
        local VERSION="$3"
        local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
        test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
-       test -e  "${BUILDDIR}/debian/rules" || cp /usr/share/doc/debhelper/examples/rules.tiny "${BUILDDIR}/debian/rules"
+       test -e  "${BUILDDIR}/debian/rules" || make_tiny_rules "${BUILDDIR}/debian/rules"
 }
 
 buildsimplenativepackage() {
@@ -1280,7 +1314,12 @@ changetowebserver() {
 }
 
 changetohttpswebserver() {
-       if ! command -v stunnel4 >/dev/null 2>&1; then
+       local stunnel4
+       if command -v stunnel4 >/dev/null 2>&1; then
+               stunnel4=stunnel4
+       elif command -v stunnel >/dev/null 2>&1; then
+               stunnel4=stunnel
+       else
                msgdie 'You need to install stunnel4 for https testcases'
        fi
        if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
@@ -1294,14 +1333,14 @@ output = /dev/null
 accept = 0
 connect = $APTHTTPPORT
 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
-       stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
+       $stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
         waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
        local PID="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
         if [ -z "$PID" ]; then
-               msgdie 'Could not fork stunnel4 successfully'
+               msgdie 'Could not fork $stunnel4 successfully'
        fi
        addtrap 'prefix' "kill ${PID};"
-       APTHTTPSPORT="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
+       APTHTTPSPORT="$(lsof -i -n | awk "/^$stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
        webserverconfig 'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
        rewritesourceslist "https://localhost:${APTHTTPSPORT}/"
 }