UX - Updated the et-radio command to use an ncurses interface for selecting the active radio

This commit is contained in:
Gaston Gonzalez
2024-10-16 06:15:33 -07:00
parent 769db9027c
commit 6b3f6cf912
+22 -12
View File
@@ -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)
options+=("$ID" "$VENDOR $MODEL")
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} [ -e ${ACTIVE_RADIO} ] && rm ${ACTIVE_RADIO}
ln -s ${RADIO_CONF} ${ACTIVE_RADIO} ln -s ${RADIO_CONF} ${ACTIVE_RADIO}
echo "Set active radio to: $selected_radio"
else
echo "No radio selected."
fi
;; ;;
active) active)