From 1533639d0c47e969c10f6951b57a5cc227aeceb5 Mon Sep 17 00:00:00 2001 From: kzolotarev95 Date: Thu, 30 Jul 2026 19:49:44 +0400 Subject: [PATCH] Fix flash metric detection with external disks --- files/usr/sbin/owrt-remote | 55 +++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/files/usr/sbin/owrt-remote b/files/usr/sbin/owrt-remote index 8386426..9f0fafd 100644 --- a/files/usr/sbin/owrt-remote +++ b/files/usr/sbin/owrt-remote @@ -134,17 +134,60 @@ memory_text() { flash_text() { local mount text - for mount in /overlay /; do + text="$( + df -kP 2>/dev/null | awk ' + function mb(k) { + if (k == "" || k == 0) return "0 MB" + return sprintf("%.1f MB", k / 1024) + } + NR == 1 { next } + { + mount = $NF + total = $(NF-4) + avail = $(NF-2) + pct = $(NF-1) + gsub(/%/, "", pct) + if (total !~ /^[0-9]+$/ || avail !~ /^[0-9]+$/ || pct !~ /^[0-9]+$/) next + + score = 0 + if (mount == "/overlay" || mount == "/rom/overlay") score = 400 + else if (mount == "/") score = 300 + else if ($1 == "overlayfs:/overlay") score = 250 + else if (mount ~ /^\/overlay(\/|$)/) score = 200 + if (score <= best_score) next + + best_score = score + best_total = total + best_avail = avail + best_pct = pct + } + END { + if (best_score > 0) { + printf "%s free / %s (%s%% used)", mb(best_avail), mb(best_total), best_pct + } + } + ' + )" + if [ -n "$text" ]; then + printf '%s' "$text" + return + fi + for mount in /overlay /rom/overlay /; do text="$( - df -k "$mount" 2>/dev/null | awk ' + df -kP "$mount" 2>/dev/null | awk ' function mb(k) { if (k == "" || k == 0) return "0 MB" return sprintf("%.1f MB", k / 1024) } - END { - if (NF >= 5) { - total=$(NF-4); avail=$(NF-2); pct=$(NF-1) - printf "%s free / %s (%s used)", mb(avail), mb(total), pct + NR == 1 { next } + NF >= 5 { + total = $(NF-4) + avail = $(NF-2) + pct = $(NF-1) + gsub(/%/, "", pct) + if (total ~ /^[0-9]+$/ && avail ~ /^[0-9]+$/ && pct ~ /^[0-9]+$/) { + printf "%s free / %s (%s%% used)", mb(avail), mb(total), pct + exit } } '