| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
# Copyright (C) 2010, 2011 Colin Watson. |
| 4 |
# |
| 5 |
# This file is part of binfmt-support. |
| 6 |
# |
| 7 |
# binfmt-support is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by the |
| 9 |
# Free Software Foundation; either version 3 of the License, or (at your |
| 10 |
# option) any later version. |
| 11 |
# |
| 12 |
# binfmt-support is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
| 15 |
# Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License along |
| 18 |
# with binfmt-support; if not, write to the Free Software Foundation, Inc., |
| 19 |
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
|
| 21 |
# Test update-binfmts --display. |
| 22 |
|
| 23 |
: "${srcdir=.}" |
| 24 |
# shellcheck source-path=SCRIPTDIR |
| 25 |
. "$srcdir/testlib.sh" |
| 26 |
|
| 27 |
init |
| 28 |
fake_proc |
| 29 |
|
| 30 |
update_binfmts_proc --install test-magic /bin/sh --magic ABCD |
| 31 |
report 'magic: install' "$?" |
| 32 |
cat >"$tmpdir/1-admin.exp" <<'EOF' |
| 33 |
: |
| 34 |
magic |
| 35 |
0 |
| 36 |
ABCD |
| 37 |
|
| 38 |
/bin/sh |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
EOF |
| 44 |
expect_files_equal 'magic: admindir entry OK' \ |
| 45 |
"$tmpdir/var/lib/binfmts/test-magic" "$tmpdir/1-admin.exp" |
| 46 |
cat >"$tmpdir/1-proc.exp" <<'EOF' |
| 47 |
enabled |
| 48 |
interpreter /bin/sh |
| 49 |
flags: |
| 50 |
offset 0 |
| 51 |
magic 41424344 |
| 52 |
EOF |
| 53 |
expect_files_equal 'magic: procdir entry OK' \ |
| 54 |
"$tmpdir/proc/test-magic" "$tmpdir/1-proc.exp" |
| 55 |
|
| 56 |
update_binfmts_proc \ |
| 57 |
--package testpkg --install test-extension /bin/sh --extension ext |
| 58 |
report 'extension with package: install' "$?" |
| 59 |
cat >"$tmpdir/2-admin.exp" <<'EOF' |
| 60 |
testpkg |
| 61 |
extension |
| 62 |
0 |
| 63 |
ext |
| 64 |
|
| 65 |
/bin/sh |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
EOF |
| 71 |
expect_files_equal 'extension with package: admindir entry OK' \ |
| 72 |
"$tmpdir/var/lib/binfmts/test-extension" "$tmpdir/2-admin.exp" |
| 73 |
cat >"$tmpdir/2-proc.exp" <<'EOF' |
| 74 |
enabled |
| 75 |
interpreter /bin/sh |
| 76 |
flags: |
| 77 |
extension .ext |
| 78 |
EOF |
| 79 |
expect_files_equal 'extension with package: procdir entry OK' \ |
| 80 |
"$tmpdir/proc/test-extension" "$tmpdir/2-proc.exp" |
| 81 |
|
| 82 |
cat >"$tmpdir/1-display.exp" <<'EOF' |
| 83 |
test-magic (enabled): |
| 84 |
package = <local> |
| 85 |
type = magic |
| 86 |
offset = 0 |
| 87 |
magic = ABCD |
| 88 |
mask = |
| 89 |
interpreter = /bin/sh |
| 90 |
detector = |
| 91 |
EOF |
| 92 |
update_binfmts_proc --display test-magic | diff -u - "$tmpdir/1-display.exp" |
| 93 |
report 'magic: display OK' "$?" |
| 94 |
|
| 95 |
cat >"$tmpdir/2-display.exp" <<'EOF' |
| 96 |
test-extension (enabled): |
| 97 |
package = testpkg |
| 98 |
type = extension |
| 99 |
offset = 0 |
| 100 |
magic = ext |
| 101 |
mask = |
| 102 |
interpreter = /bin/sh |
| 103 |
detector = |
| 104 |
EOF |
| 105 |
update_binfmts_proc \ |
| 106 |
--display test-extension | diff -u - "$tmpdir/2-display.exp" |
| 107 |
report 'extension with package: display OK' "$?" |
| 108 |
|
| 109 |
update_binfmts_proc --display nonexistent 2>/dev/null |
| 110 |
test "$?" = 2 |
| 111 |
report 'nonexistent entry: display exit code OK' "$?" |
| 112 |
|
| 113 |
finish |