Roberto Cazzaro
New Around Here
...
Last edited:
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.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
pc_insert "string to locate" "string to insert after" "config filename"
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh
pc_insert "[user (at Entware)]" "browseable=no" $CONFIG
echo "#test" >> $CONFIG
Try escaping the [ and ]Hence, this should insert "browseable=no" after [user (at Entware)] in your case:
The line "#test IS added but not the browsable directive.Code:#!/bin/sh CONFIG=$1 source /usr/sbin/helper.sh pc_insert "[user (at Entware)]" "browseable=no" $CONFIG 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:
The line "#test IS added but not the browsable directive.Code:#!/bin/sh CONFIG=$1 source /usr/sbin/helper.sh pc_insert "[user (at Entware)]" "browseable=no" $CONFIG echo "#test" >> $CONFIG
# 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
#================================================================================
}
I tried that as well, no dice:Try escaping the [ and ]
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
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
_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.Does this /usr/sbin/helper.sh patch work?
Nope tested, I have no idea what goes wrong here
#!/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
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!!! <<<<<
./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
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!!! <<<<<
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' }
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!