What's new

smb.postconf not working?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Seems smb.postconf is not adding anything at all, while /jffs/configs/smb.conf.add works as intended.
I tested this on a RT-AC1900P on 382 beta firmware.
Something for @RMerlin to look at?
 
Works for me both on my RT-AC88U (384.3 alpha) and RT-AC66U_B1 (380.69). Don't forget to chmod a+rx and to enable custom script support.

Code:
admin@stargate66b1:/jffs/scripts# service restart_nasapps
Done.

admin@stargate66b1:/jffs/scripts# tail /etc/smb.conf
[user (at Entware)]
comment = Entware's user in LEXAR JUMPDRIVE SPORT
path = /tmp/mnt/Entware/user
dos filetimes = yes
fake directory create times = yes
valid users = admin
invalid users = 
read list = admin
write list = admin
#test

admin@stargate66b1:/jffs/scripts# cat smb.postconf 
#!/bin/sh
CONFIG=$1
echo "#test" >> $CONFIG
 
Works for me both on my RT-AC88U (384.3 alpha) and RT-AC66U_B1 (380.69). Don't forget to chmod a+rx and to enable custom script support.

Code:
admin@stargate66b1:/jffs/scripts# service restart_nasapps
Done.

admin@stargate66b1:/jffs/scripts# tail /etc/smb.conf
[user (at Entware)]
comment = Entware's user in LEXAR JUMPDRIVE SPORT
path = /tmp/mnt/Entware/user
dos filetimes = yes
fake directory create times = yes
valid users = admin
invalid users =
read list = admin
write list = admin
#test

admin@stargate66b1:/jffs/scripts# cat smb.postconf
#!/bin/sh
CONFIG=$1
echo "#test" >> $CONFIG
Thanks for following up.

Your code snipped works for me too, but not what OP wants to do: Inserting after a string.

The wiki says:
Code:
pc_insert "string to locate" "string to insert after" "config filename"

Hence, this should insert "browseable=no" after [user (at Entware)] in your case:
Code:
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh

pc_insert "[user (at Entware)]" "browseable=no" $CONFIG
echo "#test" >> $CONFIG
The line "#test IS added but not the browsable directive.
 
Hence, this should insert "browseable=no" after [user (at Entware)] in your case:
Code:
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh

pc_insert "[user (at Entware)]" "browseable=no" $CONFIG
echo "#test" >> $CONFIG
The line "#test IS added but not the browsable directive.
Try escaping the [ and ]
 
Thanks for following up.

Your code snipped works for me too, but not what OP wants to do: Inserting after a string.

The wiki says:
Code:
pc_insert "string to locate" "string to insert after" "config filename"

Hence, this should insert "browseable=no" after [user (at Entware)] in your case:
Code:
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh

pc_insert "[user (at Entware)]" "browseable=no" $CONFIG
echo "#test" >> $CONFIG
The line "#test IS added but not the browsable directive.

@john9527 The helper.sh script already escapes the '[' chars etc. ??

Does this /usr/sbin/helper.sh patch work?
Code:
# This function looks for a string, and inserts a specified string after it inside a given file
# $1: the line to locate, $2: the line to insert, $3: Config file where to insert
pc_insert() {
 PATTERN=$(_quote "$1")
 CONTENT=$(_quote "$2")
 #================================================================= Martineau Hack
 #sed -i "/$PATTERN/a$CONTENT" $3
 sed -i -r "/$PATTERN/a$CONTENT" $3
 #================================================================================
}
 
Try escaping the [ and ]
I tried that as well, no dice:

Code:
Jan 25 10:58:06 custom_script: Running /jffs/scripts/smb.postconf (args: /etc/smb.conf)
Jan 25 10:58:08 Samba_Server: daemon is started
Code:
user@RT-AC1900P:/tmp/home/root# cat /jffs/scripts/smb.postconf
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh

pc_insert "netbios name = RT-AC1900P" "# testentry" $CONFIG
echo "#test" >> $CONFIG

user@RT-AC1900P:/tmp/home/root# cat /etc/smb.conf
[global]
workgroup = WORKGROUP
netbios name = RT-AC1900P
server string = RT-AC1900P
unix charset = UTF8

And nothing changed in smb.conf.

The two used functions in helper.sh work flawless if I use it in a testfile, without escaping, but not in smb.postconf:
Code:
_quote() {
    echo $1 | sed 's/[]\/()$*.^|[]/\\&/g'
}

# This function looks for a string, and inserts a specified string after it inside a given file
# $1: the line to locate, $2: the line to insert, $3: Config file where to insert
pc_insert() {
    PATTERN=$(_quote "$1")
    CONTENT=$(_quote "$2")
    sed -i "/$PATTERN/a$CONTENT" $3
}
 
Nope tested, I have no idea what goes wrong here

Hmm, strange indeed but without the patch smb.postconf always fails with a FULL string match or an ABBREVIATED match of a space delimited substring.

P.S. I assumed the issue was a minor Alpha-release quirk :D

Contents of

/jffs/scripts/smb.postconf

Code:
#!/bin/sh

CONFIG=$1

source /usr/sbin/helper.sh

# Testing my /usr/sbin/helper.sh patch 25/01/2018 for v384.3 Alpha2
pc_insert "[XSyslog" "#>>>>> Test helper.sh pc_insert ABBREV match '[XSyslog' - ALWAYS inserted...Check for 'Patch worked!' record preceding THIS!!! <<<<<" $CONFIG

# This fails without patch!
pc_insert "[XSyslog (at RT-AC68U)]" "#>>>>> Test helper.sh pc_insert FULL match '[XSyslog (at RT-AC68U)]' - Patch worked! <<<<<" $CONFIG


echo -e "#\n# '$0' Edited this file!" $(date) >> $CONFIG
and test scenario
Code:
service restart_nasapps;echo paused 3 secs as sometimes display is incorrect?!!....;sleep 3;cat /etc/smb.conf | grep -E "^#>|^\[XSys"

Done.
paused 3 secs as sometimes display is incorrect?!!....
[XSyslog (at RT-AC68U)]
#>>>>> Test helper.sh pc_insert ABBREV match '[XSyslog' - ALWAYS inserted...Check for 'Patch worked!' record preceding THIS!!! <<<<<
apply patch
Code:
./DIFF_firmware.sh helper.sh map

 Mounted /jffs/scripts/helper.sh /usr/sbin/helper.sh

 Mapped Firmware scripts:
/dev/mtdblock4           64256      6808     57448  11% /usr/sbin/helper.sh
and retest.....
Code:
service restart_nasapps;echo paused 3 secs as sometimes display is incorrect?!!....;sleep 3;cat /etc/smb.conf | grep -E "^#>|^\[XSys"

Done.
paused 3 secs as sometimes display is incorrect?!!....
[XSyslog (at RT-AC68U)]
#>>>>> Test helper.sh pc_insert FULL match '[XSyslog (at RT-AC68U)]' - Patch worked! <<<<<
#>>>>> Test helper.sh pc_insert ABBREV match '[XSyslog' - ALWAYS inserted...Check for 'Patch worked!' record preceding THIS!!! <<<<<
 
Last edited:
Found it for your particular "[user (at Entware)]" case. sed doesn't like regular parentheses being escaped.
Try this patch in helper.sh
Code:
_quote() {
   #echo $1 | sed 's/[]\/()$*.^|[]/\\&/g'
   echo $1 | sed 's/[]\/$*.^|[]/\\&/g'
}
 
Found it for your particular "[user (at Entware)]" case. sed doesn't like regular parentheses being escaped.
Try this patch in helper.sh
Code:
_quote() {
   #echo $1 | sed 's/[]\/()$*.^|[]/\\&/g'
   echo $1 | sed 's/[]\/$*.^|[]/\\&/g'
}

Yup works here! :)
 
Found it for your particular "[user (at Entware)]" case. sed doesn't like regular parentheses being escaped.
Try this patch in helper.sh
Code:
_quote() {
   #echo $1 | sed 's/[]\/()$*.^|[]/\\&/g'
   echo $1 | sed 's/[]\/$*.^|[]/\\&/g'
}

Thanks, patched.
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top