mirror of
https://github.com/thetechprepper/emcomm-tools-os-community.git
synced 2026-09-17 15:41:44 -04:00
UX - Updated the et-radio command to use an ncurses interface for selecting the active radio
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Author : Gaston Gonzalez
|
# Author : Gaston Gonzalez
|
||||||
# Date : 11 October 2024
|
# Date : 11 October 2024
|
||||||
# Updated : 12 October 2024
|
# Updated : 16 October 2024
|
||||||
# Purpose : A script for managaing plug-and-play radios
|
# Purpose : A script for managaing plug-and-play radios
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ function usage() {
|
|||||||
echo "Usage: $(basename $0) <command>"
|
echo "Usage: $(basename $0) <command>"
|
||||||
echo " active - show active radio"
|
echo " active - show active radio"
|
||||||
echo " list - list supported radios by id"
|
echo " list - list supported radios by id"
|
||||||
echo " set <radio id> - set radio as active by id"
|
echo " set - select active radio"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -lt 1 ]; then
|
if [ $# -lt 1 ]; then
|
||||||
@@ -35,20 +35,30 @@ case $1 in
|
|||||||
|
|
||||||
;;
|
;;
|
||||||
set)
|
set)
|
||||||
if [ $# -ne 2 ]; then
|
|
||||||
echo "Radio ID required. Run '$(basename $0) list' to get list of radios"
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
RADIO_CONF="${ET_HOME}/conf/radios.d/$2.json"
|
options=()
|
||||||
if [ ! -e ${RADIO_CONF} ]; then
|
while IFS= read -r radio; do
|
||||||
echo "Radio configuration does not exist for radio ID: '$2'"
|
ID=$(cat $radio | jq -r .id)
|
||||||
exit 1
|
VENDOR=$(cat $radio | jq -r .vendor)
|
||||||
fi
|
MODEL=$(cat $radio | jq -r .model)
|
||||||
|
|
||||||
[ -e ${ACTIVE_RADIO} ] && rm ${ACTIVE_RADIO}
|
options+=("$ID" "$VENDOR $MODEL")
|
||||||
ln -s ${RADIO_CONF} ${ACTIVE_RADIO}
|
done < <(find $ET_HOME/conf/radios.d -type f | sort)
|
||||||
|
|
||||||
|
selected_radio=$(dialog --clear --menu "Select a radio:" 15 50 10 "${options[@]}" 3>&1 1>&2 2>&3)
|
||||||
|
exit_status=$?
|
||||||
|
|
||||||
|
# Reset terminal to its original state
|
||||||
|
clear && tput sgr0
|
||||||
|
|
||||||
|
if [ $exit_status -eq 0 ]; then
|
||||||
|
RADIO_CONF="${ET_HOME}/conf/radios.d/$selected_radio.json"
|
||||||
|
[ -e ${ACTIVE_RADIO} ] && rm ${ACTIVE_RADIO}
|
||||||
|
ln -s ${RADIO_CONF} ${ACTIVE_RADIO}
|
||||||
|
echo "Set active radio to: $selected_radio"
|
||||||
|
else
|
||||||
|
echo "No radio selected."
|
||||||
|
fi
|
||||||
|
|
||||||
;;
|
;;
|
||||||
active)
|
active)
|
||||||
|
|||||||
Reference in New Issue
Block a user