continued work on sysinfo

This commit is contained in:
nagumii 2025-01-16 23:49:56 +02:00
parent 10e6cc4c22
commit 634ce2307f
2 changed files with 28 additions and 7 deletions

View file

@ -205,7 +205,6 @@ logging() {
}
system_info() {
local cpu_architecture="armv7l (armhf 32bit)"
local cpu_model="Rockchip rv1103 (rev$(awk '/CPU revision/ {print $4}' /proc/cpuinfo))"
local cpu_serial="$(awk '/Serial/ {print $3}' /proc/cpuinfo)"
@ -215,6 +214,8 @@ system_info() {
local swap="$(free -m | awk 'NR==3{printf "%d MB (%.2f%% free)", $2, ($4/$2)*100}')"
local mounted_drives="$([ "$(for dir in /mnt/*/; do echo -n "/mnt${dir#"/mnt"} "; done)" ] && echo "Mounted drives: $(for dir in /mnt/*; do echo -n "/mnt${dir#"/mnt"} "; done | sed 's/\/$//')")"
local os_version="Foxbuntu v$(grep -oP 'major=\K[0-9]+' /etc/foxbuntu-release).$(grep -oP 'minor=\K[0-9]+' /etc/foxbuntu-release)$(output=$(grep -o 'patch=[1-9][0-9]*' /etc/foxbuntu-release | cut -d= -f2) && [ -n "$output" ] && echo ".$output")$(grep -oP 'hotfix=\K[a-z]+' /etc/foxbuntu-release) ($(lsb_release -d | awk -F'\t' '{print $2}') $(lsb_release -c | awk -F'\t' '{print $2}'))"
local boot_modules="$(modules=$(sed -n '6,$p' /etc/modules | sed ':a;N;$!ba;s/\n/, /g;s/, $//'); [ -z "$modules" ] && echo "none" || echo "$modules")"
local i2c_addresses="$(i2cdetect -y 3 | awk 'NR>1 {for(i=2;i<=17;i++) if ($i == "ff" || $i == "UU") { printf "0x%02x ", (i-2) + (NR-2)*16} }' | tr -d '\n' )"
local info="\
Femtofox\n\
Core: Luckfox Pico Mini\n\
@ -237,7 +238,7 @@ Memory: $memory\n\
Swap: $swap\n\
$mounted_drives\n\
\n\
Networking (wlan0 & eth0 only):\n\
Networking (wlan0 & eth0):\n\
$(replace_colors "$(femto-network-config.sh -w | grep -v '^$' | grep -v '^MAC Address')")\n\
---
$(replace_colors "$(femto-network-config.sh -e)")\n\
@ -245,11 +246,15 @@ $(replace_colors "$(femto-network-config.sh -e)")\n\
Attached devices:\n\
LoRa radio: $(replace_colors "$(femto-meshtasticd-config.sh -k)")\n\
$(lsusb | grep -v 'root hub' | awk 'NR>0{printf "USB: "; for(i=7;i<=NF;i++) printf "%s ", $i; print ""} END {if (NR == 0) printf "USB: None detected"}')\n\
i2c devices: $(i2cdetect -y 3 | awk 'NR>1 {for(i=2;i<=17;i++) if ($i == "ff" || $i == "UU") { printf "0x%02x ", (i-2) + (NR-2)*16} }' | tr -d '\n' )\n\
i2c devices: $i2c_addresses\n\
\n\
Kernel:
Modules active: $(lsmod | awk 'NR>1 {print $1}' | tr '\n' ' ' && echo)\n\
Boot modules: $(modules=$(sed -n '6,$p' /etc/modules | sed ':a;N;$!ba;s/\n/, /g;s/, $//'); [ -z "$modules" ] && echo "none" || echo "$modules")\
Boot modules: $boot_modules\n\
\n\
Meshtasticd:\n\
Service status: $(femto-meshtasticd-config.sh -S)\n\
$(femto-meshtasticd-config.sh -i)\
"
echo -e "$info"
}

View file

@ -7,6 +7,7 @@ fi
help=$(cat <<EOF
Options are:
-h This message
-i Get important node info
-g Gets the current configuration URL and QR code
-k Get current LoRa radio selection
-l "RADIO" Choose LoRa radio model. Options are \`lr1121_tcxo\`, \`sx1262_tcxo\`, \`sx1262_xtal\`, \`none\` (simradio)
@ -69,11 +70,26 @@ meshtastic_update() {
}
# Parse options
while getopts ":hgkl:q:va:cpo:sStruxm" opt; do
while getopts ":higkl:q:va:cpo:sStruxm" opt; do
case ${opt} in
h) # Option -h (help)
echo -e "$help"
;;
i) # Option -i (Get important node info)
output=$(meshtastic --host --info)
echo -e "\
Version: $(echo "$output" | grep -oP '"firmwareVersion":\s*"\K[^"]+' | head -n 1)\n\
Node name: $(echo "$output" | grep -oP 'Owner:\s*\K.*' | head -n 1)\n\
NodeID: $(printf "%X\n" $(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1) | tr '[:upper:]' '[:lower:]') ($(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1))\n\
Role: $(echo "$output" | grep -oP '"role":\s*"\K[^"]+' | head -n 1)\n\
Preset: $(echo "$output" | grep -oP '"modemPreset":\s*"\K[^"]+')\n\
Region: $(echo "$output" | grep -oP '"region":\s*"\K[^"]+')\n\
$(channelNum=$(echo "$output" | grep -oP '"channelNum":\s*\K\d+' | head -n 1); [[ -n "$channelNum" && "$channelNum" -gt 0 ]] && echo -e "Frequency slot: $channelNum")
$(overrideFrequency=$(echo "$output" | grep -oP '"overrideFrequency":\s*\K[0-9.]+'); [[ -n "$overrideFrequency" && $(echo "$overrideFrequency > 0" | bc) -eq 1 ]] && echo -e "Override freq: $overrideFrequency")\n\
Uptime: $(echo "$output" | grep -oP '"uptimeSeconds":\s*\K\d+' | head -n 1 | awk '{days=int($1/86400); hrs=int(($1%86400)/3600); mins=int(($1%3600)/60); secs=int($1%60); printf "%d days %02d:%02d:%02d\n", days, hrs, mins, secs}')\n\
Public key: $(echo "$output" | grep -oP '"publicKey":\s*"\K[^"]+' | head -n 1)\
"
;;
g) # Option -g (get config URL)
url=$(meshtastic --host --qr-all | grep -oP '(?<=Complete URL \(includes all channels\): )https://[^ ]+') #add look for errors
clear
@ -142,9 +158,9 @@ while getopts ":hgkl:q:va:cpo:sStruxm" opt; do
;;
S) # Option -S (Get Meshtasticd Service state)
if echo "$(systemctl status meshtasticd)" | grep -q "active (running)"; then
echo -e "\033[4m\033[0;34monline\033[0m"
echo -e "\033[4m\033[0;34mrunning\033[0m"
elif echo "$(systemctl status meshtasticd)" | grep -q "inactive (dead)"; then
echo -e "\033[4m\033[0;31moffline\033[0m"
echo -e "\033[4m\033[0;31mnot running\033[0m"
else
echo "unknown"
fi