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 APT_CONFIG
=aptconfig.conf LD_LIBRARY_PATH
=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$
*
41 aptconfig
() { runapt apt
-config $
*; }
42 aptcache
() { runapt apt
-cache $
*; }
43 aptget
() { runapt apt
-get $
*; }
44 aptftparchive
() { runapt apt
-ftparchive $
*; }
47 local TMPWORKINGDIRECTORY
=$(mktemp -d)
48 local TESTDIR
=$(readlink -f $(dirname $0))
49 msgninfo
"Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
50 BUILDDIRECTORY
="${TESTDIR}/../../build/bin"
51 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
52 local OLDWORKINGDIRECTORY
=$(pwd)
53 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
54 cd $TMPWORKINGDIRECTORY
55 mkdir rootdir aptarchive
57 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
58 mkdir -p var
/cache
/apt
/archives
/partial var
/lib
/apt
/lists
/partial
59 local STATUSFILE
=$(echo "$(basename $0)" | sed 's/^test-/status-/')
60 if [ -f "${TESTDIR}/${STATUSFILE}" ]; then
61 cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status
63 touch var/lib/dpkg/status
66 ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods
68 local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/')
69 if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then
70 cp "${TESTDIR}/${PACKAGESFILE}" aptarchive
/Packages
72 touch var
/lib
/dpkg
/status
74 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
75 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
76 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
81 configarchitecture
() {
82 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
83 echo "APT::Architecture \"$1\";" > $CONFFILE
86 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
91 buildflataptarchive
() {
92 msginfo
"Build APT archive for ${CCMD}$0${CINFO}…"
94 APTARCHIVE
=$(readlink -f .)
95 if [ -f Packages
]; then
96 msgninfo
"\tPackages file… "
97 cat Packages
| gzip > Packages.gz
98 cat Packages
| bzip2 > Packages.bz2
99 cat Packages
| lzma
> Packages.lzma
102 if [ -f Sources
]; then
103 msgninfo
"\tSources file… "
104 cat Sources
| gzip > Sources.gz
105 cat Sources
| bzip2 > Sources.bz2
106 cat Sources
| lzma
> Sources.lzma
110 aptftparchive release .
> Release
113 setupflataptarchive
() {
115 APTARCHIVE
=$(readlink -f ./aptarchive)
116 if [ -f ${APTARCHIVE}/Packages
]; then
117 msgninfo
"\tadd deb sources.list line… "
118 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
121 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
123 if [ -f ${APTARCHIVE}/Sources
]; then
124 msgninfo
"\tadd deb-src sources.list line… "
125 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
128 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
134 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
135 if [ -n "$DIFFTEXT" ]; then
145 local COMPAREFILE
=$(mktemp)
146 echo "$1" > $COMPAREFILE
148 msgtest
"Test for equality of" "$*"
149 $
* 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
154 local COMPAREFILE1
=$(mktemp)
155 local COMPAREFILE2
=$(mktemp)
156 local COMPAREAGAINST
=$(mktemp)
157 echo "$1" > $COMPAREFILE1
158 echo "$2" > $COMPAREFILE2
160 msgtest
"Test for equality OR of" "$*"
161 $
* 2>&1 1> $COMPAREAGAINST
162 (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev
/null
||
163 diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev
/null
) && msgpass
||
164 ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \
165 "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" &&
167 rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST
171 local VIRTUAL
="E: Can't select versions from package '$1' as it purely virtual"
174 while [ -n "$1" ]; do
176 E: Can't select versions from package '$1' as it purely virtual"
177 PACKAGE
="${PACKAGE} $1"
180 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
182 E: No packages found"
183 local COMPAREFILE
=$(mktemp)
184 local ARCH
=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
185 eval `apt-config shell ARCH APT::Architecture`
186 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
187 aptcache show
$PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
192 msgtest
"Test for non-existent packages" "apt-cache show $*"
193 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
194 if [ -n "$SHOWPKG" ]; then