#!/bin/sh
#
# startfile for entware-samba, written by linux.tinkerer at gmail.com
# For Ily's FW of Asus Routers
# store this script in /opt/etc/init.d if you've installed entware

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

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

#location of pid-file
nmbdpid="/opt/var/run/nmbd.pid"
smbdpid="/opt/var/run/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
        [ -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"
        stop
        sleep 2
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
exit
