From 5deb893df621f1b9bf993b631006cf3ba5e63a25 Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Wed, 27 Jul 2022 18:54:38 -0700 Subject: [PATCH] apinger-pop for rc.local Dealing with a race condition that comes up when there is NOT a dhcpd server on the network. This causes the apinger template to never become populated and thus the wifi radios remain up. Adding the apinger template to default once to 8.8.8.8 regardless of being triggered from the dhcp client. Additionally, there seems to be a second race condition that if the wireless radio is brought down too early in the startup process it doesnt actually power down the radios. It leaves them in a weird state of radios are up, leds are on, but the wifi cli tool thinks there off. --- openwrt/Makefile | 1 + openwrt/files/etc/rc.local | 7 +++++++ openwrt/files/etc/udhcpc.user | 7 +------ openwrt/files/root/bin/apinger-pop.sh | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100755 openwrt/files/root/bin/apinger-pop.sh diff --git a/openwrt/Makefile b/openwrt/Makefile index e6c6421b..102c5457 100644 --- a/openwrt/Makefile +++ b/openwrt/Makefile @@ -119,6 +119,7 @@ endif # TODO: should do this automatically for .sh file types chmod 750 $(TMPL_OUT_DIR)/root/bin/config-version.sh chmod 750 $(TMPL_OUT_DIR)/root/bin/wifi-details.sh + chmod 750 $(TMPL_OUT_DIR)/root/bin/apinger-pop.sh chmod 755 $(TMPL_OUT_DIR)/root chmod 700 $(TMPL_OUT_DIR)/root/.ssh chmod 640 $(TMPL_OUT_DIR)/root/.ssh/authorized_keys diff --git a/openwrt/files/etc/rc.local b/openwrt/files/etc/rc.local index d439fdf1..018486ff 100644 --- a/openwrt/files/etc/rc.local +++ b/openwrt/files/etc/rc.local @@ -4,4 +4,11 @@ # TODO make this a true service /root/bin/wifi-details.sh >/dev/null 2>/dev/null /dev/null & + exit 0 diff --git a/openwrt/files/etc/udhcpc.user b/openwrt/files/etc/udhcpc.user index df6a8965..e2c007cd 100644 --- a/openwrt/files/etc/udhcpc.user +++ b/openwrt/files/etc/udhcpc.user @@ -18,12 +18,7 @@ case "$1" in # apinger template population if [ ! -z "$router" ]; then - sed "s//$router/g" /etc/apinger.tmpl > /tmp/apinger.conf - # Only restart apinger if compare has diff - if ! cmp /tmp/apinger.conf /etc/apinger.conf; then - # Cant use "service" since thats a shell function - cp /tmp/apinger.conf /etc/apinger.conf && /etc/init.d/apinger restart - fi + /root/bin/apinger-pop.sh "$router" fi if [ ! -z "$hostname" ]; then diff --git a/openwrt/files/root/bin/apinger-pop.sh b/openwrt/files/root/bin/apinger-pop.sh new file mode 100755 index 00000000..39b6c588 --- /dev/null +++ b/openwrt/files/root/bin/apinger-pop.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ -z ${1} ]; then + echo "[ERROR] require arg for setting the gateway" + exit 1 +fi + +sed "s//${1}/g" /etc/apinger.tmpl > /tmp/apinger.conf +# Only restart apinger if compare has diff +if ! cmp /tmp/apinger.conf /etc/apinger.conf; then + # Cant use "service" since thats a shell function + sleep 5 + cp /tmp/apinger.conf /etc/apinger.conf && /etc/init.d/apinger restart +fi