e33aa8f
#!/bin/sh
e33aa8f
#
e33aa8f
# wine	Allow users to run Windows(tm) applications by just clicking on them
e33aa8f
#	(or typing ./file.exe)
e33aa8f
#
e33aa8f
# chkconfig: 35 98 10
e33aa8f
# description: Allow users to run Windows(tm) applications by just clicking \
e33aa8f
#	       on them (or typing ./file.exe)
c61ab5b
### BEGIN INIT INFO
30aa51c
# Provides: wine-binfmt
30aa51c
# Required-Start:
30aa51c
# Required-Stop:
c61ab5b
# Default-Start:  2 3 4 5
c61ab5b
# Default-Stop: 0 1 6
30aa51c
# Short-Description: Add and remove wine binary handler
c61ab5b
# Description: Allow users to run Windows(tm) applications by just clicking
c61ab5b
#              on them (or typing ./file.exe)
c61ab5b
### END INIT INFO
c61ab5b
e33aa8f
e33aa8f
. /etc/rc.d/init.d/functions
e33aa8f
RETVAL=0
e33aa8f
e33aa8f
start() {
f7093a5
# fix bug on changing runlevels #213230
f7093a5
	if [ -e /proc/sys/fs/binfmt_misc/windows ]; then
f7093a5
	    echo -n $"Binary handler for Windows applications already registered"
f7093a5
	else	
c61ab5b
	    echo -n $"Registering binary handler for Windows applications: "
f7093a5
	    /sbin/modprobe binfmt_misc &>/dev/null
f7093a5
	    echo ':windows:M::MZ::/usr/bin/wine:' >/proc/sys/fs/binfmt_misc/register || :
f7093a5
	    echo ':windowsPE:M::PE::/usr/bin/wine:' >/proc/sys/fs/binfmt_misc/register || :
c61ab5b
	    RETVAL=$?
c61ab5b
	    [ $RETVAL -eq 0 ] && success || failure
f7093a5
	fi
c61ab5b
	echo
e33aa8f
}
e33aa8f
e33aa8f
stop() {
c61ab5b
	echo -n $"Unregistering binary handler for Windows applications: "
e33aa8f
	echo "-1" >/proc/sys/fs/binfmt_misc/windows || :
e33aa8f
	echo "-1" >/proc/sys/fs/binfmt_misc/windowsPE || :
c61ab5b
	RETVAL=$?
c61ab5b
	[ $RETVAL -eq 0 ] && success || failure
c61ab5b
	echo
e33aa8f
}
e33aa8f
e33aa8f
wine_status() {
e33aa8f
	if [ -e /proc/sys/fs/binfmt_misc/windows ]; then
e33aa8f
		echo $"Wine binary format handlers are registered."
e33aa8f
		return 0
e33aa8f
	else
e33aa8f
		echo $"Wine binary format handlers are not registered."
e33aa8f
		return 3
e33aa8f
	fi
e33aa8f
}
e33aa8f
e33aa8f
case "$1" in
e33aa8f
	start)
e33aa8f
		start
e33aa8f
		;;
e33aa8f
	stop)
e33aa8f
		stop
e33aa8f
		;;
e33aa8f
	status)
e33aa8f
		wine_status
e33aa8f
		RETVAL=$?
e33aa8f
		;;
e33aa8f
	restart)
e33aa8f
		stop
e33aa8f
		start
e33aa8f
		;;
30aa51c
	reload)
30aa51c
		stop
30aa51c
		start
30aa51c
		;;
c61ab5b
	condrestart|try-restart)
c61ab5b
	
e33aa8f
		if [ -e /proc/sys/fs/binfmt_misc/windows ]; then
e33aa8f
			stop
e33aa8f
			start
e33aa8f
		fi
e33aa8f
		;;
e33aa8f
	*)
30aa51c
		echo $"Usage: $prog {start|stop|status|restart|reload|try-restart}"
e33aa8f
		exit 1
e33aa8f
esac
e33aa8f
exit $RETVAL
e33aa8f