I place a script in /etc/uci-defaults in my own compiled firmware for auto configuring everything for the router at first boot, to avoid the hassle of manually configuring after every sysupgrade or reverting settings to factory defaults. I'm not sure whether this is the best choice, but I found it quite convenient for me.
My question is, how can I automatically reboot my router after the uci-defaults script is executed? Adding `reboot` to the script leads to an infinite loop, probably because the script does not exit properly, and then it is not deleted and therefore executed again during the next boot.
I have this question because sometimes I need to upgrade the router remotely via SSH (I know this is not recommended, but I have to), and I find that sometimes a reboot is needed to make the router work properly after the auto configuration, while a cold reset is not an option. I searched in the forum before posting, and I found this thread which has a very similar question, but it has been unanswered for a year.
I'm wondering if anyone knows how to achieve this, or have better suggestions. Thanks a lot in advance!
Unfortunately, I have tried all the methods provided below, but I still encounter an infinite reboot. So here is my script named 99-uci-703, I will appreciate if you can tell me how to modify the script.
#!/bin/sh test -f /root/wakeup.sh && exit 0 uci batch <<EOF set system.@system.hostname='WR703N' set system.@system.conloglevel=8 set system.@system.cronloglevel=8 set system.@system.timezone=HKT-8 set system.@system.zonename='Asia/Hong Kong' delete system.ntp.server add_list system.ntp.server='0.asia.pool.ntp.org' add_list system.ntp.server='time.asia.apple.com' add_list system.ntp.server='time.windows.com' commit system EOF uci batch <<EOF # set dropbear.@dropbear.Interface=lan set dropbear.@dropbear.Port=22 set dropbear.@dropbear.PasswordAuth=off set dropbear.@dropbear.RootPasswordAuth=off set dropbear.@dropbear.GatewayPorts=on commit dropbear EOF /etc/init.d/dropbear start /etc/init.d/dropbear enable uci batch <<EOF add firewall rule set firewall.@rule[-1].name='Allow-SSH' set firewall.@rule[-1].src=wan set firewall.@rule[-1].target=ACCEPT set firewall.@rule[-1].proto=tcp set firewall.@rule[-1].dest_port=22 commit firewall EOF /etc/init.d/firewall restart uci batch <<EOF set wireless.radio0.disabled=0 set wireless.radio0.channel=6 set wireless.radio0.hwmode=11g set wireless.radio0.htmode=HT20 set wireless.radio0.txpower=20 set wireless.radio0.country=HK set wireless.@wifi-iface.disabled=0 set wireless.@wifi-iface.network=lan set wireless.@wifi-iface.mode=ap set wireless.@wifi-iface.ssid=myssid set wireless.@wifi-iface.encryption='psk2+ccmp' set wireless.@wifi-iface.key='mypassword' # set wireless.@wifi-iface.macfilter=allow # add_list wireless.@wifi-iface.maclist=AA:BB:CC:DD:EE:FF # set wireless.@wifi-iface.hidden=1 commit wireless EOF uci batch <<EOF set dhcp.lan.leasetime=12h set dhcp.lan.start=101 set dhcp.lan.limit=99 set dhcp.lan.ra_management=1 add dhcp host set dhcp.@host=host set dhcp.@host.name=Evan-PC set dhcp.@host.mac=11:11:11:11:11:11 set dhcp.@host.ip=192.168.128.2 add dhcp host set dhcp.@host=host set dhcp.@host.name=Evan-phone set dhcp.@host.mac=22:22:22:22:22:22 set dhcp.@host.ip=192.168.128.3 commit dhcp EOF /etc/init.d/dnsmasq restart uci batch <<EOF delete network.globals set network.lan=interface delete network.lan.ifname delete network.lan.type set network.lan.proto=static set network.lan.ipaddr=192.168.128.1 set network.lan.netmask=255.255.255.0 set network.wan=interface set network.wan.ifname=eth0 set network.wan.proto=dhcp set network.wan.macaddr=01:23:45:67:89:AB set network.wan6=interface set network.wan6.proto=6to4 commit network EOF wifi /etc/init.d/network restart uci batch <<EOF set ddns.myddns_ipv4.enabled=1 set ddns.myddns_ipv4.service_name='No-IP.com' set ddns.myddns_ipv4.username=myusername set ddns.myddns_ipv4.password=mypassword set ddns.myddns_ipv4.domain='mydomain.ddns.net' set ddns.myddns_ipv4.ip_source=network set ddns.myddns_ipv4.force_interval=24 set ddns.myddns_ipv4.force_unit=hours set ddns.myddns_ipv4.check_interval=10 set ddns.myddns_ipv4.check_unit=minutes commit ddns EOF /etc/init.d/ddns start /etc/init.d/ddns enable cat <<'EOF' >/root/wakeup.sh #!/bin/sh /usr/bin/etherwake -D -i "eth0.2" "12:34:56:78:90:AB" EOF chmod +x /root/wakeup.sh (crontab -l ; echo '30 6 * * * reboot')| crontab - /etc/init.d/cron start /etc/init.d/cron enable (sleep 10 ; reboot )& exit 0
I don't think you should be rebooting. Very little is run before these scripts are executed. Only /etc/rc.d/S00sysfixtime -> ../init.d/sysfixtime runs before /etc/rc.d/S10boot -> ../init.d/boot which is what runs the uci-defaults scripts. You also need to get rid of starting or restarting services in your script - let them be started normally latter on in the boot.
I got it. I read about the boot process of OpenWrt and now I understand why I should not reboot in a uci-defaults script. I also removed those "starting services", and compiled a new firmware with the modified script. So far I have not encounter any problem.
Thanks everyone for your help!:)
(Last edited by wyf88 on 11 Jan 2016, 17:26)