]>
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) | |
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 | |
55 | cd rootdir | |
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 | |
59 | mkdir -p usr/lib/apt | |
60 | ln -s ${BUILDDIRECTORY}/methods usr/lib/apt/methods | |
61 | cd .. | |
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 | |
65 | export LC_ALL=C | |
66 | msgdone "info" | |
67 | } | |
68 | ||
69 | configarchitecture() { | |
70 | local CONFFILE=rootdir/etc/apt/apt.conf.d/01multiarch.conf | |
71 | echo "APT::Architecture \"$1\";" > $CONFFILE | |
72 | shift | |
73 | while [ -n "$1" ]; do | |
74 | echo "APT::Architectures:: \"$1\";" >> $CONFFILE | |
75 | shift | |
76 | done | |
77 | } | |
78 | ||
79 | buildflataptarchive() { | |
80 | msginfo "Build APT archive for ${CCMD}$0${CINFO}…" | |
81 | cd aptarchive | |
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 | |
88 | msgdone "info" | |
89 | fi | |
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 | |
95 | msgdone "info" | |
96 | fi | |
97 | cd .. | |
98 | aptftparchive release . > Release | |
99 | } | |
100 | ||
101 | setupflataptarchive() { | |
102 | buildflataptarchive | |
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 | |
107 | msgdone "info" | |
108 | else | |
109 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb.list | |
110 | fi | |
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 | |
114 | msgdone "info" | |
115 | else | |
116 | rm -f rootdir/etc/apt/sources.list.d/apt-test-archive-deb-src.list | |
117 | fi | |
118 | aptget update -qq | |
119 | } | |
120 | ||
121 | diff() { | |
122 | local DIFFTEXT="$($(which diff) -u $* | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" | |
123 | if [ -n "$DIFFTEXT" ]; then | |
124 | echo | |
125 | echo "$DIFFTEXT" | |
126 | return 1 | |
127 | else | |
128 | return 0 | |
129 | fi | |
130 | } | |
131 | ||
132 | testequal() { | |
133 | local COMPAREFILE=$(mktemp) | |
134 | echo "$1" > $COMPAREFILE | |
135 | shift | |
136 | msgtest "Test for equality of" "$*" | |
137 | $* 2>&1 | diff $COMPAREFILE - && msgpass || msgfail | |
138 | } | |
139 | ||
140 | testshowvirtual() { | |
141 | local VIRTUAL="E: Can't select versions from package '$1' as it purely virtual" | |
142 | local PACKAGE="$1" | |
143 | shift | |
144 | while [ -n "$1" ]; do | |
145 | VIRTUAL="${VIRTUAL} | |
146 | E: Can't select versions from package '$1' as it purely virtual" | |
147 | PACKAGE="${PACKAGE} $1" | |
148 | shift | |
149 | done | |
150 | msgtest "Test for virtual packages" "apt-cache show $PACKAGE" | |
151 | VIRTUAL="${VIRTUAL} | |
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 | |
158 | } | |
159 | ||
160 | testnopackage() { | |
161 | msgtest "Test for non-existent packages" "apt-cache show $*" | |
162 | local SHOWPKG="$(aptcache show $* 2>&1 | grep '^Package: ')" | |
163 | if [ -n "$SHOWPKG" ]; then | |
164 | echo | |
165 | echo "$SHOWPKG" | |
166 | msgfail | |
167 | return 1 | |
168 | fi | |
169 | msgpass | |
170 | } |