#! /bin/bash

# TODO
# - INIT INFO

# This script wraps SuSE typical features around rc.autofs. As many features as
# possible are included. Since SuSE has already included the normal autofs
# system we even have a Variable set in rc.config!
#
### BEGIN INIT INFO
# Provides: FOO
# Required-Start: $remote_fs $syslog
# Required-Stop:  $remote_fs $syslog
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start FOO to allow XY and provide YZ.
### END INIT INFO

# Source SuSE config
. /etc/rc.config

# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}

# Force execution if not called by a runlevel directory.
test $link = $base && START_AUTOFS=yes
test "$START_AUTOFS" = yes || exit 0

# Now set the variables used by rc.aufofs
#
# Name of the automount binary (also used for locking file names)
export AUTOMOUNT=automount
# The full path to the automount binary
export AUTOMOUNT_PATH="/usr/sbin/${AUTOMOUNT}"
# Additional Options for ALL automount daemons
export AUTOMOUNTOPTIONS=""
# Additional Options for ALL maps
export MAPOPTIONS=""
# The place, where we can find the auto.master file
export AUTO_MASTER="/etc/auto.master"


# Where is the "real" INIT-Script?
rc_autofs="/usr/sbin/rc.autofs"

. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - misc error
# 2 - invalid or excess args
# 3 - unimplemented feature (e.g. reload)
# 4 - insufficient privilege
# 5 - program not installed
# 6 - program not configured
# 7 - program is not running
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

case "$1" in
    start)
	echo -n "Starting autofs: "
	# startproc should return 0, even if service is 
	# already running to match LSB spec.
        $rc_autofs start
	rc_status -v
	;;
    stop)
	echo -n "Shutting down autofs: "
        $rc_autofs stop
	rc_status -v
	;;
    try-restart)
        echo -n "Trying to restart autofs: "
        $rc_autofs try-restart
	rc_status -v
	;;
    restart)
	echo -n "Reload service autofs: "
	$rc_autofs restart
	rc_status -v
	;;
    force-reload)
	echo -n "Reload service autofs: "
	$rc_autofs force-reload
	#touch /var/run/FOO.pid
	rc_status -v
	;;
    reload)
	echo -n "Reload service autofs: "
	$rc_autofs reload
	#touch /var/run/FOO.pid
	rc_status -v
	;;
    status)
	echo -n "Checking for autofs: "
	# Status has a slightly different for the status command:
	# 0 - service running
	# 1 - service dead, but /var/run/  pid  file exists
	# 2 - service dead, but /var/lock/ lock file exists
	# 3 - service not running

        $rc_autofs status
	rc_status
	;;
    probe)
	$rc_autofs probe
	rc_status
        ;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 2
	;;
esac
rc_exit
