Results 1 to 3 of 3

Thread: Post Your Useful Scripts

  1. #1

    Post Your Useful Scripts

    Err.. I thought it might be a neat idea if people posted any useful scripts/files they've written or have to be used with the WL-500g. So post away! I'll post some that I consider useful but most people probably wouldn't. I use some extensive post-firewall stuff with headers and functions which I won't post here (yet); it's slow at loading anyway.

    /usr/local/sbin/start-nas:
    Code:
    #!/bin/sh
    # Kill it if it's running
    killall nas
    # Use correct library
    export LD_LIBRARY_PATH=/usr/lib
    # Allow access to nas again (unmount
    # it from /dev/null)
    umount /usr/sbin/nas
    # I throw these in a lot. May/may not
    # be necessary. I haven't removed it
    # because "if it ain't broke don't fix it."
    # So shoot me.
    # Sleep for 10 milliseconds to (probably
    # unnecessarily) make time for an
    # umount.
    usleep 10000
    # Launch nas
    nas /tmp/nas.lan.conf /tmp/nas.lan.pid lan &
    /var/spool/cron/crontabs/admin: (put in /usr/local/.files)
    Code:
    0 12 1-30/2 * * /usr/local/sbin/reset-logs
    * * * * * /usr/local/sbin/ensure-proc
    (every other day it resets the logs, every minute it ensures that important processes are running)

    /usr/local/sbin/reset-logs: (chmod +x)
    Code:
    #!/bin/sh
    #rm /opt/syslog.old
    #mv /opt/syslog.log /opt/syslog.old
    #rm /opt/openvpn.old
    #mv /opt/openvpn.log /opt/openvpn.old
    rm /opt/radius.old
    mv /opt/radius.log /opt/radius.old
    rm /opt/ep.old
    mv /opt/ep.log /opt/ep.old
    rm /tmp/syslog.log
    touch /tmp/syslog.log
    /usr/local/sbin/ensure-proc: (chmod +x)
    Code:
    #!/bin/sh
    # This script checks to make sure important
    # processes are running (in case they crash).
    # It also makes sure annoying or unwanted
    # programs are not running.
    
    #LOGFILE=/dev/null
    LOGFILE=/opt/ep.log
    time=`date +"%x %l:%M:%S%p"`
    echo "`date +%m%d%H%M%C%y`" > /opt/time
    ensure()
    {
     cmd=$2
     name=$3
     if [ -z "$2" ]; then cmd=$1; fi
     if [ -z "$3" ]; then name=$1; fi
     running=`ps | grep "$1" | grep -v "grep"`
     if [ -z "$running" ]; then
      echo $time $name": restarting" >> $LOGFILE
      $cmd
     fi
    }
    
    ensure upnp "/usr/sbin/upnp -D -L `nvram get lan_ifname` -W `nvram get wan_ifname`"
    ensure nas "/usr/local/sbin/start-nas"
    #ensure openvpn "/usr/local/sbin/start-vpn"
    #ensure radiusd "/usr/local/sbin/start-radius"
    ensure dropbear
    ensure dnsmasq
    /usr/local/sbin/ipt_mac:
    Code:
    # NOT TO BE RUN DIRECTLY
    # This script is used to force association between
    # IP address and MAC address for communication
    # to occur. Otherwise, all packets are dropped.
    # Make sure /etc/dnsmasq.conf is configured to
    # use /etc/ethers.
    # Communication with authorized MAC addresses
    # is allowed only with source IP addresses 0.0.0.0
    # and that which the MAC address is associated with
    # in order to allow DHCP assignment, which, with
    # the help of /etc/ethers, should assign the MAC
    # the associated address. In other words, an
    # address assigned manually that is different from
    # the associated address may not access the
    # network.
    . variables
    init_macs() {
     if [ -e /tmp/macs ]; then
      echo "NO!!!"
      exit
     fi
     touch /tmp/macs
     $IPTM -N MACS
     $IPTM -F MACS
     $IPTM -A MACS -s 192.168.1.1 -j RETURN
     macs=
     rm -f /etc/ethers
     touch /etc/ethers
     killall dnsmasq
    }
    MAC() {
     $IPTM -A MACS -s $2 -m mac --mac-source $1 -j RETURN
     $IPTM -A MACS -s 0.0.0.0 -m mac --mac-source $1 -j RETURN
     if [ "$3" -eq 1 ]; then macs="$macs$1 "; fi
     echo "$1 $2" >> /etc/ethers
    }
    finish_macs() {
     $IPTM -A MACS -j DROP
     #$IPTM -A MACS -j LOG
     $IPTM -D PREROUTING -i $INTIF -j MACS
     $IPTM -I PREROUTING -i $INTIF -j MACS
     wl macmode 0
     usleep 250000
     wl mac none
     usleep 250000
     if [ -n "$macs" ]; then
      wl mac $macs
      usleep 250000
      wl macmode 2
     fi
     /usr/sbin/dnsmasq
     rm -f /tmp/macs
    }
    /usr/local/sbin/MACS: (chmod +x)
    Code:
    #!/bin/sh
    # This is the file which is run in
    # order to initiate the MAC/IP
    # association and protection/
    # security functions.
    . /usr/local/sbin/ipt_mac
    init_macs
    . /usr/local/sbin/maclist
    finish_macs
    /usr/local/sbin/maclist:
    Code:
    # NOT TO BE RUN DIRECTLY
    # It looks something like this:
    # This is a normal LAN device.
    # MAC 00:00:00:00:00:01 192.168.1.101
    # This is a WLAN device. Notice the 1 on the end,
    # representing to the MAC function that this MAC
    # address should be allowed to access the network
    # wirelessly.
    # MAC 00:00:00:00:00:02 192.168.1.102 1
    # You must populate this list according to your own
    # network if this is to be used.
    /usr/local/sbin/save: (chmod +x)
    Code:
    #!/bin/sh
    flashfs save
    flashfs commit
    /usr/local/sbin/do-dyndns: (chmod +x)
    Code:
    #!/bin/sh
    wan_ip=`nvram get wan_ipaddr_t`
    
    if [ -z "$wan_ip" ]; then exit; fi
    
    until [ -e /opt/lastip ]
     do
     sleep 1
    done
    
    lastip=`cat /opt/lastip`
    
    if [ "$wan_ip" != "$lastip" ]
    then
     echo NEW IP!
     ez-ipupdate -c /etc/dynamic_dns
     echo $wan_ip > /opt/lastip
     #killall noip2
     #usleep 250000
     #/opt/sbin/noip2
    else
     echo SAME IP!
    fi
    /etc/dynamic_dns: (to put it /usr/local/.files, or perhaps just save /etc/dynamic_dns in /usr/local/etc since I think it copies it to /etc .. ?)
    Code:
    #!/bin/sh
    service-type=dyndns
    user=user:pass
    interface=`nvram get wan_ifname`
    host=blah.dyndns.org
    Last edited by tomilius; 02-06-2005 at 06:20. Reason: ipt_mac one-instance mod

  2. #2
    Here's something I've just come up with to stop the WAN interface from being brought down or set to 0.0.0.0 if your dhcp lease is lost... for 5 seconds anyway. That is, it will delay such an occurence by 5 seconds, and if the IP address was renewed, it won't perform either of those things at all, making for a smooth transition to a new IP address (theoretically). So, if the IP address ends up being the same as before, you won't lose connectivity (with my own set up, I've mounted iptables-restore to /dev/null and made post-firewall check to see if the IP has changed before reloading). I'm not actually positive that it works in real-world renewal situations, but it has worked when killing udhcpc and launching it again.

    /usr/local/sbin/kill-if: (chmod +x)
    Code:
    #!/bin/sh
    # delayed wan interface set to 0.0.0.0
    sleep 5
    if [ -e /tmp/renew ]; then
     rm /tmp/renew
    else
     ifconfig `nvram get wan_ifname` 0.0.0.0
    fi
    /usr/local/sbin/udhcpc: (chmod +x)
    Code:
    #!/bin/sh
    if [ "$1" = "deconfig" ]; then
     /usr/local/sbin/kill-if &
     exit
    fi
    if [ "$1" = "bound" ] || [ "$1" = "renew" ]; then
     touch /tmp/renew
     /tmp/udhcpc-call $@
     exit
    fi
    /usr/local/sbin/post-boot: (addition, must already be created)
    Code:
    mv /tmp/udhcpc /tmp/udhcpc-call
    cp /usr/local/sbin/udhcpc /tmp/udhcpc
    Maybe this will benefit somebody... I was spurred to try to resolve this loss of connectivity when I was utterly destroyed by Charr in Guild Wars because of it.
    Last edited by tomilius; 04-06-2005 at 07:23.

  3. #3
    Choose to boot normally or on the usb disk

    When compiling Oleg's firmware. After executing the "make" command in the broadcom/src/wl500g-1.9.2.7-5a. Go into the broadcom/src/gateway/others and edit the linuxrc file. Found this lines :
    if [ -d /mnt/mnt ]; then
    cd /mnt
    mount -t devfs none dev
    pivot_root . mnt
    exec chroot . sbin/init <dev/null >dev/null 2>&1
    fi
    And replace by this :
    if [ -d /mnt/mnt ]; then
    if [ -s /mnt/boot/boot_system ]; then
    cd /mnt
    mount -t devfs none dev
    pivot_root . mnt
    exec chroot . sbin/init <dev/null >dev/null 2>&1
    fi
    fi
    Then, in your usb disk, execute this command :
    mkdir /path_to_usb_disk/boot
    touch /path_to_usb_disk/boot/boot_system
    Now, if you want to boot on usb disk, just put something in the /path_to_usb_disk/boot/boot_system file and reboot. As exemple, you can do this :
    echo 1 > /path_to_usb_disk/boot/boot_system
    If you want to boot normally, you just have to clear this file :
    rm /boot/boot_system
    touch /boot/boot_system
    Another tips in this case : you can choose to load a /linuxrc file on usb disk (which can be useful for pre-init commands) :
    Replace by :
    if [ -d /mnt/mnt ]; then
    if [ -s /mnt/boot/boot_system ]; then
    /mnt/linuxrc
    fi
    fi
    And don't forget to put a linuxrc file in the root file system on usb disk with these lines :
    #!/bin/sh
    cd /mnt
    mount -t devfs none dev
    pivot_root . mnt
    exec chroot . sbin/init <dev/null >dev/null 2>&1
    # for example, you can load the wl module here by inserting command "insmod wl"
    I hope this can be useful for someone (It had been for me)

Similar Threads

  1. Start own script in post-boot or post-firewall
    By m-h-l in forum WL-500g Q&A
    Replies: 2
    Last Post: 30-09-2005, 20:03
  2. Shell scripts and post-boot
    By samoht in forum WL-500g Q&A
    Replies: 5
    Last Post: 04-06-2005, 00:58
  3. bash scripts
    By AmoRico in forum WL-500g Q&A
    Replies: 2
    Last Post: 31-01-2005, 20:45
  4. Replies: 3
    Last Post: 24-12-2004, 20:13
  5. Edit /init scripts
    By alpha5 in forum WL-500g Q&A
    Replies: 3
    Last Post: 18-06-2004, 17:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •