#!/bin/sh

# Source networking configuration.
. /etc/sysconfig/network
 
status=$(/sbin/e-smith/config getprop smb status)
if [ "$status" = "disabled" ]
then
    /sbin/e-smith/config setprop smb status disabled
    sv d .
    exit
fi

samba=/usr/sbin/samba

[ -f $samba ] || exit 1
 
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1
 
# Check that smb.conf exists.
[ -f /etc/samba/smb.conf ] || exit 1
 
# Check that we can write to it... so non-root users stop here
[ -w /etc/samba/smb.conf ] || exit 1

# Delete the printing.tdb file if it exists to force it to rebuild.
rm -f /var/cache/samba/printing.tdb

# Backup critical tdb files
#for tdb in /etc/samba/*.tdb \
#           /var/lib/samba/*.tdb
#do
#    [ -r "$tdb" ] && tdbbackup "$tdb" .bak
#done

exec 2>&1
exec $samba -i
