#!/bin/bash
#
# 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 
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#

### BEGIN INIT INFO
# Provides:          freebsd-utils udev
# Required-Start:
# Required-Stop:     
# X-Start-Before:    mtab
# Default-Start:     S
# Default-Stop:      
# Short-Description: FreeBSD kernel specific setup
### END INIT INFO

set -e

PATH=/sbin:/bin

. /lib/lsb/init-functions

case "$1" in
  start)
    if [ "$(readlink /etc/mtab)" != "/proc/mounts" ] ; then
      log_warning_msg "Warning: replacing /etc/mtab by a symlink to /proc/mounts."
      rm -f /etc/mtab
      ln -sf /proc/mounts /etc/mtab
    fi

    log_action_begin_msg "Loading devfs rules"
    devfs ruleset 1
    devfs rule delset
    for rule in /etc/devfs.d/*.rules ; do
      egrep -v '^[[:space:]]*(#|$)' $rule | devfs rule add -
    done
    devfs rule applyset
    log_action_end_msg $?

    log_action_begin_msg "Setting up /dev links"
    # setup /dev/cdrom symlink
    if ! test -e /dev/cdrom && ! test -L /dev/cdrom ; then
      for i in {,a}cd{0,1,2,3,4,5,6,7,8,9} ; do
        if test -e /dev/$i ; then
          ln -s $i /dev/cdrom
          break
        fi
      done
    fi
    log_action_end_msg 0
   
    log_action_begin_msg "Mounting kernel filesystems"
    # Mount /dev/fd, /proc and /sys
    if ! test -f /proc/cmdline ; then
      mount -t linprocfs proc /proc
    fi
    if ! test -d /sys/devices ; then
      # Should be done during the installation
      if [ ! -d /sys ] ; then
        mkdir /sys
      fi
      mount -t linsysfs sys /sys
    fi
    if ! mount | grep -q "on /dev/fd (fdescfs" ; then
      mount -t fdescfs fdescfs /dev/fd
    fi
    log_action_end_msg 0
    ;;

  stop|reload|restart|force-reload)
    ;; 

  *)
      echo "Usage: $0 {start|stop|restart|force-reload}" >&2
      exit 1
      ;;
esac

exit 0
    
