From c771bf9891fb50f715ae9de7859f821d864cd47d Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Tue, 5 Apr 2022 23:02:02 +0800 Subject: [PATCH] autocore: reduce grep call Signed-off-by: Tianling Shen (cherry picked from commit 7897839f5157a611d04063a111fc9f70995461bc) --- package/emortal/autocore/files/arm/tempinfo | 8 ++++---- package/emortal/autocore/files/generic/cpuinfo | 8 ++++---- package/emortal/autocore/files/x86/autocore | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package/emortal/autocore/files/arm/tempinfo b/package/emortal/autocore/files/arm/tempinfo index 6a16a7a9ed..22877a7e44 100755 --- a/package/emortal/autocore/files/arm/tempinfo +++ b/package/emortal/autocore/files/arm/tempinfo @@ -3,10 +3,6 @@ IEEE_PATH="/sys/class/ieee80211" THERMAL_PATH="/sys/class/thermal" -if [ -e "$IEEE_PATH/phy0/hwmon0/temp1_input" ]; then - mt76_temp=" $(awk -F ': ' '{print $2}' "$IEEE_PATH/phy0/hwmon0/temp1_input")°C" -fi - if grep -Eq "ipq40xx|ipq806x" "/etc/openwrt_release"; then wifi_temp="$(awk '{printf("%.1f°C ", $0 / 1000)}' "$IEEE_PATH"/phy*/device/hwmon/hwmon*/temp1_input | awk '$1=$1')" else @@ -14,6 +10,10 @@ else fi if grep -q "ipq40xx" "/etc/openwrt_release"; then + if [ -e "$IEEE_PATH/phy0/hwmon0/temp1_input" ]; then + mt76_temp=" $(awk -F ': ' '{print $2}' "$IEEE_PATH/phy0/hwmon0/temp1_input")°C" + fi + echo -n "WiFi:${mt76_temp} ${wifi_temp}" else cpu_temp="$(awk '{printf("%.1f°C", $0 / 1000)}' "$THERMAL_PATH/thermal_zone0/temp")" diff --git a/package/emortal/autocore/files/generic/cpuinfo b/package/emortal/autocore/files/generic/cpuinfo index 8ccbcc99b3..e92c0afc41 100755 --- a/package/emortal/autocore/files/generic/cpuinfo +++ b/package/emortal/autocore/files/generic/cpuinfo @@ -6,7 +6,7 @@ CPUINFO_PATH="/proc/cpuinfo" CPUFREQ_PATH="/sys/devices/system/cpu/cpufreq" THERMAL_PATH="/sys/class/thermal" -cpu_arch="$(grep "model name" "$CPUINFO_PATH" | head -n1 | awk -F ': ' '{print $2}' | xargs)" +cpu_arch="$(awk -F ': ' '/model name/ {print $2}' "$CPUINFO_PATH" | head -n1)" [ -n "${cpu_arch}" ] || cpu_arch="?" case "$DISTRIB_TARGET" in @@ -22,9 +22,9 @@ case "$DISTRIB_TARGET" in "bcm53xx"/*) cpu_freq="$(nvram get clkfreq | awk -F ',' '{print $1}')MHz" ;; "mvebu"/*) - cpu_freq="$(grep "BogoMIPS" "$CPUINFO_PATH" | sed -n "1p" | awk -F ': ' '{print $2}')MHz" ;; + cpu_freq="$(awk -F ': ' '/BogoMIPS/ {print $2}' "$CPUINFO_PATH" | head -n1)MHz" ;; "x86"/*) - cpu_freq="$(grep "MHz" "$CPUINFO_PATH" | head -n1 | awk -F ': ' '{print $2}')MHz" + cpu_freq="$(awk -F ': ' '/MHz/ {print $2}' "$CPUINFO_PATH" | head -n1)MHz" ;; *) [ ! -e "$CPUFREQ_PATH/policy0/cpuinfo_cur_freq" ] || \ @@ -41,7 +41,7 @@ case "$DISTRIB_TARGET" in # Intel cpu_temp="$(sensors "coretemp-*" 2>"/dev/null" | grep -E "(Package id |Core )" | grep -Eo "\+[0-9.]*°C" | head -n1 | tr -d "+")" # AMD - [ -n "${cpu_temp}" ] || cpu_temp="$(sensors "k*temp-*" 2>"/dev/null" | grep "Tdie" | head -n1 | awk '{print $2}' | tr -d "+")" + [ -n "${cpu_temp}" ] || cpu_temp="$(sensors "k*temp-*" 2>"/dev/null" | awk '/Tdie/ {print $2}' | head -n1 | tr -d "+")" ;; *) [ ! -e "$THERMAL_PATH/thermal_zone0/temp" ] || \ diff --git a/package/emortal/autocore/files/x86/autocore b/package/emortal/autocore/files/x86/autocore index 471bd773b6..1fcb9dc755 100755 --- a/package/emortal/autocore/files/x86/autocore +++ b/package/emortal/autocore/files/x86/autocore @@ -22,7 +22,7 @@ start() { uci set network.@globals[0].packet_steering="1" uci commit network - for i in $(ip address | grep -E 'eth[0-9]+' | awk -F ': ' '{print $2}' | xargs) + for i in $(ip address | awk -F ': ' '/eth[0-9]+/ {print $2}' | xargs) do { ethtool -K "$i" rx-checksum on