1 #!/bin/sh -- # no runable script, just for vi
3 # we all like colorful messages
4 CERROR
="\e[1;31m" # red
5 CWARNING
="\e[1;33m" # yellow
6 CMSG
="\e[1;32m" # green
7 CINFO
="\e[1;96m" # light blue
8 CDEBUG
="\e[1;94m" # blue
9 CNORMAL
="\e[0;39m" # default system console color
10 CDONE
="\e[1;32m" # green
11 CPASS
="\e[1;32m" # green
12 CFAIL
="\e[1;31m" # red
13 CCMD
="\e[1;35m" # pink
15 msgdie
() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; }
16 msgwarn
() { echo "${CWARNING}W: $1${CNORMAL}" >&2; }
17 msgmsg
() { echo "${CMSG}$1${CNORMAL}" >&2; }
18 msginfo
() { echo "${CINFO}I: $1${CNORMAL}" >&2; }
19 msgdebug
() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; }
20 msgdone
() { echo "${CDONE}DONE${CNORMAL}" >&2; }
21 msgnwarn
() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; }
22 msgnmsg
() { echo -n "${CMSG}$1${CNORMAL}" >&2; }
23 msgninfo
() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; }
24 msgndebug
() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; }
25 msgtest
() { echo -n "${CINFO}$1 ${CCMD}$(echo "$2" | sed -e 's/^aptc/apt-c/' -e 's/^aptg/apt-g/' -e 's/^aptf/apt-f/')${CINFO} …${CNORMAL} " >&2; }
26 msgpass
() { echo "${CPASS}PASS${CNORMAL}" >&2; }
27 msgskip
() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
28 msgfail
() { echo "${CFAIL}FAIL${CNORMAL}" >&2; }
30 # enable / disable Debugging
35 msgdone
() { if [ "$1" = "debug" -o "$1" = "info" ]; then true
; else echo "${CDONE}DONE${CNORMAL}" >&2; fi }
38 msgdebug
"Executing: ${CCMD}$*${CDEBUG} "
39 if [ -f .
/aptconfig.conf
]; then
40 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
42 LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
45 aptconfig
() { runapt apt
-config $
*; }
46 aptcache
() { runapt apt
-cache $
*; }
47 aptget
() { runapt apt
-get $
*; }
48 aptftparchive
() { runapt apt
-ftparchive $
*; }
51 local TMPWORKINGDIRECTORY
=$(mktemp -d)
52 local TESTDIR
=$(readlink -f $(dirname $0))
53 msgninfo
"Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
54 BUILDDIRECTORY
="${TESTDIR}/../../build/bin"
55 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
56 local OLDWORKINGDIRECTORY
=$(pwd)
57 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
58 cd $TMPWORKINGDIRECTORY
59 mkdir rootdir aptarchive
61 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
62 mkdir -p var
/cache
/apt
/archives
/partial var
/lib
/apt
/lists
/partial
63 local STATUSFILE
=$(echo "$(basename $0)" | sed 's/^test-/status-/')
64 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
65 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
67 touch var/lib/dpkg/status
70 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
72 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
73 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
74 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive
/Packages
76 touch aptarchive
/Packages
78 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
79 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
80 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
85 configarchitecture
() {
86 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
87 echo "APT::Architecture \"$1\";" > $CONFFILE
90 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
95 buildflataptarchive
() {
96 msginfo
"Build APT archive for ${CCMD}$0${CINFO}…"
98 APTARCHIVE
=$(readlink -f .)
99 if [ -f Packages
]; then
100 msgninfo
"\tPackages file… "
101 cat Packages
| gzip > Packages.gz
102 cat Packages
| bzip2 > Packages.bz2
103 cat Packages
| lzma
> Packages.lzma
106 if [ -f Sources
]; then
107 msgninfo
"\tSources file… "
108 cat Sources
| gzip > Sources.gz
109 cat Sources
| bzip2 > Sources.bz2
110 cat Sources
| lzma
> Sources.lzma
114 aptftparchive release .
> Release
117 setupflataptarchive
() {
119 APTARCHIVE
=$(readlink -f ./aptarchive)
120 if [ -f ${APTARCHIVE}/Packages
]; then
121 msgninfo
"\tadd deb sources.list line… "
122 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
125 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
127 if [ -f ${APTARCHIVE}/Sources
]; then
128 msgninfo
"\tadd deb-src sources.list line… "
129 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
132 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
138 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
139 if [ -n "$DIFFTEXT" ]; then
149 local COMPAREFILE
=$(mktemp)
150 echo "$1" > $COMPAREFILE
152 msgtest
"Test for equality of" "$*"
153 $
* 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
158 local COMPAREFILE1
=$(mktemp)
159 local COMPAREFILE2
=$(mktemp)
160 local COMPAREAGAINST
=$(mktemp)
161 echo "$1" > $COMPAREFILE1
162 echo "$2" > $COMPAREFILE2
164 msgtest
"Test for equality OR of" "$*"
165 $
* 2>&1 1> $COMPAREAGAINST
166 (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
167 diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
168 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
169 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
171 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
175 local VIRTUAL
="N: Can't select versions from package '$1' as it purely virtual"
178 while [ -n "$1" ]; do
180 N: Can't select versions from package '$1' as it purely virtual"
181 PACKAGE
="${PACKAGE} $1"
184 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
186 N: No packages found"
187 local COMPAREFILE
=$(mktemp)
188 local ARCH
=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
189 eval `apt-config shell ARCH APT::Architecture`
190 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
191 aptcache show
$PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
196 msgtest
"Test for non-existent packages" "apt-cache show $*"
197 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
198 if [ -n "$SHOWPKG" ]; then