What's new

Custom scripts and stock firmware.

  • 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!

Vexira

Part of the Furniture
Will we ever be able to use custom scripts on stock firmware, it would be nice for example for stock firmware to have an option like merlins to allow for the use of custom scripts like freshjr qos script, so that units like the GT-AC5300 could have such functionality available to it
 
Unlikely, because that means their tech support would then have to deal with completely Linux-illiterate persons contacting them requesting help on writing "a DOS batchfile for my router to do a thingy".
 
I see your point, but if it would allow for the use of edge fresh jr qos script on lets say a GT-AC5300 id see a benefit. Just a toggle switch like your firmware would be nice most users probably wouldn't see it.

And im surprised people don't already do it.
 
When I was looking around for a problem I had with my asus ac86u and a usb3 hdd I came upon this post
https://www.securityforrealpeople.com/2014/12/customizing-samba-on-asuswrt-wireless.html

It says that:
"One undocumented feature in ASUSWRT is the ability to specify a custom script to execute anytime a USB drive is mounted. Since a USB drive that is plugged into the router has to be mounted before use, this feature also has the effect of substituting for a "run at boot" script. "

I am not sure if this the case anymore and didn't have the chance to test it as I am using Merlin's 384.
 
Will we ever be able to use custom scripts on stock firmware, it would be nice for example for stock firmware to have an option like merlins to allow for the use of custom scripts like freshjr qos script, so that units like the GT-AC5300 could have such functionality available to it
When I was looking around for a problem I had with my asus ac86u and a usb3 hdd I came upon this post
https://www.securityforrealpeople.com/2014/12/customizing-samba-on-asuswrt-wireless.html

It says that:
"One undocumented feature in ASUSWRT is the ability to specify a custom script to execute anytime a USB drive is mounted. Since a USB drive that is plugged into the router has to be mounted before use, this feature also has the effect of substituting for a "run at boot" script. "

I am not sure if this the case anymore and didn't have the chance to test it as I am using Merlin's 384.
In addition to script_usbmount NVRAM variable described in the link from Zentachi there also is (at least on my RT-N18U FW - would assume also on other stock FW) an NVRAM variable "ffs2_exec". If this variable is set to an executable script it will be executed at the start of jffs (basically every boot).

I use this for example to add entries to the hosts file in /etc (cloudflare does not allow me to spell out full path !?) which turns my router into a DNS server for my local network....

A few notes on use of ffs2_exec:
1) script must be executable and include shebang (#!/bin/sh)
2) the calling code waits for the script to terminate (different from script_usbmount), so as the script waits for router services to finish start-up (polling success_start_service NVRAM variable), the script should move to background in a pseudo-daemon way.
Here as an example the script I use (“boot_runscript”). In the example it calls another script “append_hosts” which does nothing more than appending my custom hosts list to hosts fiile and send a SIGHUP to dnsmasq...

Code:
#!/bin/sh
#
# boot_runscript - custom script executed at boot (during start of jffs)
#
# Note:    1) NVRAM variable "jffs2_exec" must point to this script
#    2) The calling code waits for this script to terminate,
#       so in order to not stall the boot process, we quickly
#       move to the background
#

maxwait=300
append_hosts='/jffs/bin/append_hosts'


umask 022

#
# move to background in a subshell
#
(
    cd /

    # ignore SIGHUP
    trap '' SIGHUP

    # redirect STDIN, STDOUT, STDERR
    exec 0< '/dev/null'
    exec 1> '/dev/null'
    exec 2> '/dev/null'

    #
    # wait till all the system services are started
    # by polling "success_start_service" NVRAM variable
    #
    i=0
    while [ "$i" -le "$maxwait" ]
    do
        success_start_service="$( nvram get 'success_start_service' )"
        if [ "$success_start_service" == '1' ]
        then
            break
        fi
        sleep 10
        i=$(( $i + 10 ))
    done

    if [ "$i" -gt "$maxwait" ]
    then
        # timeout
        logger 'boot_runscript: timout waiting for "success_start_service"'
        exit 1
    fi

    #
    # wait a little longer to allow ntp client to get correct time
    #
    sleep 60

    logger 'boot_runscript executing'

    # append custom hosts file to hosts
    if [ -x "$append_hosts" ]
    then
        eval "$append_hosts"
    fi
    
    # add other stuff you want to do...
    
    exit 0
)&

exit 0

Enjoy, GBS
 
Could this be used to add a swap file to stock Asus?

Sent from my P01M using Tapatalk
 
Could this be used to add a swap file to stock Asus?

Sent from my P01M using Tapatalk
Disclaimer: have not tried using a swap file - only speaking theoretically...
Teoretically yes, but for a swap file you would need an external USB storage anyway, so I would rather use script_usbmount NVRAM variable to point to a script which creates the swap. This script will automatically be launched when an USB device gets mounted...

script_usbmount script gets called with mount point as argument, so you can use this to determine if this is the right device to create the swap file ...
Edit: In order to have the script called with mount point as argument set script_usbmount as follows:
nvram set script_usbmount='<path_to_your_script>/<your_script> "$*"'
e.g. nvram set script_usbmount='/jffs/bin/usbmount_runscript "$*"'
And don't forget the: nvram commit

BTW - script_usbmount script does not have to move into the background like jffs2_exec script, but you should still poll the success_start_service NVRAM variable...
 
Last edited:
In addition to script_usbmount NVRAM variable described in the link from Zentachi there also is (at least on my RT-N18U FW - would assume also on other stock FW) an NVRAM variable "ffs2_exec". If this variable is set to an executable script it will be executed at the start of jffs (basically every boot).

How does ffs_exec compare to /jffs/.asusrouter

Currently I have
Code:
killall dnsmasq
dnsmasq --log-async --conf-dir=/jffs/configs/dnsmasq

and in /jffs/configs/dnsmasq a link to system plus custom

Code:
dnsmasq.conf -> /etc/dnsmasq.conf
dnsmasq.conf.add

dnsmasq.conf.add has script and addn_hosts

Code:
dhcp-script=/jffs/scripts/dhcp-script.sh
addn-hosts=/jffs/etc/host.s

- host.s= hosts but SNB is blocking that for some reason
 
Last edited:
In addition to script_usbmount NVRAM variable described in the link from Zentachi there also is (at least on my RT-N18U FW - would assume also on other stock FW) an NVRAM variable "ffs2_exec". If this variable is set to an executable script it will be executed at the start of jffs (basically every boot).

A few notes on use of ffs2_exec:
1) script must be executable and include shebang (#!/bin/sh)
2) the calling code waits for the script to terminate (different from script_usbmount), so as the script waits for router services to finish start-up (polling success_start_service NVRAM variable), the script should move to background in a pseudo-daemon way.
Here as an example the script I use (“boot_runscript”). In the example it calls another script “append_hosts” which does nothing more than appending my custom hosts list to hosts fiile and send a SIGHUP to dnsmasq...

Hi @GBS, I have been using your solution and it worked well till I updated the firmware to 3.0.0.4.384_45717. My script is no longer executed for some reason. After the update, the permissions of scripts in /jffs/scripts directory are getting reseted to default (-rw-r--r--) after each router reboot. Perhaps that's what prevents them from being executed. Have anybody found a workaround?
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

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