msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
# enable / disable Debugging
-msginfo() { true; }
-msgdebug() { true; }
-msgninfo() { true; }
-msgndebug() { true; }
-msgdone() { if [ "$1" = "debug" -o "$1" = "info" ]; then true; else echo "${CDONE}DONE${CNORMAL}" >&2; fi }
+MSGLEVEL=${MSGLEVEL:-3}
+if [ $MSGLEVEL -le 0 ]; then
+ msgdie() { true; }
+fi
+if [ $MSGLEVEL -le 1 ]; then
+ msgwarn() { true; }
+ msgnwarn() { true; }
+fi
+if [ $MSGLEVEL -le 2 ]; then
+ msgmsg() { true; }
+ msgnmsg() { true; }
+fi
+if [ $MSGLEVEL -le 3 ]; then
+ msginfo() { true; }
+ msgninfo() { true; }
+fi
+if [ $MSGLEVEL -le 4 ]; then
+ msgdebug() { true; }
+ msgndebug() { true; }
+fi
+msgdone() {
+ if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] ||
+ [ "$1" = "info" -a $MSGLEVEL -le 3 ] ||
+ [ "$1" = "msg" -a $MSGLEVEL -le 2 ] ||
+ [ "$1" = "warn" -a $MSGLEVEL -le 1 ] ||
+ [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then
+ true;
+ else
+ echo "${CDONE}DONE${CNORMAL}" >&2;
+ fi
+}
runapt() {
msgdebug "Executing: ${CCMD}$*${CDEBUG} "
- APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
+ if [ -f ./aptconfig.conf ]; then
+ APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
+ else
+ LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
+ fi
}
aptconfig() { runapt apt-config $*; }
aptcache() { runapt apt-cache $*; }
setupenvironment() {
local TMPWORKINGDIRECTORY=$(mktemp -d)
+ local TESTDIR=$(readlink -f $(dirname $0))
msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
- BUILDDIRECTORY=$(readlink -f $(dirname $0)/../../build/bin)
+ BUILDDIRECTORY="${TESTDIR}/../../build/bin"
test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
local OLDWORKINGDIRECTORY=$(pwd)
trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
cd rootdir
mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d var/cache var/lib/dpkg
mkdir -p var/cache/apt/archives/partial var/lib/apt/lists/partial
- touch var/lib/dpkg/status
+ local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/')
+ if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
+ cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
+ else
+ touch var/lib/dpkg/status
+ fi
mkdir -p usr/lib/apt
ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
cd ..
+ local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
+ if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
+ cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages
+ else
+ touch aptarchive/Packages
+ fi
echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
echo "Debug::NoLocking \"true\";" >> aptconfig.conf
echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
done
}
-buildflataptarchive() {
- msginfo "Build APT archive for ${CCMD}$0${CINFO}…"
+buildsimplenativepackage() {
+ local NAME="$1"
+ local ARCH="$2"
+ local VERSION="$3"
+ local RELEASE="${4:-unstable}"
+ local DEPENDENCIES="$5"
+ local DESCRIPTION="$6"
+ msgndebug "Build package ${CCMD}${NAME}=${VERSION}/${RELEASE}${CDEBUG}… "
+ local BUILDDIR=incoming/${NAME}-${VERSION}
+ mkdir -p ${BUILDDIR}/debian/source
+ cd ${BUILDDIR}
+ echo "* most suckless software product ever" > FEATURES
+ test -e debian/copyright || (echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright)
+ test -e debian/changelog || (echo "$NAME ($VERSION) $RELEASE; urgency=low
+
+ * Initial release
+
+ -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog)
+ test -e debian/control || (echo "Source: $NAME
+Section: admin
+Priority: optional
+Maintainer: Joe Sixpack <joe@example.org>
+Build-Depends: debhelper (>= 7)
+Standards-Version: 3.9.1
+
+Package: $NAME
+Architecture: $ARCH" > debian/control)
+ test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control
+ if [ -z "$DESCRIPTION" ]; then
+ echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
+ If you find such a package installed on your system,
+ YOU did something horribly wrong! They are autogenerated
+ und used only by testcases for APT and surf no other propose…" >> debian/control
+ else
+ echo "Description: $DESCRIPTION" >> debian/control
+ fi
+ test -e debian/compat || (echo "7" > debian/compat)
+ test -e debian/source/format || (echo "3.0 (native)" > debian/source/format)
+ test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules
+ dpkg-buildpackage -uc -us -a$ARCH > /dev/null 2> /dev/null
+ cd - > /dev/null
+ rm -rf $BUILDDIR
+ msgdone "debug"
+}
+
+buildaptarchive() {
+ msgninfo "Build APT archive for ${CCMD}$0${CINFO} based on "
+ if [ -d incoming ]; then
+ buildaptarchivefromincoming $*
+ else
+ buildaptarchivefromfiles $*
+ fi
+}
+
+createaptftparchiveconfig() {
+ local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
+ echo -n 'Dir {
+ ArchiveDir "' >> ftparchive.conf
+ echo -n $(readlink -f .) >> ftparchive.conf
+ echo -n '";
+ CacheDir "' >> ftparchive.conf
+ echo -n $(readlink -f ..) >> ftparchive.conf
+ echo -n '";
+};
+TreeDefault {
+ Directory "pool/";
+ SrcDirectory "pool/";
+};
+APT {
+ FTPArchive {
+ Release {
+ Origin "joesixpack";
+ Label "apttestcases";
+ Suite "unstable";
+ Description "repository with dummy packages";
+ Architectures "' >> ftparchive.conf
+ echo -n "$ARCHS" >> ftparchive.conf
+ echo 'source";
+ };
+ };
+};' >> ftparchive.conf
+ if [ -z "$1" ]; then
+ echo -n 'tree "dists/unstable" {
+ Architectures "' >> ftparchive.conf
+ echo -n "$ARCHS" >> ftparchive.conf
+ echo 'source";
+ Sections "main";
+};' >> ftparchive.conf
+ fi
+}
+
+buildaptftparchivedirectorystructure() {
+ local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#')"
+ for arch in $ARCHS; do
+ mkdir -p dists/unstable/main/binary-${arch}
+ done
+ mkdir -p dists/unstable/main/source
+ mkdir -p dists/unstable/main/i18n
+}
+
+buildaptarchivefromincoming() {
+ msginfo "incoming packages…"
+ cd aptarchive
+ [ -e pool ] || ln -s ../incoming pool
+ [ -e ftparchive.conf ] || createaptftparchiveconfig
+ [ -e dists ] || buildaptftparchivedirectorystructure
+ aptftparchive -qq generate ftparchive.conf
+ for dir in $(find ./dists -mindepth 1 -maxdepth 1 -type d); do
+ aptftparchive -qq release $dir > $dir/Release
+ sed -i -e '/0 Release$/ d' $dir/Release # remove the self reference
+ done
+ cd - > /dev/null
+ msgdone "info"
+}
+
+buildaptarchivefromfiles() {
+ msginfo "prebuild files…"
cd aptarchive
- APTARCHIVE=$(readlink -f .)
if [ -f Packages ]; then
msgninfo "\tPackages file… "
cat Packages | gzip > Packages.gz
cat Sources | lzma > Sources.lzma
msgdone "info"
fi
+ aptftparchive -qq release . > Release
+ sed -i -e '/0 Release$/ d' Release # remove the self reference
cd ..
- aptftparchive release . > Release
}
-setupflataptarchive() {
- buildflataptarchive
- APTARCHIVE=$(readlink -f ./aptarchive)
+setupaptarchive() {
+ buildaptarchive
+ local APTARCHIVE=$(readlink -f ./aptarchive)
if [ -f ${APTARCHIVE}/Packages ]; then
msgninfo "\tadd deb sources.list line… "
echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list
shift
msgtest "Test for equality of" "$*"
$* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
+ rm $COMPAREFILE
+}
+
+testequalor2() {
+ local COMPAREFILE1=$(mktemp)
+ local COMPAREFILE2=$(mktemp)
+ local COMPAREAGAINST=$(mktemp)
+ echo "$1" > $COMPAREFILE1
+ echo "$2" > $COMPAREFILE2
+ shift 2
+ msgtest "Test for equality OR of" "$*"
+ $* 2>&1 1> $COMPAREAGAINST
+ (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
+ diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
+ ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
+ "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
+ msgfail )
+ rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
}
testshowvirtual() {
- local VIRTUAL="E: Can't select versions from package '$1' as it purely virtual"
+ local VIRTUAL="N: Can't select versions from package '$1' as it purely virtual"
local PACKAGE="$1"
shift
while [ -n "$1" ]; do
VIRTUAL="${VIRTUAL}
-E: Can't select versions from package '$1' as it purely virtual"
+N: Can't select versions from package '$1' as it purely virtual"
PACKAGE="${PACKAGE} $1"
shift
done
msgtest "Test for virtual packages" "apt-cache show $PACKAGE"
VIRTUAL="${VIRTUAL}
-E: No packages found"
+N: No packages found"
local COMPAREFILE=$(mktemp)
local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
eval `apt-config shell ARCH APT::Architecture`
echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail
+ rm $COMPAREFILE
}
testnopackage() {