render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone
David Woodhouse 5c3734
#!/bin/sh
David Woodhouse 5c3734
#
David Woodhouse 5c3734
# qemu	Allow users to run non-native Linux programs by just clicking on them
David Woodhouse 5c3734
#	(or typing ./file.exe)
David Woodhouse 5c3734
#
David Woodhouse 5c3734
# chkconfig: 2345 35 98
David Woodhouse 5c3734
# description: Allow users to run non-native Linux programs by just clicking \
David Woodhouse 5c3734
#	       on them (or typing ./file.exe)
David Woodhouse 5c3734
David Woodhouse 5c3734
. /etc/rc.d/init.d/functions
David Woodhouse 5c3734
RETVAL=0
David Woodhouse 5c3734
QEMU=/usr/bin
David Woodhouse 5c3734
David Woodhouse 5c3734
start() {
David Woodhouse 5c3734
	cpu=`uname -m`
David Woodhouse 5c3734
        case "$cpu" in
David Woodhouse 5c3734
	    i386|i486|i586|i686|i86pc|BePC)
David Woodhouse 5c3734
		cpu="i386"
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	    "Power Macintosh"|ppc|ppc64)
David Woodhouse 5c3734
		cpu="ppc"
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	    armv4l|armv5l)
David Woodhouse 5c3734
		cpu="arm"
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	esac
David Woodhouse 5c3734
David Woodhouse 5c3734
	echo -n $"Registering binary handler for qemu applications"
David Woodhouse 5c3734
	/sbin/modprobe binfmt_misc &>/dev/null
David Woodhouse 5c3734
	if [ "$cpu" != i386 -a -x $QEMU/qemu-i386 -a -d /usr/qemu-i386 ] ; then
David Woodhouse 5c3734
	    echo ":qemu-i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:$QEMU/qemu-i386:" > /proc/sys/fs/binfmt_misc/register
David Woodhouse 5c3734
	    echo ":qemu-i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:$QEMU/qemu-i386:" > /proc/sys/fs/binfmt_misc/register
David Woodhouse 5c3734
	fi
David Woodhouse 5c3734
	if [ "$cpu" != arm -a -x $QEMU/qemu-arm -a -d /usr/qemu-arm ] ; then
David Woodhouse 5c3734
	    echo   ":qemu-arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:$QEMU/qemu-arm:" > /proc/sys/fs/binfmt_misc/register
David Woodhouse 5c3734
	fi
David Woodhouse 5c3734
	if [ "$cpu" != ppc -a -x $QEMU/qemu-ppc -a -d /usr/qemu-ppc ] ; then
David Woodhouse 5c3734
	    echo   ":ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:$QEMU/qemu-ppc:" > /proc/sys/fs/binfmt_misc/register
David Woodhouse 5c3734
	echo do ppc
David Woodhouse 5c3734
	fi
David Woodhouse 5c3734
	if [ "$cpu" != sparc -a -x $QEMU/qemu-sparc -a -d /usr/qemu-sparc ] ; then
David Woodhouse 5c3734
	    echo   ":qemu-sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff\xff:$QEMU/qemu-sparc:" > /proc/sys/fs/binfmt_misc/register
David Woodhouse 5c3734
	fi
David Woodhouse 5c3734
	echo
David Woodhouse 5c3734
}
David Woodhouse 5c3734
David Woodhouse 5c3734
stop() {
David Woodhouse 5c3734
	echo -n $"Unregistering binary handler for qemu applications"
David Woodhouse 5c3734
	for a in i386 i486 ppc arm sparc ] ; do 
David Woodhouse 5c3734
	    [ -r /proc/sys/fs/binfmt_misc/qemu-$a ] && echo "-1" >/proc/sys/fs/binfmt_misc/qemu-$a
David Woodhouse 5c3734
	done
David Woodhouse 5c3734
	echo
David Woodhouse 5c3734
}
David Woodhouse 5c3734
David Woodhouse 5c3734
reload() {
David Woodhouse 5c3734
	stop
David Woodhouse 5c3734
	start
David Woodhouse 5c3734
}
David Woodhouse 5c3734
David Woodhouse 5c3734
qemu_status() {
David Woodhouse 5c3734
	if ls /proc/sys/fs/binfmt_misc/qemu-* &>/dev/null; then 
David Woodhouse 5c3734
		echo $"qemu binary format handlers are registered."
David Woodhouse 5c3734
		return 0
David Woodhouse 5c3734
	else
David Woodhouse 5c3734
		echo $"qemu binary format handlers are not registered."
David Woodhouse 5c3734
		return 3
David Woodhouse 5c3734
	fi
David Woodhouse 5c3734
}
David Woodhouse 5c3734
David Woodhouse 5c3734
case "$1" in
David Woodhouse 5c3734
	start)
David Woodhouse 5c3734
		start
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	stop)
David Woodhouse 5c3734
		stop
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	status)
David Woodhouse 5c3734
		qemu_status
David Woodhouse 5c3734
		RETVAL=$?
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	restart)
David Woodhouse 5c3734
		stop
David Woodhouse 5c3734
		start
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	condrestart)
David Woodhouse 5c3734
		if qemu_status &>/dev/null; then
David Woodhouse 5c3734
			stop
David Woodhouse 5c3734
			start
David Woodhouse 5c3734
		fi
David Woodhouse 5c3734
		;;
David Woodhouse 5c3734
	*)
David Woodhouse 5c3734
		echo $"Usage: $prog {start|stop|status|restart|condrestart}"
David Woodhouse 5c3734
		exit 1
David Woodhouse 5c3734
esac
David Woodhouse 5c3734
exit $RETVAL
David Woodhouse 5c3734