]>
Commit | Line | Data |
---|---|---|
d151adbf DK |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
4 | TESTDIR=$(readlink -f $(dirname $0)) | |
5 | . $TESTDIR/framework | |
6 | ||
7 | setupenvironment | |
8 | configarchitecture 'native' | |
9 | ||
10 | # create a bunch of failures | |
11 | createfailure() { | |
12 | setupsimplenativepackage "failure-$1" 'native' '1.0' 'unstable' 'Depends: dependee' | |
13 | BUILDDIR="incoming/failure-$1-1.0" | |
14 | echo '#!/bin/sh | |
15 | exit 29' > ${BUILDDIR}/debian/$1 | |
16 | buildpackage "$BUILDDIR" 'unstable' 'main' 'native' | |
17 | rm -rf "$BUILDDIR" | |
18 | } | |
19 | ||
20 | buildsimplenativepackage 'dependee' 'native' '1.0' 'unstable' | |
21 | createfailure 'preinst' | |
22 | createfailure 'postinst' | |
23 | createfailure 'prerm' | |
24 | createfailure 'postrm' | |
25 | ||
26 | setupaptarchive | |
27 | ||
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 | |
32 | #define _GNU_SOURCE | |
33 | #include <stdio.h> | |
34 | #include <stdlib.h> | |
35 | #include <string.h> | |
36 | #include <dlfcn.h> | |
37 | ||
38 | static char * chrootdir = NULL; | |
39 | ||
40 | int chroot(const char *path) { | |
41 | printf("WARNING: CHROOTing to %s was ignored!\n", path); | |
42 | free(chrootdir); | |
43 | chrootdir = strdup(path); | |
44 | return 0; | |
45 | } | |
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); | |
57 | } | |
58 | EOF | |
59 | testsuccess gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl | |
60 | ||
61 | mkdir -p "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/" | |
62 | DPKG="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" | |
63 | echo "#!/bin/sh | |
64 | if [ -n \"\$LD_PRELOAD\" ]; then | |
65 | export LD_PRELOAD=\"${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}\" | |
66 | else | |
67 | export LD_PRELOAD=\"${TMPWORKINGDIRECTORY}/noopchroot.so\" | |
68 | fi | |
69 | dpkg \"\$@\"" > $DPKG | |
70 | chmod +x $DPKG | |
71 | sed -ie "s|^DPKG::options:: \"dpkg\";\$|DPKG::options:: \"$DPKG\";|" aptconfig.conf | |
72 | ||
73 | # setup some pre- and post- invokes to check the output isn't garbled later | |
74 | APTHOOK="${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apthook" | |
75 | echo '#!/bin/sh | |
76 | echo "$1: START" | |
77 | echo "$1: MaiN" | |
78 | echo "$1: ENd"' > $APTHOOK | |
79 | chmod +x $APTHOOK | |
80 | echo "DPKG::Pre-Invoke:: \"${APTHOOK} PRE\"; | |
81 | DPKG::Post-Invoke:: \"${APTHOOK} POST\";" > rootdir/etc/apt/apt.conf.d/99apthooks | |
82 | ||
83 | testmyfailure() { | |
84 | local PROGRESS='rootdir/tmp/progress.log' | |
85 | exec 3> $PROGRESS | |
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 | |
90 | msgpass | |
91 | else | |
92 | cat $TEST | |
93 | msgfail | |
94 | fi | |
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 | |
102 | msgpass | |
103 | else | |
104 | cat $TEST | |
105 | msgfail | |
106 | fi | |
107 | msgtest 'Test for failure message of maintainerscript in' 'progress log' | |
108 | if grep -q '^pmerror:.\+exit status 29$' "$PROGRESS"; then | |
109 | msgpass | |
110 | else | |
111 | cat $PROGRESS | |
112 | msgfail | |
113 | fi | |
114 | testmarkedauto 'dependee' | |
115 | } | |
116 | ||
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 | |
129 | ||
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 |