]>
Commit | Line | Data |
---|---|---|
8d876415 DK |
1 | #!/bin/sh -- # no runable script, just for vi |
2 | ||
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 | |
14 | ||
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; } | |
29 | ||
30 | # enable / disable Debugging | |
31 | msginfo() { true; } | |
32 | msgdebug() { true; } | |
33 | msgninfo() { true; } | |
34 | msgndebug() { true; } | |
35 | msgdone() { if [ "$1" = "debug" -o "$1" = "info" ]; then true; else echo "${CDONE}DONE${CNORMAL}" >&2; fi } | |
36 | ||
37 | runapt() { | |
38 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
39 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
40 | } | |
41 | aptconfig() { runapt apt-config $*; } | |
42 | aptcache() { runapt apt-cache $*; } | |
43 | aptget() { runapt apt-get $*; } | |
44 | aptftparchive() { runapt apt-ftparchive $*; } | |
45 | ||
46 | setupenvironment() { | |
47 | local TMPWORKINGDIRECTORY=$(mktemp -d) | |
8f8169ac | 48 | local TESTDIR=$(readlink -f $(dirname $0)) |
8d876415 | 49 | msgninfo "Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… " |
8f8169ac | 50 | BUILDDIRECTORY="${TESTDIR}/../../build/bin" |
8d876415 DK |
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 | |
56 | cd rootdir | |
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 | |
8f8169ac DK |
59 | local STATUSFILE=$(echo "$(basename $0)" | sed 's/^test-/status-/') |
60 | if [ -f "${TESTDIR}/${STATUSFILE}" ]; then | |
61 | cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status | |
62 | else | |
63 | touch var/lib/dpkg/status | |
64 | fi | |
8d876415 DK |
65 | mkdir -p usr/lib/apt |
66 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
67 | cd .. | |
8f8169ac DK |
68 | local PACKAGESFILE=$(echo "$(basename $0)" | sed 's/^test-/Packages-/') |
69 | if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then | |
70 | cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages | |
71 | else | |
72 | touch var/lib/dpkg/status | |
73 | fi | |
8d876415 DK |
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 | |
77 | export LC_ALL=C | |
78 | msgdone "info" | |
79 | } | |
80 | ||
81 | configarchitecture() { | |
82 | local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
83 | echo "APT::Architecture \"$1\";" > $CONFFILE | |
84 | shift | |
85 | while [ -n "$1" ]; do | |
86 | echo "APT::Architectures:: \"$1\";" >> $CONFFILE | |
87 | shift | |
88 | done | |
89 | } | |
90 | ||
91 | buildflataptarchive() { | |
92 | msginfo "Build APT archive for ${CCMD}$0${CINFO}…" | |
93 | cd aptarchive | |
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 | |
100 | msgdone "info" | |
101 | fi | |
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 | |
107 | msgdone "info" | |
108 | fi | |
109 | cd .. | |
110 | aptftparchive release . > Release | |
111 | } | |
112 | ||
113 | setupflataptarchive() { | |
114 | buildflataptarchive | |
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 | |
119 | msgdone "info" | |
120 | else | |
121 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
122 | fi | |
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 | |
126 | msgdone "info" | |
127 | else | |
128 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
129 | fi | |
130 | aptget update -qq | |
131 | } | |
132 | ||
133 | diff() { | |
134 | local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" | |
135 | if [ -n "$DIFFTEXT" ]; then | |
136 | echo | |
137 | echo "$DIFFTEXT" | |
138 | return 1 | |
139 | else | |
140 | return 0 | |
141 | fi | |
142 | } | |
143 | ||
144 | testequal() { | |
145 | local COMPAREFILE=$(mktemp) | |
146 | echo "$1" > $COMPAREFILE | |
147 | shift | |
148 | msgtest "Test for equality of" "$*" | |
149 | $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail | |
150 | } | |
151 | ||
685625bd DK |
152 | testequalor2() { |
153 | local COMPAREFILE1=$(mktemp) | |
154 | local COMPAREFILE2=$(mktemp) | |
155 | local COMPAREAGAINST=$(mktemp) | |
156 | echo "$1" > $COMPAREFILE1 | |
157 | echo "$2" > $COMPAREFILE2 | |
158 | shift 2 | |
159 | msgtest "Test for equality OR of" "$*" | |
160 | $* 2>&1 1> $COMPAREAGAINST | |
161 | (diff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || | |
162 | diff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass || | |
163 | ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(diff $COMPAREFILE1 $COMPAREAGAINST)" \ | |
164 | "\n${CINFO}Diff against OR 2${CNORMAL}" "$(diff $COMPAREFILE2 $COMPAREAGAINST)" && | |
165 | msgfail ) | |
166 | } | |
167 | ||
8d876415 DK |
168 | testshowvirtual() { |
169 | local VIRTUAL="E: Can't select versions from package '$1' as it purely virtual" | |
170 | local PACKAGE="$1" | |
171 | shift | |
172 | while [ -n "$1" ]; do | |
173 | VIRTUAL="${VIRTUAL} | |
174 | E: Can't select versions from package '$1' as it purely virtual" | |
175 | PACKAGE="${PACKAGE} $1" | |
176 | shift | |
177 | done | |
178 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
179 | VIRTUAL="${VIRTUAL} | |
180 | E: No packages found" | |
181 | local COMPAREFILE=$(mktemp) | |
182 | local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU) | |
183 | eval `apt-config shell ARCH APT::Architecture` | |
184 | echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE | |
185 | aptcache show $PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass || msgfail | |
186 | } | |
187 | ||
188 | testnopackage() { | |
189 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
190 | local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" | |
191 | if [ -n "$SHOWPKG" ]; then | |
192 | echo | |
193 | echo "$SHOWPKG" | |
194 | msgfail | |
195 | return 1 | |
196 | fi | |
197 | msgpass | |
198 | } |