OpenWrt Forum Archive

Topic: bootload script

The content of this topic has been archived on 31 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

hello i would like to execute this lines :
ifconfig eth0 192.168.8.1
ifconfig usb0 192.168.7.3
systemctl stop firewalld.service     
sudo iptables -t nat -A POSTROUTING --out-interface usb0  -j MASQUERADE
sudo iptables -A FORWARD --in-interface eth0 -j ACCEPT
sleep 1
echo 1 >  /proc/sys/net/ipv4/ip_forward

at the end of load of linux, I know that i have to do something in  init.d but I'm not realy sure what ...
I copied example script to /etc/init.d
cat example
#!/bin/sh
# Example script
# Copyright (C) 2007 OpenWrt.org

START=10
STOP=15

boot() {
        echo boot
        ifconfig eth0 192.168.8.1
        ifconfig usb0 192.168.7.3
        systemctl stop firewalld.service     
        sudo iptables -t nat -A POSTROUTING --out-interface usb0  -j MASQUERADE
        sudo iptables -A FORWARD --in-interface eth0 -j ACCEPT
        sleep 1
        echo 1 >  /proc/sys/net/ipv4/ip_forward
        # commands to run on boot
}

start() {
        echo start
        # commands to launch application
}

stop() {
        echo stop
        # commands to kill application
}
/etc/init.d directory output

:/etc/init.d# ls
acpid                              halt                               mountnfs.sh         single
alsa-utils                        hdparm                         mtab.sh                skeleton
apache2                         hostapd                        networking           ssh
avahi-daemon                hostname.sh                pppd-dns              sudo
bluetooth                        hwclock.sh                   procps                  udev
bootlogs                         kbd                                rc                         udev-mtab
bootmisc.sh                   keyboard-setup             rc.local                 udhcpd
capemgr.sh                    killprocs                        rcS                        umountfs
checkfs.sh                      kmod                            README              umountnfs.sh
checkroot-bootclean.sh  lightdm                          reboot                  umountroot
checkroot.sh                   loadcpufreq                  rmnologin             urandom
console-setup                 motd                             rsync                    wicd
cpufrequtils                     mountall-bootclean.sh  rsyslog                 x11-common
cron                                mountall.sh                   samba                  xrdp
dbus                               mountdevsubfs.sh         saned
example                         mountkernfs.sh              screen-cleanup
generic-boot-script.sh    mountnfs-bootclean.sh  sendsigs

I also enabled this script but its not working. Can someone help me please ??

Try changing the line "#!/bin/sh " in your script to "#!/bin/sh /etc/rc.common" and then try to enable it and see if it works.

the way to add bootload script:
1)add new script in /etc/init.d as you have done
2)Establish a soft link.  ln -s /etc/init.d/name /etc/rc.d/S100name
then, the next time you restart your device you can see the result

The discussion might have continued from here.