#!/bin/sh

opmode=`nvram_get 2860 OperationMode`
SAMBA_FILE=/etc/smb.conf

if [ ! -n "$2" ]; then
	echo "insufficient arguments!"
	echo "Usage: $0 <netbios_name> <workgroup>"
	echo "Example: $0 RT2880 Ralink"
	exit 0
fi

NETBIOS_NAME="$1"
WORKGROUP="$2"
MOUNT_PATH="$3"
MOUNT_NAME="$4"
SHARE_NAME="$4"

echo "[global]
use sendfile = yes
netbios name = $NETBIOS_NAME
server string = Samba Server
workgroup = $WORKGROUP
security = share
guest ok = yes
guest account = sonypws
log file = /var/smb/log.samba
socket options = TCP_NODELAY SO_RCVBUF=48000 SO_SNDBUF=40000
encrypt passwords = yes
use spne go = no
client use spnego = no
load printers = no
disable spoolss = yes
printcap name = /dev/null
show add printer wizard = no
host msdfs = no
strict allocate = no
#os level = 20
log level = 0
max log size = 50
max connections = 8
null passwords = yes
force create mode = 0777
force directory mode = 0777
dos charset = CP850
unix charset = UTF8
display charset = UTF8
bind interfaces only = yes" > $SAMBA_FILE
if [ "$opmode" = 0 ]; then
	echo "interfaces = lo br0" >> $SAMBA_FILE
elif [ "$opmode" = 1 ]; then
	echo "interfaces = lo br0 eth2.2" >> $SAMBA_FILE
elif [ "$opmode" = 2 ]; then
	echo "interfaces = lo eth2 ra0" >> $SAMBA_FILE
elif [ "$opmode" = 3 ]; then
	echo "interfaces = lo br0 apcli0" >> $SAMBA_FILE
else
	echo "interfaces = lo" >> $SAMBA_FILE
fi

 
if [ "$MOUNT_NAME" = "SDCard" ]; then
	SHARE_NAME=SD_Card
elif [ "$MOUNT_NAME" = "USBDisk" ]; then
	SHARE_NAME=USB_Device
fi
 
echo "[$SHARE_NAME]
path = $MOUNT_PATH
guest ok = yes
oplocks = no
browseable = yes
writable = yes
create mask = 0664
directory mask = 0775" >> $SAMBA_FILE

iptables -t raw -D PREROUTING -p tcp --dport 445  -j NOTRACK
iptables -t raw -A PREROUTING -p tcp --dport 445  -j NOTRACK
iptables -t raw -D OUTPUT -p tcp --sport 445  -j NOTRACK
iptables -t raw -A OUTPUT -p tcp --sport 445  -j NOTRACK

