]>
Commit | Line | Data |
---|---|---|
8d876415 DK |
1 | #!/bin/sh -- # no runable script, just for vi |
2 | ||
3 | # we all like colorful messages | |
682a3bf7 DK |
4 | if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null && \ |
5 | expr match "$(readlink -f /proc/$$/fd/2)" '/dev/pts/[0-9]\+' > /dev/null; then | |
6 | CERROR="\e[1;31m" # red | |
7 | CWARNING="\e[1;33m" # yellow | |
8 | CMSG="\e[1;32m" # green | |
9 | CINFO="\e[1;96m" # light blue | |
10 | CDEBUG="\e[1;94m" # blue | |
11 | CNORMAL="\e[0;39m" # default system console color | |
12 | CDONE="\e[1;32m" # green | |
13 | CPASS="\e[1;32m" # green | |
14 | CFAIL="\e[1;31m" # red | |
15 | CCMD="\e[1;35m" # pink | |
16 | fi | |
8d876415 DK |
17 | |
18 | msgdie() { echo "${CERROR}E: $1${CNORMAL}" >&2; exit 1; } | |
19 | msgwarn() { echo "${CWARNING}W: $1${CNORMAL}" >&2; } | |
20 | msgmsg() { echo "${CMSG}$1${CNORMAL}" >&2; } | |
21 | msginfo() { echo "${CINFO}I: $1${CNORMAL}" >&2; } | |
22 | msgdebug() { echo "${CDEBUG}D: $1${CNORMAL}" >&2; } | |
23 | msgdone() { echo "${CDONE}DONE${CNORMAL}" >&2; } | |
24 | msgnwarn() { echo -n "${CWARNING}W: $1${CNORMAL}" >&2; } | |
25 | msgnmsg() { echo -n "${CMSG}$1${CNORMAL}" >&2; } | |
26 | msgninfo() { echo -n "${CINFO}I: $1${CNORMAL}" >&2; } | |
27 | msgndebug() { echo -n "${CDEBUG}D: $1${CNORMAL}" >&2; } | |
28 | 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; } | |
29 | msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; } | |
30 | msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; } | |
31 | msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; } | |
32 | ||
33 | # enable / disable Debugging | |
fc89263e DK |
34 | MSGLEVEL=${MSGLEVEL:-3} |
35 | if [ $MSGLEVEL -le 0 ]; then | |
36 | msgdie() { true; } | |
37 | fi | |
38 | if [ $MSGLEVEL -le 1 ]; then | |
39 | msgwarn() { true; } | |
40 | msgnwarn() { true; } | |
41 | fi | |
42 | if [ $MSGLEVEL -le 2 ]; then | |
43 | msgmsg() { true; } | |
44 | msgnmsg() { true; } | |
39cc8228 DK |
45 | msgtest() { true; } |
46 | msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; } | |
47 | msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; } | |
682a3bf7 DK |
48 | if [ -n "$CFAIL" ]; then |
49 | msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; } | |
50 | else | |
51 | msgfail() { echo -n " ###FAILED###" >&2; } | |
52 | fi | |
fc89263e DK |
53 | fi |
54 | if [ $MSGLEVEL -le 3 ]; then | |
55 | msginfo() { true; } | |
56 | msgninfo() { true; } | |
57 | fi | |
58 | if [ $MSGLEVEL -le 4 ]; then | |
59 | msgdebug() { true; } | |
60 | msgndebug() { true; } | |
61 | fi | |
62 | msgdone() { | |
63 | if [ "$1" = "debug" -a $MSGLEVEL -le 4 ] || | |
64 | [ "$1" = "info" -a $MSGLEVEL -le 3 ] || | |
65 | [ "$1" = "msg" -a $MSGLEVEL -le 2 ] || | |
66 | [ "$1" = "warn" -a $MSGLEVEL -le 1 ] || | |
67 | [ "$1" = "die" -a $MSGLEVEL -le 0 ]; then | |
68 | true; | |
69 | else | |
70 | echo "${CDONE}DONE${CNORMAL}" >&2; | |
71 | fi | |
72 | } | |
8d876415 DK |
73 | |
74 | runapt() { | |
75 | msgdebug "Executing: ${CCMD}$*${CDEBUG} " | |
7d0627b6 DK |
76 | if [ -f ./aptconfig.conf ]; then |
77 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
4b2a4ab8 MV |
78 | elif [ -f ../aptconfig.conf ]; then |
79 | APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
7d0627b6 DK |
80 | else |
81 | LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$* | |
82 | fi | |
8d876415 DK |
83 | } |
84 | aptconfig() { runapt apt-config $*; } | |
85 | aptcache() { runapt apt-cache $*; } | |
86 | aptget() { runapt apt-get $*; } | |
87 | aptftparchive() { runapt apt-ftparchive $*; } | |
1f8b2599 | 88 | aptkey() { runapt apt-key $*; } |
ec7f904e | 89 | aptmark() { runapt apt-mark $*; } |
158fda31 DK |
90 | dpkg() { |
91 | $(which dpkg) --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log $* | |
92 | } | |
b6b5a542 DK |
93 | aptitude() { |
94 | if [ -f ./aptconfig.conf ]; then | |
95 | APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $* | |
96 | elif [ -f ../aptconfig.conf ]; then | |
97 | APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $* | |
98 | else | |
99 | LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which aptitude) $* | |
100 | fi | |
101 | } | |
8d876415 | 102 | |
b720d0bd DK |
103 | addtrap() { |
104 | CURRENTTRAP="$CURRENTTRAP $1" | |
105 | trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM | |
106 | } | |
8d876415 DK |
107 | |
108 | setupenvironment() { | |
75954ae2 | 109 | TMPWORKINGDIRECTORY=$(mktemp -d) |
8f8169ac | 110 | local TESTDIR=$(readlink -f $(dirname $0)) |
3cbbda3c | 111 | msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… " |
8f8169ac | 112 | BUILDDIRECTORY="${TESTDIR}/../../build/bin" |
8d876415 DK |
113 | test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first" |
114 | local OLDWORKINGDIRECTORY=$(pwd) | |
b720d0bd | 115 | addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;" |
8d876415 | 116 | cd $TMPWORKINGDIRECTORY |
cd725954 | 117 | mkdir rootdir aptarchive keys |
8d876415 | 118 | cd rootdir |
b29c3712 DK |
119 | mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d |
120 | mkdir -p var/cache var/lib var/log | |
cffea9af | 121 | mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers |
2c6baa5a | 122 | local STATUSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/status-/' -e 's/^skip-/status-/') |
8f8169ac DK |
123 | if [ -f "${TESTDIR}/${STATUSFILE}" ]; then |
124 | cp "${TESTDIR}/${STATUSFILE}" var/lib/dpkg/status | |
125 | else | |
126 | touch var/lib/dpkg/status | |
127 | fi | |
cd725954 | 128 | touch var/lib/dpkg/available |
8d876415 DK |
129 | mkdir -p usr/lib/apt |
130 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
131 | cd .. | |
2c6baa5a | 132 | local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/') |
8f8169ac DK |
133 | if [ -f "${TESTDIR}/${PACKAGESFILE}" ]; then |
134 | cp "${TESTDIR}/${PACKAGESFILE}" aptarchive/Packages | |
8f8169ac | 135 | fi |
4a4ea26c AM |
136 | local SOURCESSFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Sources-/' -e 's/^skip-/Sources-/') |
137 | if [ -f "${TESTDIR}/${SOURCESSFILE}" ]; then | |
138 | cp "${TESTDIR}/${SOURCESSFILE}" aptarchive/Sources | |
8f8169ac | 139 | fi |
cd725954 DK |
140 | cp $(find $TESTDIR -name '*.pub' -o -name '*.sec') keys/ |
141 | ln -s ${TMPWORKINGDIRECTORY}/keys/joesixpack.pub rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg | |
cffea9af | 142 | echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf |
94eb3bee | 143 | echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf |
8d876415 DK |
144 | echo "Debug::NoLocking \"true\";" >> aptconfig.conf |
145 | echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf | |
f425d4d5 | 146 | echo "Dir::Bin::Methods \"${BUILDDIRECTORY}/methods\";" >> aptconfig.conf |
cffea9af DK |
147 | echo "Dir::Bin::dpkg \"fakeroot\";" >> aptconfig.conf |
148 | echo "DPKG::options:: \"dpkg\";" >> aptconfig.conf | |
149 | echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf | |
150 | echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf | |
151 | echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf | |
152 | echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf | |
2c085486 | 153 | echo 'quiet::NoUpdate "true";' >> aptconfig.conf |
8d876415 | 154 | export LC_ALL=C |
7f52cf7b | 155 | export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin" |
8d876415 DK |
156 | msgdone "info" |
157 | } | |
158 | ||
159 | configarchitecture() { | |
160 | local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
234675b7 | 161 | rm -f $CONFFILE |
8d876415 DK |
162 | echo "APT::Architecture \"$1\";" > $CONFFILE |
163 | shift | |
164 | while [ -n "$1" ]; do | |
165 | echo "APT::Architectures:: \"$1\";" >> $CONFFILE | |
166 | shift | |
167 | done | |
168 | } | |
169 | ||
75954ae2 | 170 | setupsimplenativepackage() { |
ce9864a8 DK |
171 | local NAME="$1" |
172 | local ARCH="$2" | |
173 | local VERSION="$3" | |
174 | local RELEASE="${4:-unstable}" | |
175 | local DEPENDENCIES="$5" | |
176 | local DESCRIPTION="$6" | |
b7899b00 DK |
177 | local SECTION="${7:-others}" |
178 | local DISTSECTION | |
179 | if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then | |
180 | DISTSECTION="main" | |
181 | else | |
182 | DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" | |
183 | fi | |
ce9864a8 DK |
184 | local BUILDDIR=incoming/${NAME}-${VERSION} |
185 | mkdir -p ${BUILDDIR}/debian/source | |
186 | cd ${BUILDDIR} | |
187 | echo "* most suckless software product ever" > FEATURES | |
b7899b00 DK |
188 | test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright |
189 | test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low | |
ce9864a8 DK |
190 | |
191 | * Initial release | |
192 | ||
b7899b00 DK |
193 | -- Joe Sixpack <joe@example.org> $(date -R)" > debian/changelog |
194 | test -e debian/control || echo "Source: $NAME | |
195 | Section: $SECTION | |
ce9864a8 DK |
196 | Priority: optional |
197 | Maintainer: Joe Sixpack <joe@example.org> | |
198 | Build-Depends: debhelper (>= 7) | |
199 | Standards-Version: 3.9.1 | |
200 | ||
875bcb36 DK |
201 | Package: $NAME" > debian/control |
202 | if [ "$ARCH" = 'all' ]; then | |
203 | echo "Architecture: all" >> debian/control | |
204 | else | |
205 | echo "Architecture: any" >> debian/control | |
206 | fi | |
ce9864a8 DK |
207 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> debian/control |
208 | if [ -z "$DESCRIPTION" ]; then | |
209 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
210 | If you find such a package installed on your system, | |
211 | YOU did something horribly wrong! They are autogenerated | |
212 | und used only by testcases for APT and surf no other propose…" >> debian/control | |
213 | else | |
214 | echo "Description: $DESCRIPTION" >> debian/control | |
215 | fi | |
b7899b00 DK |
216 | test -e debian/compat || echo "7" > debian/compat |
217 | test -e debian/source/format || echo "3.0 (native)" > debian/source/format | |
ce9864a8 | 218 | test -e debian/rules || cp /usr/share/doc/debhelper/examples/rules.tiny debian/rules |
75954ae2 DK |
219 | cd - > /dev/null |
220 | } | |
221 | ||
222 | buildsimplenativepackage() { | |
223 | local NAME="$1" | |
224 | local ARCH="$2" | |
225 | local VERSION="$3" | |
226 | local RELEASE="${4:-unstable}" | |
227 | local DEPENDENCIES="$5" | |
228 | local DESCRIPTION="$6" | |
229 | local SECTION="${7:-others}" | |
d67004e0 | 230 | local PRIORITY="${8:-optional}" |
75954ae2 DK |
231 | local DISTSECTION |
232 | if [ "$SECTION" = "$(echo "$SECTION" | cut -d'/' -f 2)" ]; then | |
233 | DISTSECTION="main" | |
234 | else | |
235 | DISTSECTION="$(echo "$SECTION" | cut -d'/' -f 1)" | |
236 | fi | |
5a635ee4 | 237 | local BUILDDIR=${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION} |
b761356f | 238 | |
18331adf | 239 | msgninfo "Build package ${NAME} in ${VERSION} for ${RELEASE} in ${DISTSECTION}… " |
b761356f DK |
240 | mkdir -p $BUILDDIR/debian/source |
241 | echo "* most suckless software product ever" > ${BUILDDIR}/FEATURES | |
242 | echo "#!/bin/sh | |
243 | echo '$NAME says \"Hello!\"'" > ${BUILDDIR}/${NAME} | |
244 | ||
245 | echo "Copyleft by Joe Sixpack $(date +%Y)" > ${BUILDDIR}/debian/copyright | |
246 | echo "$NAME ($VERSION) $RELEASE; urgency=low | |
247 | ||
248 | * Initial release | |
249 | ||
250 | -- Joe Sixpack <joe@example.org> $(date -R)" > ${BUILDDIR}/debian/changelog | |
251 | echo "Source: $NAME | |
252 | Section: $SECTION | |
d67004e0 | 253 | Priority: $PRIORITY |
b761356f DK |
254 | Maintainer: Joe Sixpack <joe@example.org> |
255 | Standards-Version: 3.9.1 | |
256 | ||
875bcb36 DK |
257 | Package: $NAME" > ${BUILDDIR}/debian/control |
258 | if [ "$ARCH" = 'all' ]; then | |
259 | echo "Architecture: all" >> ${BUILDDIR}/debian/control | |
260 | else | |
261 | echo "Architecture: any" >> ${BUILDDIR}/debian/control | |
262 | fi | |
b761356f DK |
263 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> ${BUILDDIR}/debian/control |
264 | if [ -z "$DESCRIPTION" ]; then | |
265 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
266 | If you find such a package installed on your system, | |
267 | YOU did something horribly wrong! They are autogenerated | |
268 | und used only by testcases for APT and surf no other propose…" >> ${BUILDDIR}/debian/control | |
269 | else | |
270 | echo "Description: $DESCRIPTION" >> ${BUILDIR}/debian/control | |
271 | fi | |
272 | echo '3.0 (native)' > ${BUILDDIR}/debian/source/format | |
273 | local SRCS="$( (cd ${BUILDDIR}/..; dpkg-source -b ${NAME}-${VERSION} 2>&1) | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')" | |
b761356f | 274 | for SRC in $SRCS; do |
5a635ee4 | 275 | echo "pool/${SRC}" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.srclist |
b761356f | 276 | done |
84aa13f4 DK |
277 | |
278 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g'); do | |
279 | rm -rf ${BUILDDIR}/debian/tmp | |
280 | mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin | |
281 | cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} | |
282 | cp ${BUILDDIR}/${NAME} ${BUILDDIR}/debian/tmp/usr/bin/${NAME}-${arch} | |
283 | (cd ${BUILDDIR}; dpkg-gencontrol -DArchitecture=$arch) | |
284 | (cd ${BUILDDIR}/debian/tmp; md5sum $(find usr/ -type f) > DEBIAN/md5sums) | |
285 | ||
286 | dpkg-deb --build ${BUILDDIR}/debian/tmp ${BUILDDIR}/.. 2> /dev/null > /dev/null | |
287 | echo "pool/${NAME}_${VERSION}_${arch}.deb" >> ${BUILDDIR}/../${RELEASE}.${DISTSECTION}.pkglist | |
288 | done | |
289 | ||
13845042 DK |
290 | mkdir -p ${BUILDDIR}/../${NAME}_${VERSION} |
291 | cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}/ | |
292 | cp ${BUILDDIR}/debian/changelog ${BUILDDIR}/../${NAME}_${VERSION}.changelog | |
5a635ee4 | 293 | rm -rf "${BUILDDIR}" |
b761356f | 294 | msgdone "info" |
75954ae2 DK |
295 | } |
296 | ||
297 | buildpackage() { | |
298 | local BUILDDIR=$1 | |
299 | local RELEASE=$2 | |
300 | local SECTION=$3 | |
301 | msgninfo "Build package $(echo "$BUILDDIR" | grep -o '[^/]*$') for ${RELEASE} in ${SECTION}… " | |
302 | cd $BUILDDIR | |
303 | if [ "$ARCH" = "all" ]; then | |
304 | ARCH="$(dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null)" | |
305 | fi | |
b7899b00 DK |
306 | local BUILT="$(dpkg-buildpackage -uc -us -a$ARCH 2> /dev/null)" |
307 | local PKGS="$( echo "$BUILT" | grep '^dpkg-deb: building package' | cut -d'/' -f 2 | sed -e "s#'\.##")" | |
5ed56f93 | 308 | local SRCS="$( echo "$BUILT" | grep '^dpkg-source: info: building' | grep -o '[a-z0-9._+~-]*$')" |
ce9864a8 | 309 | cd - > /dev/null |
b7899b00 | 310 | for PKG in $PKGS; do |
75954ae2 | 311 | echo "pool/${PKG}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.pkglist |
b7899b00 DK |
312 | done |
313 | for SRC in $SRCS; do | |
75954ae2 | 314 | echo "pool/${SRC}" >> ${TMPWORKINGDIRECTORY}/incoming/${RELEASE}.${SECTION}.srclist |
b7899b00 | 315 | done |
cffea9af | 316 | msgdone "info" |
ce9864a8 DK |
317 | } |
318 | ||
319 | buildaptarchive() { | |
ce9864a8 DK |
320 | if [ -d incoming ]; then |
321 | buildaptarchivefromincoming $* | |
322 | else | |
323 | buildaptarchivefromfiles $* | |
324 | fi | |
325 | } | |
326 | ||
327 | createaptftparchiveconfig() { | |
328 | 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' ' ')" | |
158fda31 DK |
329 | if [ -z "$ARCHS" ]; then |
330 | # the pool is empty, so we will operate on faked packages - let us use the configured archs | |
331 | ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')" | |
332 | fi | |
ce9864a8 DK |
333 | echo -n 'Dir { |
334 | ArchiveDir "' >> ftparchive.conf | |
335 | echo -n $(readlink -f .) >> ftparchive.conf | |
336 | echo -n '"; | |
337 | CacheDir "' >> ftparchive.conf | |
338 | echo -n $(readlink -f ..) >> ftparchive.conf | |
339 | echo -n '"; | |
b7899b00 DK |
340 | FileListDir "' >> ftparchive.conf |
341 | echo -n $(readlink -f pool/) >> ftparchive.conf | |
342 | echo -n '"; | |
343 | }; | |
344 | Default { | |
bc33e0f0 DK |
345 | Packages::Compress ". gzip bzip2 lzma xz"; |
346 | Sources::Compress ". gzip bzip2 lzma xz"; | |
347 | Contents::Compress ". gzip bzip2 lzma xz"; | |
b7080ced | 348 | Translation::Compress ". gzip bzip2 lzma xz"; |
18331adf | 349 | LongDescription "false"; |
ce9864a8 DK |
350 | }; |
351 | TreeDefault { | |
352 | Directory "pool/"; | |
353 | SrcDirectory "pool/"; | |
354 | }; | |
355 | APT { | |
356 | FTPArchive { | |
357 | Release { | |
358 | Origin "joesixpack"; | |
359 | Label "apttestcases"; | |
360 | Suite "unstable"; | |
361 | Description "repository with dummy packages"; | |
362 | Architectures "' >> ftparchive.conf | |
363 | echo -n "$ARCHS" >> ftparchive.conf | |
364 | echo 'source"; | |
365 | }; | |
366 | }; | |
367 | };' >> ftparchive.conf | |
b7899b00 DK |
368 | for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do |
369 | echo -n 'tree "dists/' >> ftparchive.conf | |
370 | echo -n "$DIST" >> ftparchive.conf | |
371 | echo -n '" { | |
ce9864a8 DK |
372 | Architectures "' >> ftparchive.conf |
373 | echo -n "$ARCHS" >> ftparchive.conf | |
b7899b00 DK |
374 | echo -n 'source"; |
375 | FileList "' >> ftparchive.conf | |
376 | echo -n "${DIST}.\$(SECTION).pkglist" >> ftparchive.conf | |
377 | echo -n '"; | |
378 | SourceFileList "' >> ftparchive.conf | |
379 | echo -n "${DIST}.\$(SECTION).srclist" >> ftparchive.conf | |
380 | echo -n '"; | |
381 | Sections "' >> ftparchive.conf | |
382 | echo -n "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')" >> ftparchive.conf | |
383 | echo '"; | |
ce9864a8 | 384 | };' >> ftparchive.conf |
b7899b00 | 385 | done |
ce9864a8 DK |
386 | } |
387 | ||
388 | buildaptftparchivedirectorystructure() { | |
b7899b00 DK |
389 | local DISTS="$(grep -i '^tree ' ftparchive.conf | cut -d'/' -f 2 | sed -e 's#".*##')" |
390 | for DIST in $DISTS; do | |
391 | local SECTIONS="$(grep -i -A 5 "dists/$DIST" ftparchive.conf | grep -i 'Sections' | cut -d'"' -f 2)" | |
392 | for SECTION in $SECTIONS; do | |
393 | local ARCHS="$(grep -A 5 "dists/$DIST" ftparchive.conf | grep Architectures | cut -d'"' -f 2 | sed -e 's#source##')" | |
394 | for ARCH in $ARCHS; do | |
395 | mkdir -p dists/${DIST}/${SECTION}/binary-${ARCH} | |
396 | done | |
397 | mkdir -p dists/${DIST}/${SECTION}/source | |
398 | mkdir -p dists/${DIST}/${SECTION}/i18n | |
399 | done | |
ce9864a8 | 400 | done |
ce9864a8 DK |
401 | } |
402 | ||
9b78cda6 DK |
403 | insertpackage() { |
404 | local RELEASE="$1" | |
405 | local NAME="$2" | |
406 | local ARCH="$3" | |
407 | local VERSION="$4" | |
408 | local DEPENDENCIES="$5" | |
d67004e0 DK |
409 | local PRIORITY="${6:-optional}" |
410 | local ARCHS="" | |
411 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g'); do | |
412 | if [ "$arch" = "all" ]; then | |
413 | ARCHS="$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')" | |
414 | else | |
415 | ARCHS="$arch" | |
416 | fi | |
417 | for BUILDARCH in $ARCHS; do | |
418 | local PPATH="aptarchive/dists/${RELEASE}/main/binary-${BUILDARCH}" | |
419 | mkdir -p $PPATH aptarchive/dists/${RELEASE}/main/source | |
420 | touch aptarchive/dists/${RELEASE}/main/source/Sources | |
421 | local FILE="${PPATH}/Packages" | |
422 | echo "Package: $NAME | |
423 | Priority: $PRIORITY | |
9b78cda6 | 424 | Section: other |
2c085486 | 425 | Installed-Size: 42 |
9b78cda6 | 426 | Maintainer: Joe Sixpack <joe@example.org> |
d67004e0 | 427 | Architecture: $arch |
2c085486 | 428 | Version: $VERSION |
d67004e0 DK |
429 | Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE |
430 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE | |
431 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE} | |
9b78cda6 DK |
432 | If you find such a package installed on your system, |
433 | YOU did something horribly wrong! They are autogenerated | |
434 | und used only by testcases for APT and surf no other propose… | |
435 | " >> $FILE | |
d67004e0 | 436 | done |
9b78cda6 DK |
437 | done |
438 | } | |
439 | ||
234675b7 DK |
440 | insertsource() { |
441 | local RELEASE="$1" | |
442 | local NAME="$2" | |
443 | local ARCH="$3" | |
444 | local VERSION="$4" | |
445 | local DEPENDENCIES="$5" | |
446 | local ARCHS="" | |
447 | local SPATH="aptarchive/dists/${RELEASE}/main/source" | |
448 | mkdir -p $SPATH | |
449 | local FILE="${SPATH}/Sources" | |
450 | echo "Package: $NAME | |
451 | Binary: $NAME | |
452 | Version: $VERSION | |
453 | Maintainer: Joe Sixpack <joe@example.org> | |
454 | Architecture: $ARCH" >> $FILE | |
455 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE | |
456 | echo "Files: | |
457 | d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.dsc | |
458 | d41d8cd98f00b204e9800998ecf8427e 0 ${NAME}_${VERSION}.tar.gz" >> $FILE | |
459 | } | |
460 | ||
dfc2b1be DK |
461 | insertinstalledpackage() { |
462 | local NAME="$1" | |
463 | local ARCH="$2" | |
464 | local VERSION="$3" | |
465 | local DEPENDENCIES="$4" | |
d67004e0 | 466 | local PRIORITY="${5:-optional}" |
dfc2b1be | 467 | local FILE="rootdir/var/lib/dpkg/status" |
d67004e0 DK |
468 | for arch in $(echo "$ARCH" | sed -e 's#,#\n#g'); do |
469 | echo "Package: $NAME | |
dfc2b1be | 470 | Status: install ok installed |
d67004e0 | 471 | Priority: $PRIORITY |
dfc2b1be DK |
472 | Section: other |
473 | Installed-Size: 42 | |
474 | Maintainer: Joe Sixpack <joe@example.org> | |
d67004e0 | 475 | Architecture: $arch |
dfc2b1be | 476 | Version: $VERSION" >> $FILE |
d67004e0 DK |
477 | test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE |
478 | echo "Description: an autogenerated dummy ${NAME}=${VERSION}/installed | |
dfc2b1be DK |
479 | If you find such a package installed on your system, |
480 | YOU did something horribly wrong! They are autogenerated | |
481 | und used only by testcases for APT and surf no other propose… | |
482 | " >> $FILE | |
d67004e0 | 483 | done |
dfc2b1be DK |
484 | } |
485 | ||
486 | ||
ce9864a8 | 487 | buildaptarchivefromincoming() { |
3cbbda3c | 488 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on incoming packages…" |
ce9864a8 DK |
489 | cd aptarchive |
490 | [ -e pool ] || ln -s ../incoming pool | |
491 | [ -e ftparchive.conf ] || createaptftparchiveconfig | |
492 | [ -e dists ] || buildaptftparchivedirectorystructure | |
b7899b00 | 493 | msgninfo "\tGenerate Packages, Sources and Contents files… " |
ce9864a8 | 494 | aptftparchive -qq generate ftparchive.conf |
ce9864a8 DK |
495 | cd - > /dev/null |
496 | msgdone "info" | |
9b78cda6 | 497 | generatereleasefiles |
ce9864a8 DK |
498 | } |
499 | ||
500 | buildaptarchivefromfiles() { | |
3cbbda3c | 501 | msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…" |
9b78cda6 DK |
502 | find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do |
503 | msgninfo "\t${line} file… " | |
504 | cat ${line} | gzip > ${line}.gz | |
505 | cat ${line} | bzip2 > ${line}.bz2 | |
506 | cat ${line} | lzma > ${line}.lzma | |
b7080ced | 507 | cat ${line} | xz > ${line}.xz |
8d876415 | 508 | msgdone "info" |
9b78cda6 DK |
509 | done |
510 | generatereleasefiles | |
511 | } | |
512 | ||
a3bbbab7 DK |
513 | # can be overridden by testcases for their pleasure |
514 | getcodenamefromsuite() { echo -n "$1"; } | |
515 | getreleaseversionfromsuite() { true; } | |
516 | ||
9b78cda6 | 517 | generatereleasefiles() { |
884a4c0a DK |
518 | # $1 is the Date header and $2 is the ValidUntil header to be set |
519 | # both should be given in notation date/touch can understand | |
9b78cda6 DK |
520 | msgninfo "\tGenerate Release files… " |
521 | if [ -e aptarchive/dists ]; then | |
18331adf DK |
522 | for dir in $(find ./aptarchive/dists -mindepth 3 -maxdepth 3 -type d -name 'i18n'); do |
523 | aptftparchive -qq release $dir -o APT::FTPArchive::Release::Patterns::='Translation-*' > $dir/Index | |
524 | done | |
9b78cda6 | 525 | for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do |
a3bbbab7 DK |
526 | local SUITE="$(echo "$dir" | cut -d'/' -f 4)" |
527 | local CODENAME="$(getcodenamefromsuite $SUITE)" | |
528 | local VERSION="$(getreleaseversionfromsuite $SUITE)" | |
884a4c0a DK |
529 | if [ -n "$VERSION" ]; then |
530 | VERSION="-o APT::FTPArchive::Release::Version='${VERSION}'" | |
a3bbbab7 | 531 | fi |
884a4c0a DK |
532 | aptftparchive -qq release $dir \ |
533 | -o APT::FTPArchive::Release::Suite="${SUITE}" \ | |
534 | -o APT::FTPArchive::Release::Codename="${CODENAME}" \ | |
535 | -o APT::FTPArchive::Release::Label="Testcases" \ | |
536 | ${VERSION} \ | |
537 | | sed -e '/0 Release$/ d' > $dir/Release # remove the self reference | |
a3bbbab7 | 538 | if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then |
35faae11 DK |
539 | sed -i '/^Date: / a\ |
540 | NotAutomatic: yes' $dir/Release | |
541 | fi | |
884a4c0a DK |
542 | if [ -n "$1" -a "$1" != "now" ]; then |
543 | sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" $dir/Release | |
544 | fi | |
545 | if [ -n "$2" ]; then | |
546 | sed -i "/^Date: / a\ | |
547 | Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $dir/Release | |
548 | fi | |
9b78cda6 DK |
549 | done |
550 | else | |
551 | aptftparchive -qq release ./aptarchive | sed -e '/0 Release$/ d' > aptarchive/Release # remove the self reference | |
8d876415 | 552 | fi |
884a4c0a | 553 | if [ -n "$1" -a "$1" != "now" ]; then |
fe0f7911 DK |
554 | for release in $(find ./aptarchive -name 'Release'); do |
555 | touch -d "$1" $release | |
556 | done | |
8d876415 | 557 | fi |
b7899b00 | 558 | msgdone "info" |
8d876415 DK |
559 | } |
560 | ||
b7899b00 DK |
561 | setupdistsaptarchive() { |
562 | local APTARCHIVE=$(readlink -f ./aptarchive) | |
563 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb.list | |
564 | rm -f root/etc/apt/sources.list.d/apt-test-*-deb-src.list | |
565 | for DISTS in $(find ./aptarchive/dists/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 4); do | |
566 | SECTIONS=$(find ./aptarchive/dists/${DISTS}/ -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f 5 | tr '\n' ' ') | |
567 | msgninfo "\tadd deb and deb-src sources.list lines for ${CCMD}${DISTS} ${SECTIONS}${CINFO}… " | |
568 | echo "deb file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb.list | |
569 | echo "deb-src file://$APTARCHIVE $DISTS $SECTIONS" > rootdir/etc/apt/sources.list.d/apt-test-${DISTS}-deb-src.list | |
570 | msgdone "info" | |
571 | done | |
572 | } | |
573 | ||
574 | setupflataptarchive() { | |
ce9864a8 | 575 | local APTARCHIVE=$(readlink -f ./aptarchive) |
8d876415 DK |
576 | if [ -f ${APTARCHIVE}/Packages ]; then |
577 | msgninfo "\tadd deb sources.list line… " | |
578 | echo "deb file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
579 | msgdone "info" | |
580 | else | |
581 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
582 | fi | |
583 | if [ -f ${APTARCHIVE}/Sources ]; then | |
584 | msgninfo "\tadd deb-src sources.list line… " | |
585 | echo "deb-src file://$APTARCHIVE /" > rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
586 | msgdone "info" | |
587 | else | |
588 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
589 | fi | |
b7899b00 DK |
590 | } |
591 | ||
592 | setupaptarchive() { | |
593 | buildaptarchive | |
594 | if [ -e aptarchive/dists ]; then | |
595 | setupdistsaptarchive | |
596 | else | |
597 | setupflataptarchive | |
598 | fi | |
f213b6ea | 599 | signreleasefiles |
cd725954 | 600 | msgninfo "\tSync APT's cache with the archive… " |
8d876415 | 601 | aptget update -qq |
cd725954 | 602 | msgdone "info" |
8d876415 DK |
603 | } |
604 | ||
f213b6ea DK |
605 | signreleasefiles() { |
606 | local SIGNER="${1:-Joe Sixpack}" | |
607 | msgninfo "\tSign archive with $SIGNER key… " | |
608 | local SECKEYS="" | |
609 | for KEY in $(find keys/ -name '*.sec'); do | |
610 | SECKEYS="$SECKEYS --secret-keyring $KEY" | |
611 | done | |
612 | local PUBKEYS="" | |
613 | for KEY in $(find keys/ -name '*.pub'); do | |
614 | PUBKEYS="$PUBKEYS --keyring $KEY" | |
615 | done | |
616 | for RELEASE in $(find aptarchive/ -name Release); do | |
617 | gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE} | |
fe0f7911 | 618 | gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE |
f213b6ea DK |
619 | done |
620 | msgdone "info" | |
621 | } | |
622 | ||
623 | changetowebserver() { | |
624 | if which weborf > /dev/null; then | |
625 | weborf -xb aptarchive/ 2>&1 > /dev/null & | |
b720d0bd | 626 | addtrap "kill $!;" |
6e7d39d0 DK |
627 | elif which gatling > /dev/null; then |
628 | cd aptarchive | |
629 | gatling -p 8080 -F -S 2>&1 > /dev/null & | |
630 | addtrap "kill $!;" | |
631 | cd - > /dev/null | |
c5bcc607 DK |
632 | elif which lighttpd > /dev/null; then |
633 | echo "server.document-root = \"$(readlink -f ./aptarchive)\" | |
634 | server.port = 8080 | |
635 | server.stat-cache-engine = \"disable\"" > lighttpd.conf | |
636 | lighttpd -t -f lighttpd.conf >/dev/null || msgdie 'Can not change to webserver: our lighttpd config is invalid' | |
637 | lighttpd -D -f lighttpd.conf 2>/dev/null >/dev/null & | |
638 | addtrap "kill $!;" | |
639 | else | |
640 | msgdie 'You have to install weborf or lighttpd first' | |
641 | return 1 | |
f213b6ea | 642 | fi |
c5bcc607 DK |
643 | local APTARCHIVE="file://$(readlink -f ./aptarchive)" |
644 | for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do | |
645 | sed -i $LIST -e "s#$APTARCHIVE#http://localhost:8080/#" | |
646 | done | |
647 | return 0 | |
f213b6ea DK |
648 | } |
649 | ||
650 | checkdiff() { | |
8d876415 DK |
651 | local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" |
652 | if [ -n "$DIFFTEXT" ]; then | |
653 | echo | |
654 | echo "$DIFFTEXT" | |
655 | return 1 | |
656 | else | |
657 | return 0 | |
658 | fi | |
659 | } | |
660 | ||
75954ae2 DK |
661 | testfileequal() { |
662 | local FILE="$1" | |
663 | shift | |
664 | msgtest "Test for correctness of file" "$FILE" | |
665 | if [ -z "$*" ]; then | |
f213b6ea | 666 | echo -n "" | checkdiff $FILE - && msgpass || msgfail |
75954ae2 | 667 | else |
f213b6ea | 668 | echo "$*" | checkdiff $FILE - && msgpass || msgfail |
75954ae2 DK |
669 | fi |
670 | } | |
671 | ||
8d876415 DK |
672 | testequal() { |
673 | local COMPAREFILE=$(mktemp) | |
b720d0bd | 674 | addtrap "rm $COMPAREFILE;" |
8d876415 DK |
675 | echo "$1" > $COMPAREFILE |
676 | shift | |
677 | msgtest "Test for equality of" "$*" | |
f213b6ea | 678 | $* 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail |
8d876415 DK |
679 | } |
680 | ||
685625bd DK |
681 | testequalor2() { |
682 | local COMPAREFILE1=$(mktemp) | |
683 | local COMPAREFILE2=$(mktemp) | |
684 | local COMPAREAGAINST=$(mktemp) | |
b720d0bd | 685 | addtrap "rm $COMPAREFILE1 $COMPAREFILE2 $COMPAREAGAINST;" |
685625bd DK |
686 | echo "$1" > $COMPAREFILE1 |
687 | echo "$2" > $COMPAREFILE2 | |
688 | shift 2 | |
689 | msgtest "Test for equality OR of" "$*" | |
690 | $* 2>&1 1> $COMPAREAGAINST | |
f213b6ea DK |
691 | (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || |
692 | checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass || | |
693 | ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \ | |
694 | "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" && | |
685625bd DK |
695 | msgfail ) |
696 | } | |
697 | ||
8d876415 | 698 | testshowvirtual() { |
edc0ef10 | 699 | local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
700 | local PACKAGE="$1" |
701 | shift | |
702 | while [ -n "$1" ]; do | |
703 | VIRTUAL="${VIRTUAL} | |
edc0ef10 | 704 | N: Can't select versions from package '$1' as it is purely virtual" |
8d876415 DK |
705 | PACKAGE="${PACKAGE} $1" |
706 | shift | |
707 | done | |
708 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
709 | VIRTUAL="${VIRTUAL} | |
4bec02c2 | 710 | N: No packages found" |
8d876415 | 711 | local COMPAREFILE=$(mktemp) |
b720d0bd | 712 | addtrap "rm $COMPAREFILE;" |
8d876415 DK |
713 | local ARCH=$(dpkg-architecture -qDEB_HOST_ARCH_CPU) |
714 | eval `apt-config shell ARCH APT::Architecture` | |
715 | echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE | |
e8379ba3 | 716 | aptcache show -q=0 $PACKAGE 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail |
8d876415 DK |
717 | } |
718 | ||
719 | testnopackage() { | |
720 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
721 | local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" | |
722 | if [ -n "$SHOWPKG" ]; then | |
723 | echo | |
724 | echo "$SHOWPKG" | |
725 | msgfail | |
726 | return 1 | |
727 | fi | |
728 | msgpass | |
729 | } | |
01a6e24c DK |
730 | |
731 | testdpkginstalled() { | |
732 | msgtest "Test for correctly installed package(s) with" "dpkg -l $*" | |
87bc1c45 DK |
733 | local PKGS="$(dpkg -l $* | grep '^i' | wc -l)" |
734 | if [ "$PKGS" != $# ]; then | |
01a6e24c DK |
735 | echo $PKGS |
736 | dpkg -l $* | grep '^[a-z]' | |
737 | msgfail | |
738 | return 1 | |
739 | fi | |
740 | msgpass | |
741 | } | |
742 | ||
5cf733e1 DK |
743 | testdpkgnotinstalled() { |
744 | msgtest "Test for correctly not-installed package(s) with" "dpkg -l $*" | |
87bc1c45 | 745 | local PKGS="$(dpkg -l $* 2> /dev/null | grep '^i' | wc -l)" |
01a6e24c DK |
746 | if [ "$PKGS" != 0 ]; then |
747 | echo | |
748 | dpkg -l $* | grep '^[a-z]' | |
749 | msgfail | |
750 | return 1 | |
751 | fi | |
752 | msgpass | |
753 | } | |
ec7f904e DK |
754 | |
755 | testmarkedauto() { | |
756 | local COMPAREFILE=$(mktemp) | |
757 | addtrap "rm $COMPAREFILE;" | |
758 | if [ -n "$1" ]; then | |
759 | msgtest 'Test for correctly marked as auto-installed' "$*" | |
760 | while [ -n "$1" ]; do echo "$1"; shift; done | sort > $COMPAREFILE | |
761 | else | |
762 | msgtest 'Test for correctly marked as auto-installed' 'no package' | |
c98fb5e0 | 763 | echo -n > $COMPAREFILE |
ec7f904e DK |
764 | fi |
765 | aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail | |
766 | } | |
89a1aa5d DK |
767 | |
768 | pause() { | |
769 | echo "STOPPED execution. Press enter to continue" | |
770 | local IGNORE | |
771 | read IGNORE | |
772 | } |