#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#
# This file was automatically customized by dh-make on Tue, 28 Aug 2001 12:05:04 +0200

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=plex86
DESC="Plex86 Services"
MODULE="/lib/modules/`uname -r`/misc/plex86.o"
INSMOD=""
RMMOD=""


set -e

if [ `id -u` != "0" ]; then
  echo "This script needs to be run with root priviledges."
  exit 1;
fi

if test ! -f $MODULE; then
  echo "Plex86 module for this Linux version is not present."
  echo "Please install a plex86-kernel package. You can install the plex86-kernel-src package in order to build it, or, if it is already installed, reconfigure it using the following command (to run as root):"
  echo "dpkg-reconfigure plex86-kernel-src"
  exit 1;
fi

case "$1" in
  start)
	echo -n "Starting $DESC: "
        if ! grep -q plex86 /proc/devices; then /sbin/insmod plex86; fi
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	if grep -q plex86 /proc/devices; then /sbin/rmmod plex86; fi
	echo "$NAME."
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	echo -n "Restarting $DESC: "
	if grep -q plex86 /proc/devices; then /sbin/rmmod plex86; fi
	sleep 1
        /sbin/insmod plex86
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart}" >&2
	exit 1
	;;
esac

exit 0
