use 'best' hash for source authentication
[ntk/apt.git] / test / integration / framework
index 1ab421c..9cdc31e 100644 (file)
@@ -90,7 +90,13 @@ msgdone() {
                echo "${CDONE}DONE${CNORMAL}";
        fi
 }
-
+getaptconfig() {
+       if [ -f ./aptconfig.conf ]; then
+            echo "./aptconfig.conf"
+       elif [ -f ../aptconfig.conf ]; then
+            echo "../aptconfig.conf"
+        fi
+}
 runapt() {
        msgdebug "Executing: ${CCMD}$*${CDEBUG} "
        local CMD="$1"
@@ -99,13 +105,7 @@ runapt() {
        sh|aptitude|*/*) ;;
        *) CMD="${BUILDDIRECTORY}/$CMD";;
        esac
-       if [ -f ./aptconfig.conf ]; then
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
-       elif [ -f ../aptconfig.conf ]; then
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
-       else
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${LIBRARYPATH} $CMD "$@"
-       fi
+       MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@"
 }
 aptconfig() { runapt apt-config "$@"; }
 aptcache() { runapt apt-cache "$@"; }
@@ -118,6 +118,7 @@ apt() { runapt apt "$@"; }
 apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; }
 aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; }
 aptitude() { runapt aptitude "$@"; }
+aptextracttemplates() { runapt apt-extracttemplates "$@"; }
 
 dpkg() {
        command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
@@ -127,7 +128,10 @@ dpkgcheckbuilddeps() {
 }
 gdb() {
        echo "gdb: run »$*«"
-       APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${LIBRARYPATH} command gdb ${BUILDDIRECTORY}/$1 --args "$@"
+       CMD="$1"
+       shift
+
+       APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${LIBRARYPATH} command gdb ${BUILDDIRECTORY}/$CMD --args ${BUILDDIRECTORY}/$CMD "$@"
 }
 gpg() {
        # see apt-key for the whole trickery. Setup is done in setupenvironment
@@ -189,7 +193,13 @@ setupenvironment() {
        touch var/lib/dpkg/available
        mkdir -p usr/lib/apt
        ln -s ${METHODSDIR} usr/lib/apt/methods
-       ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
+        # use the autoremove from the BUILDDIRECTORY if its there, otherwise
+        # system
+        if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
+           ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
+        else
+           ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
+        fi
        cd ..
        local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
        if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
@@ -216,6 +226,7 @@ setupenvironment() {
        fi
        echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
        echo 'quiet::NoUpdate "true";' >> aptconfig.conf
+       echo 'quiet::NoStatistic "true";' >> aptconfig.conf
        echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https
         echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
        configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
@@ -234,7 +245,8 @@ setupenvironment() {
        gpg --quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev/null 2>&1
 
        # cleanup the environment a bit
-       export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
+        # prefer our apt binaries over the system apt binaries
+       export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
        export LC_ALL=C.UTF-8
        unset LANGUAGE APT_CONFIG
        unset GREP_OPTIONS DEB_BUILD_PROFILES
@@ -259,6 +271,10 @@ getarchitectures() {
        echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')"
 }
 
+getarchitecturesfromcommalist() {
+       echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/"
+}
+
 configarchitecture() {
        {
                echo "APT::Architecture \"$(getarchitecture $1)\";"
@@ -432,7 +448,7 @@ Package: $NAME" >> ${BUILDDIR}/debian/control
 #              fi
        done
 
-       for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
+       for arch in $(getarchitecturesfromcommalist "$ARCH"); do
                rm -rf ${BUILDDIR}/debian/tmp
                mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin
                cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME}
@@ -587,7 +603,7 @@ insertpackage() {
  something went horribly wrong! They are autogenerated
  und used only by testcases and surf no other propose…"}"
        local ARCHS=""
-       for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
+       for arch in $(getarchitecturesfromcommalist "$ARCH"); do
                if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
                        ARCHS="$(getarchitectures)"
                else
@@ -649,7 +665,7 @@ insertinstalledpackage() {
 
        local FILE='rootdir/var/lib/dpkg/status'
        local INFO='rootdir/var/lib/dpkg/info'
-       for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
+       for arch in $(getarchitecturesfromcommalist "$ARCH"); do
                echo "Package: $NAME
 Status: $STATUS
 Priority: $PRIORITY
@@ -874,6 +890,20 @@ rewritesourceslist() {
        done
 }
 
+# wait for up to 10s for a pid file to appear to avoid possible race
+# when a helper is started and dosn't write the PID quick enough
+waitforpidfile() {
+        local PIDFILE="$1"
+        for i in $(seq 10); do
+                if test -s "$PIDFILE"; then
+                        return 0
+                fi
+                sleep 1
+        done
+        msgdie "waiting for $PIDFILE failed"
+        return 1
+}
+
 changetowebserver() {
        if [ "$1" != '--no-rewrite' ]; then
                rewritesourceslist 'http://localhost:8080/'
@@ -887,6 +917,7 @@ changetowebserver() {
                        cat $LOG
                        false
                fi
+                waitforpidfile aptwebserver.pid
                local PID="$(cat aptwebserver.pid)"
                if [ -z "$PID" ]; then
                        msgdie 'Could not fork aptwebserver successfully'
@@ -914,7 +945,11 @@ accept = 4433
 connect = 8080
 " > ${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'
+       fi
        addtrap 'prefix' "kill ${PID};"
        rewritesourceslist 'https://localhost:4433/'
 }
@@ -943,8 +978,7 @@ acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
 
 downloadfile() {
        local PROTO="$(echo "$1" | cut -d':' -f 1 )"
-       apthelper -o Acquire::https::CaInfo=${TESTDIR}/apt.pem \
-               -o Debug::Acquire::${PROTO}=1 \
+       apthelper -o Debug::Acquire::${PROTO}=1 \
                download-file "$1" "$2" 2>&1 || true
        # only if the file exists the download was successful
        if [ -e "$2" ]; then