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 msgninfo
"Preparing environment for ${CCMD}$0${CINFO} in ${TMPWORKINGDIRECTORY}… "
49 BUILDDIRECTORY
=$(readlink -f $(dirname $0)/..
/..
/build
/bin
)
50 test -x "${BUILDDIRECTORY}/apt-get" || msgdie
"You need to build tree first"
51 local OLDWORKINGDIRECTORY
=$(pwd)
52 trap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
53 cd $TMPWORKINGDIRECTORY
54 mkdir rootdir aptarchive
56 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
57 mkdir -p var
/cache
/apt
/archives
/partial var
/lib
/apt
/lists
/partial
58 touch var
/lib
/dpkg
/status
60 ln -s ${BUILDDIRECTORY}/methods usr
/lib
/apt
/methods
62 echo "RootDir \"${TMPWORKINGDIRECTORY}/rootdir\";" > aptconfig.conf
63 echo "Debug::NoLocking \"true\";" >> aptconfig.conf
64 echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
69 configarchitecture
() {
70 local CONFFILE
=rootdir
/etc
/apt
/apt.conf.d
/01multiarch.conf
71 echo "APT::Architecture \"$1\";" > $CONFFILE
74 echo "APT::Architectures:: \"$1\";" >> $CONFFILE
79 buildflataptarchive
() {
80 msginfo
"Build APT archive for ${CCMD}$0${CINFO}…"
82 APTARCHIVE
=$(readlink -f .)
83 if [ -f Packages
]; then
84 msgninfo
"\tPackages file… "
85 cat Packages
| gzip > Packages.gz
86 cat Packages
| bzip2 > Packages.bz2
87 cat Packages
| lzma
> Packages.lzma
90 if [ -f Sources
]; then
91 msgninfo
"\tSources file… "
92 cat Sources
| gzip > Sources.gz
93 cat Sources
| bzip2 > Sources.bz2
94 cat Sources
| lzma
> Sources.lzma
98 aptftparchive release .
> Release
101 setupflataptarchive
() {
103 APTARCHIVE
=$(readlink -f ./aptarchive)
104 if [ -f ${APTARCHIVE}/Packages
]; then
105 msgninfo
"\tadd deb sources.list line… "
106 echo "deb file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
109 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb.list
111 if [ -f ${APTARCHIVE}/Sources
]; then
112 msgninfo
"\tadd deb-src sources.list line… "
113 echo "deb-src file://$APTARCHIVE /" > rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
116 rm -f rootdir
/etc
/apt
/sources.list.d
/apt
-test-archive-deb-src.list
122 local DIFFTEXT
="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
123 if [ -n "$DIFFTEXT" ]; then
133 local COMPAREFILE
=$(mktemp)
134 echo "$1" > $COMPAREFILE
136 msgtest
"Test for equality of" "$*"
137 $
* 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
141 local VIRTUAL
="E: Can't select versions from package '$1' as it purely virtual"
144 while [ -n "$1" ]; do
146 E: Can't select versions from package '$1' as it purely virtual"
147 PACKAGE
="${PACKAGE} $1"
150 msgtest
"Test for virtual packages" "apt-cache show $PACKAGE"
152 E: No packages found"
153 local COMPAREFILE
=$(mktemp)
154 local ARCH
=$(dpkg-architecture -qDEB_HOST_ARCH_CPU)
155 eval `apt-config shell ARCH APT::Architecture`
156 echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' > $COMPAREFILE
157 aptcache show
$PACKAGE 2>&1 | diff $COMPAREFILE - && msgpass
|| msgfail
161 msgtest
"Test for non-existent packages" "apt-cache show $*"
162 local SHOWPKG
="$(aptcache show $* 2>&1 | grep '^Package: ')"
163 if [ -n "$SHOWPKG" ]; then