#!/bin/sh
#
# File: /System/Library/StartupItems/NcFTPd/NcFTPd
#

. /etc/rc.common

##
# Start NcFTPd (FTP server)
##

if [ "${NCFTPD_FTPSERVER:=-YES-}" = "-YES-" ]; then
    ############################################################################
    #
    # Choose "verbose mode" by setting NCFTPD_VERBOSITY to "-v" while testing,
    # and then set it NCFTPD_VERBOSITY to "" when testing is complete.
    #
    # NCFTPD_VERBOSITY="-v"
    NCFTPD_VERBOSITY="-v"	# from install_ncftpd.pl
    
    
    ############################################################################
    #
    # Location of NcFTPd's configuration files.
    #
    NCFTPD_GENERAL_CF="/usr/local/etc/ncftpd/general.cf"
    NCFTPD_DOMAIN_CF="/usr/local/etc/ncftpd/domain.cf"
    
    
    ############################################################################
    #
    # Location of the startup log.  This log is used before the logger
    # process has been bootstrapped, so the startup log serves as a
    # location to log errors that occur before the logger has been
    # started.
    #
    NCFTPD_STARTUP_ERROR_LOG="/var/log/ncftpd/startup_errors"
    
    
    ############################################################################
    #
    # Rather than running $NCFTPD_PROG directly, we set the
    # PATH and use a relative path.  This makes it easy to
    # spot the "ncftpd" processes in "ps" or "top".
    #
    # This also implies that you must properly set the variable
    # $NCFTPD_PROG_PATH so it contains the directory containing
    # $NCFTPD_PROG.
    #
    NCFTPD_PROG_PATH="/usr/local/sbin:/usr/local/bin:$PATH"
    NCFTPD_PROG="/usr/local/sbin/ncftpd"

    if [ -x "$NCFTPD_PROG" ] && [ -f "$NCFTPD_GENERAL_CF" ]  && [ -f "$NCFTPD_DOMAIN_CF" ] ; then
        ConsoleMessage "Starting NcFTPd FTP Service"
        oPATH="$PATH"
        PATH="${NCFTPD_PROG_PATH}"
        export PATH
        ncftpd -d ${NCFTPD_VERBOSITY} "${NCFTPD_GENERAL_CF}" "${NCFTPD_DOMAIN_CF}" > "$NCFTPD_STARTUP_ERROR_LOG" 2>&1
        PATH="$oPATH"
    fi
    unset NCFTPD_HOME NCFTPD_GENERAL_CF NCFTPD_DOMAIN_CF NCFTPD_VERBOSITY oPATH
fi
