From bb99382e78cc766f87137397450be7dcf9af4dd6 Mon Sep 17 00:00:00 2001 From: nagumii Date: Fri, 17 Jan 2025 18:07:26 +0200 Subject: [PATCH] Complete initial sysinfo release --- .../usr/local/bin/femto-config | 120 +++++++++++------- .../usr/local/bin/femto-meshtasticd-config.sh | 29 +++-- 2 files changed, 94 insertions(+), 55 deletions(-) diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config index 6adb3d8..6ca5aa8 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-config @@ -204,6 +204,7 @@ logging() { fi } +# at some point this will be moved to a different script, and have many functions instead of one giant dump system_info() { local cpu_architecture="armv7l (armhf 32bit)" local cpu_model="Rockchip rv1103 (rev$(awk '/CPU revision/ {print $4}' /proc/cpuinfo))" @@ -214,16 +215,35 @@ 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 system_uptime="$(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')" + local logging_enabled="$(logging "check" | sed 's/\x1b\[[0-9;]*m//g')" 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="\ + local wifi_status="$(replace_colors "$(femto-network-config.sh -w | grep -v '^$' | grep -v '^Hostname')")" #remove hostname line, as it's identical to the one in ethernet settings + local eth_status="$(replace_colors "$(femto-network-config.sh -e)")" + local usb_devices="$(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"}')" + local kernel_modules_active="$(lsmod | awk 'NR>1 {print $1}' | tr '\n' ' ' && echo)" + local lora_radio="$(replace_colors "$(femto-meshtasticd-config.sh -k)")" + local meshtasticd_service_status="$(replace_colors "$(femto-meshtasticd-config.sh -S)")" + local meshtasticd_info="$(replace_colors "$(femto-meshtasticd-config.sh -i)")" + local usb_mode="$(cat /sys/devices/platform/ff3e0000.usb2-phy/otg_mode)" + local spi0_state="$([ "$(awk -F= '/^SPI0_M0_STATUS/ {print $2}' /etc/luckfox.cfg)" -eq 1 ] && echo "enabled" || echo "disabled")" + local spi0_speed="$((0x$(xxd -p /sys/firmware/devicetree/base/spi@ff500000/spidev@0/spi-max-frequency | tr -d '\n')))" + local i2c3_state="$([ "$(awk -F= '/^I2C3_M1_STATUS/ {print $2}' /etc/luckfox.cfg)" -eq 1 ] && echo "enabled" || echo "disabled")" + local i2c3_speed="$(awk -F= '/^I2C3_M1_SPEED/ {print $2}' /etc/luckfox.cfg)" + local uart3_state="$([ "$(awk -F= '/^UART3_M1_STATUS/ {print $2}' /etc/luckfox.cfg)" -eq 1 ] && echo "enabled" || echo "disabled")" + local uart4_state="$([ "$(awk -F= '/^UART4_M1_STATUS/ {print $2}' /etc/luckfox.cfg)" -eq 1 ] && echo "enabled" || echo "disabled")" + + echo -e "\ Femtofox\n\ Core: Luckfox Pico Mini\n\ Operating System: $os_version\n\ -Kernel Version: $(uname -r)\n\ -Uptime: $(uptime -p | awk '{$1=""; print $0}' | sed -e 's/ day\b/d/g' -e 's/ hour\b/h/g' -e 's/ hours\b/h/g' -e 's/ minute\b/m/g' -e 's/ minutes\b/m/g' | sed 's/,//g')\n\ -Logging: $(logging "check" | sed 's/\x1b\[[0-9;]*m//g')\n\ +Kernel version: $(uname -r)\n\ +Uptime: $system_uptime\n\ +Logging: $logging_enabled\n\ System time: $(date)\n\ +K modules active: $kernel_modules_active\n\ +K boot modules: $boot_modules\n\ \n\ CPU:\n\ Architecture: $cpu_architecture\n\ @@ -239,25 +259,28 @@ Swap: $swap\n\ $mounted_drives\n\ \n\ Networking (wlan0 & eth0):\n\ -$(replace_colors "$(femto-network-config.sh -w | grep -v '^$' | grep -v '^MAC Address')")\n\ +$wifi_status\n\ --- -$(replace_colors "$(femto-network-config.sh -e)")\n\ +$eth_status\n\ +\n\ + Interfaces:\n\ +USB mode: $usb_mode\n\ +SPI-0 state: $spi0_state\n\ +SPI-0 speed: $spi0_speed\n\ +i2c-3 state: $i2c3_state\n\ +i2c-3 speed: $i2c3_speed\n\ +UART-3 state: $uart3_state\n\ +UART-4 state: $uart4_state\n\ \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\ +LoRa radio: $lora_radio\n\ +$usb_devices\n\ i2c devices: $i2c_addresses\n\ -\n\ - Kernel: -Version: $(uname -r) -Modules active: $(lsmod | awk 'NR>1 {print $1}' | tr '\n' ' ' && echo)\n\ -Boot modules: $boot_modules\n\ \n\ Meshtasticd:\n\ -Service status: $(replace_colors "$(femto-meshtasticd-config.sh -S)")\n\ -$(replace_colors "$(femto-meshtasticd-config.sh -i)")\ +Service status: $meshtasticd_service_status\n\ +$meshtasticd_info\ " -echo -e "$info" } # utilities @@ -391,22 +414,23 @@ meshtasticd_settings() { while true; do echo "Checking Meshtasticd service state..." local option="" - option=$(dialog --no-collapse --colors --title "$title" --cancel-label "Back" --menu "Meshtasticd service is $(replace_colors "$(femto-meshtasticd-config.sh -S)")$(femto-meshtasticd-config.sh -k | grep -q 'simulated' && echo '\n\Z1Using simulated radio\Zn')" 22 50 4 \ - 1 "View configuration URL & QR code" \ - 2 "Set new configuration URL" \ - 3 "Set LoRa radio" \ - 4 "View admin keys" \ - 5 "Set admin key" \ - 6 "Clear admin keys" \ - 7 "Legacy admin channel" \ - 8 "Detailed Meshtasticd service status" \ - 9 "Mesh connectivity test" \ - 10 "Start/restart Meshtasticd service" \ - 11 "Stop Meshtasticd service" \ - 12 "Upgrade/install Meshtasticd" \ - 13 "Uninstall Meshtasticd" \ + option=$(dialog --no-collapse --colors --title "$title" --cancel-label "Back" --menu "Meshtasticd service is $(replace_colors "$(femto-meshtasticd-config.sh -S)")$(femto-meshtasticd-config.sh -k | grep -q 'simulated' && echo '\n\Z1Using simulated radio\Zn')" 23 50 4 \ + 1 "View node info" \ + 2 "View configuration URL & QR code" \ + 3 "Set new configuration URL" \ + 4 "Set LoRa radio" \ + 5 "View admin keys" \ + 6 "Set admin key" \ + 7 "Clear admin keys" \ + 8 "Legacy admin channel" \ + 9 "Detailed Meshtasticd service status" \ + 10 "Mesh connectivity test" \ + 11 "Start/restart Meshtasticd service" \ + 12 "Stop Meshtasticd service" \ + 13 "Upgrade/install Meshtasticd" \ + 14 "Uninstall Meshtasticd" \ "" "" \ - 14 "Back to Main Menu" 3>&1 1>&2 2>&3) + 15 "Back to Main Menu" 3>&1 1>&2 2>&3) exit_status=$? # This line checks the exit status of the dialog command if [ $exit_status -ne 0 ]; then # Exit the loop if the user selects "Cancel" or closes the dialog @@ -414,12 +438,16 @@ meshtasticd_settings() { fi case $option in - 1) #Get current configuration URL & QR code) + 1) #View node info) + dialog --no-collapse --infobox "Getting Node info..." 5 45 + dialog --no-collapse --colors --title "Node info" --msgbox "$(replace_colors "$(femto-meshtasticd-config.sh -i)")" 0 0 + ;; + 2) #Get current configuration URL & QR code) dialog --no-collapse --infobox "Getting Meshtastic QR code and URL..." 5 45 femto-meshtasticd-config.sh -g pause ;; - 2) + 3) newurl=$(dialog --no-collapse --title "Meshtastic URL" --inputbox "New Meshtasticd URL (SHIFT+INS to paste):" 8 60 3>&1 1>&2 2>&3) if [ -n "$newurl" ]; then #if a URL was entered dialog --no-collapse --title "$title" --yesno "New Meshtasticd URL:\n$newurl\n\nConfirm?" 15 60 @@ -429,28 +457,28 @@ meshtasticd_settings() { fi fi ;; - 3) + 4) set_lora_radio ;; - 4) + 5) dialog --no-collapse --infobox "Getting admin keys..." 5 45 dialog --no-collapse --title "Admin keys" --msgbox "Up to 3 admin keys are permitted, more will be ignored.\n\nKeys:$(femto-meshtasticd-config.sh -v | tail -n 1 | sed 's/|n/\\n/g')" 0 0 ;; - 5) #set admin key) + 6) #set admin key) key=$(dialog --no-collapse --title "Meshtastic Admin Key" --inputbox "Meshtastic admin key - up to 3, more will be ignored.\n\n(SHIFT+INS to paste):" 11 40 3>&1 1>&2 2>&3) if [ -n "$key" ]; then #if a URL was entered femto-meshtasticd-config.sh -a "$key" pause fi ;; - 6) + 7) dialog --no-collapse --title "$title" --yesno "Meshtasticd can have up to 3 admin keys.\nClear admin key list?" 0 0 if [ $? -eq 0 ]; then #unless cancel/no femto-meshtasticd-config.sh -c pause fi ;; - 7) #legacy admin) + 8) #legacy admin) dialog --no-collapse --infobox "Getting current legacy admin state..." 5 45 state=$(sudo femto-meshtasticd-config.sh -p) if echo "$state" | grep -q "True"; then @@ -474,46 +502,46 @@ meshtasticd_settings() { esac done ;; - 8) #check meshtasticd service status) + 9) #check meshtasticd service status) dialog --no-collapse --infobox "Getting Meshtasticd service status..." 5 45 dialog --no-collapse --title "Meshtasticd service status" --msgbox "$(systemctl status meshtasticd)" 0 0 ;; - 9) #test mesh connectivity) + 10) #test mesh connectivity) dialog --no-collapse --title "Meshtastic connectivity test" --yesno "Will send \"test\" to channel 0 and wait for acknowledgement. Will try up to 3 times.\n\nPerform test?" 10 45 if [ $? -eq 0 ]; then #unless cancel/no dialog --no-collapse --infobox "Performing mesh connectivity test.\n\nThis may take a while..." 6 45 - dialog --no-collapse --title "Meshtasticd service status" --msgbox "$(femto-meshtasticd-config.sh -r)" 0 0 + dialog --no-collapse --colors --title "Meshtasticd service status" --msgbox "$(replace_colors "$(femto-meshtasticd-config.sh -r)")" 0 0 fi ;; - 10) #start/restart meshtasticd) + 11) #start/restart meshtasticd) dialog --no-collapse --title "$title" --yesno "Start/restart Meshtasticd service?" 5 45 if [ $? -eq 0 ]; then #unless cancel/no femto-meshtasticd-config.sh -s dialog --no-collapse --msgbox "Meshtasticd service started/restarted." 5 45 fi ;; - 11) #stop meshtasticd) + 12) #stop meshtasticd) dialog --no-collapse --title "$title" --yesno "Stop Meshtasticd service?" 5 45 if [ $? -eq 0 ]; then #unless cancel/no femto-meshtasticd-config.sh -t dialog --no-collapse --msgbox "Meshtasticd service stopped." 5 45 fi ;; - 12) #Upgrade meshtasticd) + 13) #Upgrade meshtasticd) dialog --no-collapse --title "$title" --yesno "Upgrade Meshtasticd?\nRequires internet connection." 0 0 if [ $? -eq 0 ]; then #unless cancel/no femto-meshtasticd-config.sh -u pause fi ;; - 13) #uninstall meshtasticd) + 14) #uninstall meshtasticd) dialog --no-collapse --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed." 0 0 if [ $? -eq 0 ]; then femto-meshtasticd-config.sh -x dialog --no-collapse --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`sudo apt purge\`.\nAfter reinstallation but before first launch, run the \"first boot script\" from the misc menu." 8 40 fi ;; - 14) + 15) return ;; esac diff --git a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-meshtasticd-config.sh b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-meshtasticd-config.sh index 34c190a..6d8328e 100755 --- a/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-meshtasticd-config.sh +++ b/foxbuntu/sysdrv/out/rootfs_uclibc_rv1106/usr/local/bin/femto-meshtasticd-config.sh @@ -77,18 +77,29 @@ while getopts ":higkl:q:va:cpo:sStruxm" opt; do ;; i) # Option -i (Get important node info) output=$(meshtastic --host --info) + preset_or_settings="Use preset? $(echo "$output" | grep -oP '"usePreset":\s*\K\w+')\n" + if echo "$output" | grep -qP '"usePreset":\s*true'; then + preset_or_settings+="Preset: $(echo "$output" | grep -oP '"modemPreset":\s*"\K[^"]+')" + else + preset_or_settings+="\ +Bandwidth: $(echo "$output" | grep -oP '"bandwidth":\s*\K\w+')\n\ +Spread factor: $(echo "$output" | grep -oP '"spreadFactor":\s*\K\w+')\n\ +Coding rate: $(echo "$output" | grep -oP '"codingRate":\s*\K\w+')" + fi 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 "%08x\n" $(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1)) ($(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1))\n\ +NodeID: !$(printf "%08x\n" $(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1)) (nodenum: $(echo "$output" | grep -oP '"myNodeNum":\s*\K\d+' | head -n 1))\n\ TX enabled? $(txEnabled=$(echo "$output" | grep -oP '"txEnabled":\s*\K\w+'); [[ "$txEnabled" == "true" ]] && echo "\033[0;34menabled\033[0m" || echo "\033[0;31mdisabled\033[0m")\n\ Role: $(echo "$output" | grep -oP '"role":\s*"\K[^"]+' | head -n 1)\n\ -Preset: $(echo "$output" | grep -oP '"modemPreset":\s*"\K[^"]+')\n\ +$preset_or_settings\n\ +Frequency offset: $(echo "$output" | grep -oP '"bandwidth":\s*\K\w+') 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)\ +Hop limit: $(echo "$output" | grep -oP '"hopLimit":\s*\K\w+')\n\ +$(channelNum=$(echo "$output" | grep -oP '"channelNum":\s*\K\d+' | head -n 1); [[ -n "$channelNum" && "$channelNum" -gt 0 ]] && echo -e "Frequency slot: $channelNum\n")\ +$(overrideFrequency=$(echo "$output" | grep -oP '"overrideFrequency":\s*\K[0-9.]+'); [[ -n "$overrideFrequency" && $(echo "$overrideFrequency > 0" | bc) -eq 1 ]] && echo "Override freq: $overrideFrequency\n")\ +Public key: $(echo "$output" | grep -oP '"publicKey":\s*"\K[^"]+' | head -n 1)\n\ +Nodes in nodedb: $(echo "$output" | grep -oP '"![a-zA-Z0-9]+":\s*\{' | wc -l)\ " ;; g) # Option -g (get config URL) @@ -145,13 +156,13 @@ Public key: $(echo "$output" | grep -oP '"publicKey":\s*"\K[^"]+' | head - r) # Option -r (mesh connectivity test) for ((i=0; i<=2; i++)); do if meshtastic --host --ch-index 0 --sendtext "test" --ack 2>/dev/null | grep -q "ACK"; then - echo "Received acknowledgement!" + echo -e "Received acknowledgement...\n\n\033[0;34mMesh connectivity confirmed!\033[0m" exit 0 else - echo "Retrying... ($((i + 1)))" + echo "No response, retrying... ($((i + 1)))" fi done - echo "Failed after 3 attempts." + echo -e "\033[0;31mFailed after 3 attempts.\033[0m" ;; s) # Option -s (start/restart Meshtasticd service) systemctl restart meshtasticd