فهرست منبع

base-files: add 'isup' to the wifi script

This is a silent command that allows easy wifi up/down automation for
scripts.

It takes one or multiple devices as arguments (or all if none are passed),
and the exit code indicates if any of those is not up.

E.g.:
wifi isup && echo "all wifi devices are up"
wifi isup radio0 || echo "this wifi is down"

Signed-off-by: Andre Heider <[email protected]>
Andre Heider 3 سال پیش
والد
کامیت
28e357d528
1فایلهای تغییر یافته به همراه18 افزوده شده و 1 حذف شده
  1. 18 1
      package/base-files/files/sbin/wifi

+ 18 - 1
package/base-files/files/sbin/wifi

@@ -6,7 +6,7 @@
 
 
 usage() {
 usage() {
 	cat <<EOF
 	cat <<EOF
-Usage: $0 [config|up|down|reconf|reload|status]
+Usage: $0 [config|up|down|reconf|reload|status|isup]
 enables (default), disables or configures devices not yet configured.
 enables (default), disables or configures devices not yet configured.
 EOF
 EOF
 	exit 1
 	exit 1
@@ -21,6 +21,22 @@ ubus_wifi_cmd() {
 	ubus call network.wireless "$cmd" "$(json_dump)"
 	ubus call network.wireless "$cmd" "$(json_dump)"
 }
 }
 
 
+wifi_isup() {
+	local dev="$1"
+
+	json_load "$(ubus_wifi_cmd "status" "$dev")"
+	json_get_keys devices
+
+	for device in $devices; do
+		json_select "$device"
+			json_get_var up up
+			[ $up -eq 0 ] && return 1
+		json_select ..
+	done
+
+	return 0
+}
+
 find_net_config() {(
 find_net_config() {(
 	local vif="$1"
 	local vif="$1"
 	local cfg
 	local cfg
@@ -245,6 +261,7 @@ case "$1" in
 	detect) wifi_detect_notice ;;
 	detect) wifi_detect_notice ;;
 	config) wifi_config ;;
 	config) wifi_config ;;
 	status) ubus_wifi_cmd "status" "$2";;
 	status) ubus_wifi_cmd "status" "$2";;
+	isup) wifi_isup "$2"; exit $?;;
 	reload) wifi_reload "$2";;
 	reload) wifi_reload "$2";;
 	reload_legacy) wifi_reload_legacy "$2";;
 	reload_legacy) wifi_reload_legacy "$2";;
 	--help|help) usage;;
 	--help|help) usage;;