#!/bin/sh # # Mono via BINFMT_MISC # # Author: Adam Drzewiecki # e-mail: A.Drzewiecki@ztpnet.pl # Last modified: 13 Dec 2008 # # BINMFT_MISC config directory CONF_DIR="/proc/sys/fs/binfmt_misc" # Executable type name NAME="mono" # Interpreter filename INTERPRETER="mono" # Searching for interpreter mono_location() { if [ -x "/usr/local/bin/$INTERPRETER" ] ; then MONO="/usr/local/bin/$INTERPRETER" elif [ -x "/usr/bin/$INTERPRETER" ] ; then MONO="/usr/bin/$INTERPRETER" elif [ -x "/bin/$INTERPRETER" ] ; then MONO="/bin/$INTERPRETER" else echo "no interpreter found" exit -1 fi } # BINFMT_MISC initialization prepare_binfmt_misc() { if grep -qs binfmt_misc /proc/filesystems || modprobe binfmt_misc >/dev/null 2>&1 ; then if ! grep -qs binfmt_misc /proc/mounts && \ ! mount binfmt_misc -t binfmt_misc $CONF_DIR >/dev/null 2>&1; then echo "BINFMT_MISC can't be mounted" exit -1 fi else echo "BINFMT_MISC is not compiled in kernel" exit -1 fi } # Attempt to unload BINFMT_MISC module remove_binfmt_misc() { if lsmod | grep -qs binfmt_misc ; then if grep -qs binfmt_misc /proc/mounts && umount $CONF_DIR >/dev/null 2>&1 ; then rmmod binfmt_misc >/dev/null 2>&1 fi fi } # Setup environment for Mono mono_start() { echo -n "Preparing environment for Mono: " prepare_binfmt_misc mono_location if [ ! -e "$CONF_DIR/$NAME" ] ; then if echo ":$NAME:M::MZ::$MONO:" > $CONF_DIR/register 2>/dev/null ; then echo "success (interpreter: $MONO, version $($MONO --version | head -n 1 | tr '\ ' '\n' | grep ^[0-9]))" else echo "registering error" fi else echo "Mono already registered" fi } # Cleanup environment mono_stop() { echo -n "Shutting down environment for Mono: " if [ -e "$CONF_DIR/$NAME" ] && echo "-1" >$CONF_DIR/$NAME 2>/dev/null ; then echo "done" else echo "failed" fi remove_binfmt_misc } # # int main() # case "$1" in start) mono_start ;; stop) mono_stop ;; restart) mono_stop mono_start ;; *) echo "usage: $(basename $0) start|stop|restart" ;; esac