From 82d3e9686ddb5c549e726c434505fa43d71b4e2b Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 21 Feb 2023 11:17:54 +0000 Subject: [PATCH] sane-ip-check: set exit code based on if we get IP or not --- pkgs/sane-scripts/src/sane-ip-check | 5 +++-- pkgs/sane-scripts/src/sane-ip-check-router-wan | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkgs/sane-scripts/src/sane-ip-check b/pkgs/sane-scripts/src/sane-ip-check index cfac2622..708a69dd 100755 --- a/pkgs/sane-scripts/src/sane-ip-check +++ b/pkgs/sane-scripts/src/sane-ip-check @@ -1,3 +1,4 @@ #!/usr/bin/env bash -curl https://ipinfo.io/ip -echo +ip=$(curl --silent https://ipinfo.io/ip) +echo "$ip" | grep -P " *^\d+\.\d+\.\d+\.\d+ *$" +exit $? diff --git a/pkgs/sane-scripts/src/sane-ip-check-router-wan b/pkgs/sane-scripts/src/sane-ip-check-router-wan index 555fabd5..94b1e3b9 100755 --- a/pkgs/sane-scripts/src/sane-ip-check-router-wan +++ b/pkgs/sane-scripts/src/sane-ip-check-router-wan @@ -3,13 +3,16 @@ # requires creds passwd=$(sudo cat /run/secrets/router_passwd) cookie=$(mktemp) +curlflags="curl --silent --insecure --cookie-jar $cookie --connect-timeout 5" # authenticate -curl -s --insecure --cookie-jar $cookie \ +curl $curlflags \ --data "username=admin&password=$passwd" \ https://192.168.0.1 # query the WAN IP -curl -s --insecure --cookie $cookie \ +ip=$(curl $curlflags \ -H "X-Requested-With: XMLHttpRequest" \ "https://192.168.0.1/cgi/cgi_action?Action=GetConnectionStatus" \ - | jq -r .wan_status.ipaddr + | jq -r .wan_status.ipaddr) +echo "$ip" | grep -P " *^\d+\.\d+\.\d+\.\d+ *$" +exit $?