1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

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!

Custom scripts and stock firmware.

Discussion in 'ASUSWRT - Official' started by Vexira, Feb 2, 2018.

  1. Vexira

    Vexira Very Senior Member

    Joined:
    Jan 20, 2017
    Messages:
    1,368
    Location:
    Australia
    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
     
  2. Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!
  3. RMerlin

    RMerlin Super Moderator

    Joined:
    Apr 14, 2012
    Messages:
    27,986
    Location:
    Canada
    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".
     
    Vexira likes this.
  4. Vexira

    Vexira Very Senior Member

    Joined:
    Jan 20, 2017
    Messages:
    1,368
    Location:
    Australia
    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.
     
  5. Rajesh Honnawarkar

    Rajesh Honnawarkar New Around Here

    Joined:
    Jan 7, 2018
    Messages:
    4
    yeah, i would like to do the ad-blocking stuff on the router. Is that possible with stock firmware (esp. now I am running AiMesh)?
     
  6. Zentachi

    Zentachi Occasional Visitor

    Joined:
    Jan 17, 2018
    Messages:
    46
    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.
     
  7. Sinner

    Sinner Senior Member

    Joined:
    Sep 30, 2017
    Messages:
    273
    Location:
    Canada
    I'm testing out this adguard dns beta.. seems to work quite well so far.. just involves changing the wan dns servers on your router and then works for entire network.. more info here: https://adguard.com/en/adguard-dns/overview.html
     
    scope666 and Rajesh Honnawarkar like this.
  8. GBS

    GBS New Around Here

    Joined:
    Feb 16, 2018
    Messages:
    2
    Location:
    Munich, Germany
    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
     
  9. bbunge

    bbunge Very Senior Member

    Joined:
    Aug 11, 2014
    Messages:
    565
    Could this be used to add a swap file to stock Asus?

    Sent from my P01M using Tapatalk
     
  10. GBS

    GBS New Around Here

    Joined:
    Feb 16, 2018
    Messages:
    2
    Location:
    Munich, Germany
    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: Feb 17, 2018
  11. ourcontact

    ourcontact Occasional Visitor

    Joined:
    Sep 25, 2018
    Messages:
    10
    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: Oct 6, 2018
Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!