4 TESTDIR
=$(readlink -f $(dirname $0))
8 configarchitecture
'native'
10 # create a bunch of failures
12 setupsimplenativepackage
"failure-$1" 'native' '1.0' 'unstable' 'Depends: dependee'
13 BUILDDIR
="incoming/failure-$1-1.0"
15 exit 29' > ${BUILDDIR}/debian
/$1
16 buildpackage
"$BUILDDIR" 'unstable' 'main' 'native'
20 buildsimplenativepackage
'dependee' 'native' '1.0' 'unstable'
21 createfailure
'preinst'
22 createfailure
'postinst'
24 createfailure
'postrm'
28 # create a library to noop chroot() and rewrite maintainer script executions
29 # via execvp() as used by dpkg as we don't want our rootdir to be a fullblown
30 # chroot directory dpkg could chroot into to execute the maintainer scripts
31 cat << EOF > noopchroot.c
38 static char * chrootdir = NULL;
40 int chroot(const char *path) {
41 printf("WARNING: CHROOTing to %s was ignored!\n", path);
43 chrootdir = strdup(path);
46 int execvp(const char *file, char *const argv[]) {
47 static int (*func_execvp) (const char *, char * const []) = NULL;
48 if (func_execvp == NULL)
49 func_execvp = (int (*) (const char *, char * const [])) dlsym(RTLD_NEXT, "execvp");
50 if (chrootdir == NULL || strncmp(file, "/var/lib/dpkg/", strlen("/var/lib/dpkg/")) != 0)
51 return func_execvp(file, argv);
52 printf("REWRITE execvp call %s into %s\n", file, chrootdir);
53 char newfile[strlen(chrootdir) + strlen(file)];
54 strcpy(newfile, chrootdir);
55 strcat(newfile, file);
56 return func_execvp(newfile, argv);
59 testsuccess gcc
-fPIC -shared -o noopchroot.so noopchroot.c
-ldl
61 mkdir -p "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
62 DPKG
="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
64 if [ -n \"\$LD_PRELOAD\" ]; then
65 export LD_PRELOAD=\"${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}\"
67 export LD_PRELOAD=\"${TMPWORKINGDIRECTORY}/noopchroot.so\"
71 sed -ie "s|^DPKG::options:: \"dpkg\";\$|DPKG::options:: \"$DPKG\";|" aptconfig.conf
73 # setup some pre- and post- invokes to check the output isn't garbled later
74 APTHOOK
="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apthook"
78 echo "$1: ENd"' > $APTHOOK
80 echo "DPKG::Pre-Invoke:: \"${APTHOOK} PRE\";
81 DPKG::Post-Invoke:: \"${APTHOOK} POST\";" > rootdir
/etc
/apt
/apt.conf.d
/99apthooks
84 local PROGRESS
='rootdir/tmp/progress.log'
86 testfailure
"$@" -o APT
::Status
-Fd=3
87 msgtest
'Test for failure message of maintainerscript in' 'console log'
88 local TEST
='rootdir/tmp/testfailure.output'
89 if grep -q 'exit status 29' "$TEST"; then
95 msgtest
'Test for proper execution of invoke scripts in' 'console log'
96 if grep -q '^PRE: START$' $TEST &&
97 grep -q '^PRE: MaiN$' $TEST &&
98 grep -q '^PRE: ENd$' $TEST &&
99 grep -q '^POST: START$' $TEST &&
100 grep -q '^POST: MaiN$' $TEST &&
101 grep -q '^POST: ENd$' $TEST; then
107 msgtest
'Test for failure message of maintainerscript in' 'progress log'
108 if grep -q '^pmerror:.\+exit status 29$' "$PROGRESS"; then
114 testmarkedauto
'dependee'
117 cp -a rootdir
/var
/lib
/dpkg
/status rootdir
/var
/lib
/dpkg
/status.backup
118 testmyfailure aptget
install failure
-preinst -y
119 cp -a rootdir
/var
/lib
/dpkg
/status.backup rootdir
/var
/lib
/dpkg
/status
120 testmyfailure aptget
install failure
-postinst -y
121 cp -a rootdir
/var
/lib
/dpkg
/status.backup rootdir
/var
/lib
/dpkg
/status
122 testsuccess aptget
install failure
-prerm -y
123 testdpkginstalled failure
-prerm
124 testmyfailure aptget purge failure
-prerm -y
125 cp -a rootdir
/var
/lib
/dpkg
/status.backup rootdir
/var
/lib
/dpkg
/status
126 testsuccess aptget
install failure
-postrm -y
127 testdpkginstalled failure
-postrm
128 testmyfailure aptget purge failure
-postrm -y
130 # FIXME: test with output going to a PTY as it usually does
131 #cp -a rootdir/var/lib/dpkg/status.backup rootdir/var/lib/dpkg/status
132 #aptget install failure-preinst -y