PageRenderTime 227ms CodeModel.GetById 220ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/init.d/binfmt-support

http://github.com/brinkman83/bashrc
Shell | 78 lines | 57 code | 10 blank | 11 comment | 15 complexity | 4ab2f0197ef37462353f8808e22b58ff MD5 | raw file
 1#! /bin/sh
 2### BEGIN INIT INFO
 3# Provides:          binfmt-support
 4# Required-Start:    $local_fs $remote_fs
 5# Required-Stop:     $local_fs $remote_fs
 6# Default-Start:     2 3 4 5
 7# Default-Stop:
 8# Short-Description: Support for extra binary formats
 9# Description:       Enable support for extra binary formats using the Linux
10#                    kernel's binfmt_misc facility.
11### END INIT INFO
12
13PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
14NAME=binfmt-support
15DESC="additional executable binary formats"
16
17if [ "$(uname)" != Linux ]; then
18  exit 0
19fi
20
21which update-binfmts >/dev/null 2>&1 || exit 0
22
23. /lib/lsb/init-functions
24[ -r /etc/default/rcS ] && . /etc/default/rcS
25
26set -e
27CODE=0
28
29case "$1" in
30  start)
31    ADMINDIR=/var/lib/binfmts
32    CACHEDIR=/var/cache/binfmts
33    fmts="$(cd "$ADMINDIR"; ls)" || exit 0
34    [ -z "$fmts" ] && exit 0
35    log_daemon_msg "Enabling $DESC" "$NAME"
36    PROCDIR=/proc/sys/fs/binfmt_misc
37    if [ ! -e "$PROCDIR/register" ]; then
38	if which modprobe >/dev/null 2>&1; then
39	    modprobe -q binfmt_misc || true
40	fi
41	mount -t binfmt_misc -o nodev,noexec,nosuid binfmt_misc "$PROCDIR"
42    fi
43    cachefail=0
44    for fmt in $fmts; do
45	[ -e "$PROCDIR/$fmt" ] && continue
46	if [ ! -e "$CACHEDIR/$fmt" ] ||
47	   ! cat "$CACHEDIR/$fmt" > $PROCDIR/register; then
48	    cachefail=1
49	fi
50	CODE=$?
51    done
52    if [ "$cachefail" = 1 ]; then
53	update-binfmts --enable || CODE=$?
54    fi
55    log_end_msg $CODE
56    exit $CODE
57    ;;
58
59  stop)
60    log_daemon_msg "Disabling $DESC" "$NAME"
61    update-binfmts --disable || CODE=$?
62    log_end_msg $CODE
63    exit $CODE
64    ;;
65
66  restart|force-reload)
67    $0 stop
68    $0 start
69    ;;
70
71  *)
72    N=/etc/init.d/$NAME
73    echo "Usage: $N {start|stop|restart|force-reload}" >&2
74    exit 1
75    ;;
76esac
77
78exit 0