Files
emcomm-tools-os-community/overlay/opt/emcomm-tools/bin/et-system-info
T

114 lines
2.6 KiB
Bash
Raw Normal View History

#!/bin/bash
#
# Author : Gaston Gonzalez
# Date : 6 October 2024
# Updated : 11 October 2024
# Purpose : Utility script for dumping system information
function usage() {
echo "Usage: $(basename $0) <command>"
echo " active-radio - Display model of active radio"
echo " et-cat - Is CAT control connected"
echo " et-gps - Is the GPS connected"
echo " ip - System IP address"
echo " release - EmComm Tools Release"
}
if [ $# -ne 1 ]; then
usage
exit 1
fi
case $1 in
active-radio)
if [ -L "${ET_HOME}/conf/radios.d/active-radio.json" ]; then
cat "${ET_HOME}/conf/radios.d/active-radio.json" | jq -r .model
else
echo "No radio selected"
fi
;;
et-cat)
if [ ! -L "${ET_HOME}/conf/radios.d/active-radio.json" ]; then
echo "N/A"
exit 0
fi
# 1. Check if the symlink was created by the udev rules
if [ -e /dev/et-cat ]; then
# 2. Check if the rigctl systemd unit is running properly
systemctl status rigctld --no-pager > /dev/null
if [ $? -eq 0 ]; then
# 3. Grab and format frequency
FREQ=$(timeout 1 rigctl -m 2 f)
if [ $? -eq 0 ]; then
printf "%'d MHz\n" "$FREQ" | sed 's|,|.|g'
else
echo "Connected. Can't access VFO";
fi
else
echo "Connected. rigctld not running"
fi
else
echo "Not connected";
fi
;;
et-gps)
# 1. Check if the symlink was created by the udev rules
if [ -e /dev/et-gps ]; then
# 2. Check if the gpsd systemd unit is running properly
systemctl status gpsd --no-pager > /dev/null
if [ $? -eq 0 ]; then
# 3. Obtain the current GPS mode
2024-10-11 12:38:04 -07:00
GPS_JSON=$(gpspipe -w -n 10 | grep -m 1 TPV)
if [ $? -eq 0 ]; then
2024-10-11 12:38:04 -07:00
GPS_MODE=$(echo $GPS_JSON | jq --exit-status -r .mode)
case $GPS_MODE in
2024-10-11 12:20:24 -07:00
1)
echo "No fix"
;;
2024-10-11 12:20:24 -07:00
2)
echo "2D fix"
;;
2024-10-11 12:20:24 -07:00
3)
2024-10-11 12:38:04 -07:00
LAT=$(echo $GPS_JSON | jq -r .lat)
LON=$(echo $GPS_JSON | jq -r .lon)
printf "%.5f,%.5f\n" $LAT $LON
;;
*)
2024-10-11 12:20:24 -07:00
echo "Unknown mode"
;;
esac
else
echo "Connected. Can't decode"
fi
else
echo "Connected. gpsd not running"
fi
else
echo "Not connected"
fi
;;
ip)
hostname -I
;;
release)
grep DISTRIB_DESCRIPTION /etc/lsb-release | sed 's|"||g' | awk '{print $1}' | cut -d"=" -f2
;;
*)
echo "Command not supported."
usage
exit 1
;;
esac