Add in the mess from the original symbiosisware version.
[distorted-chroot] / mess / config / schroot / scripts / 15binfmt
CommitLineData
fd0f20e1
MW
1#!/bin/sh
2# Copyright © 2011 Julian Andres Klode <jak@debian.org>
3#
4# schroot is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# schroot is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12# General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see
16# <http://www.gnu.org/licenses/>.
17#
18#####################################################################
19
20set -e
21
22. "$SETUP_DATA_DIR/common-data"
23. "$SETUP_DATA_DIR/common-functions"
24. "$SETUP_DATA_DIR/common-config"
25
26
27if [ "$STAGE" != "setup-start" ] && \
28 [ "$STAGE" != "setup-stop" ] && \
29 [ "$STAGE" != "setup-recover" ]; then
30 exit 0
31elif ! which update-binfmts > /dev/null 2>&1; then
32 info "Missing update-binfmts; not enabling binfmt support"
33 exit 0
34fi
35
36shell="${CHROOT_PATH}/bin/sh"
37
38for emulator in $(update-binfmts --find "$shell"); do
39 dst="${CHROOT_PATH}$emulator"
40 if [ ! -e "$emulator" ]; then
41 info "Missing emulator: $emulator; not enabling binfmt support"
42 elif [ ! -e "$dst" ]; then
43 ## [mdw] don't bind over an existing qemu. Two things go wrong:
44 ## firstly, and more obviously, this forces the use of the host qemu,
45 ## which may be too old to run more bleeding-edge code; and secondly,
46 ## if the chroot's emulator is a symlink to a file in the host
47 ## filesystem to be bound into the chroot, then this bind mount is
48 ## never cleaned up. It's just a bad idea.
49 touch "$dst"
50 mount --bind "$emulator" "$dst"
51 mount -o remount,ro,bind "$dst"
52 fi
53done