DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2011-05-30 12:46:38

augusto
Member
Registered: 2011-03-04
Posts: 6

script to add samba shares

Hi everyone,

I wanted to share a little script to add samba shares. Please forgive me if there're more scripts like this going around, but I counldn't find any.

the script reads any configuration snippets that are present in /ffp/etc/samba/*.conf and appends them to /etc/samba/smb.conf with a bit of extra logic to detect if the script was run before.

/ffp/start/sambaShares.sh

Code:

#!/ffp/bin/sh

# PROVIDE: sambaShare
# REQUIRE: LOGIN

. /ffp/etc/ffp.subr

name="sambaShare"
start_cmd="sambaShare_start"
stop_cmd="sambaShare_stop"
status_cmd="sambaShare_status"

# put your smb.conf snippets in the directory below. The file name must end in '.conf'.
file_pattern="/ffp/etc/samba/*.conf"
watermark="samba_share_script_was_here"
smb_conf="/etc/samba/smb.conf"
smb_conf_backup="/ffp/etc/samba/smb.conf.original"
smb_restart="/usr/bin/smb restart"

sambaShare_start()
{
  if grep "$watermark" $smb_conf >/dev/null; then
    die "samba share script was already run before. Do a stop or restart"
  fi
  
  #backup original smb.conf
  cp $smb_conf $smb_conf_backup
  
  #add watermark
  echo >> $smb_conf
  echo "#$watermark" >> $smb_conf
  
  files_to_append=`ls $file_pattern`
  
  for file in $files_to_append; do
    echo "appending file $file to $smb_conf"
    
    echo >> $smb_conf
    echo "#section taken from $file" >> $smb_conf
    cat $file >> $smb_conf
  done
  
  echo "restarting samba"
  $smb_restart
}

sambaShare_stop()
{
  if ! grep "$watermark" $smb_conf >/dev/null; then
    die "samba share script was not run before."
  fi
  
  echo "removing extra samba shares"
  cp $smb_conf_backup $smb_conf
  
  echo "restarting samba"
  $smb_restart
}

sambaShare_status()
{
  if grep "$watermark" $smb_conf >/dev/null; then
    echo "extra samba shares IS running"
  else
    echo "extra samba shares IS NOT running"
  fi

}

run_rc_command "$1"

At the moment I'm using it to mount a usb drive with the following snippet

/ffp/etc/samba/usb.conf

Code:

[ usb ]
comment =
path = /mnt/USB
valid users = secret
read only = no
guest ok = no
oplocks = no
map archive = no

I hope this might be of use to someone.

Cheers,
Augusto

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB