#! /bin/sh
#
# startfile for built in samba, by newbiefan @ wl500g.info
# For Olegs & Ily's FW for Asus Routers
# store this script in /opt/etc/init.d if you've installed optware

# Prgmname=/full_path/Prgmname
prgmname1="/usr/sbin/nmbd"
prgmname2="/usr/sbin/smbd"

# configfile=/full_path/configfile
configfile="/opt/etc/smb.conf"

#location of pid-file
nmbdpid="/var/lock/nmbd.pid"
smbdpid="/var/lock/smbd.pid"

start() {
        # Code here to start the program
        ${prgmname1} -D -s ${configfile}
        logger -t nmbd "started $prgmname1, conf: $configfile"
        ${prgmname2} -D -s ${configfile}
        logger -t smbd "started $prgmname2, conf: $configfile"
        return 0
}

stop() {
        # Code here to stop the program and check it's dead
        #if [ -n "`pidof nmbd`" ]; then
        [ -f $nmbdpid ] && kill `cat $nmbdpid` && rm -f $nmbdpid
        logger -t nmbd "service stopped"
        sleep 1
        [ -f $smbdpid ] && kill `cat $smbdpid` && rm -f $smbdpid
        logger -t smbd "service stopped"
        return 0
}
##########################start here##########################
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        logger -t Samba "nmbd & smbd restart, executed from $(whoami)"
        stop
        sleep 2
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
sleep 1
exit
