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

193 lines
4.3 KiB
Bash
Executable File

#!/bin/bash
#
# Author : Gaston Gonzalez
# Date : 4 November 2024
# Updated : 12 August 2026
# Purpose : Wrapper script for starting YAAC with PnP support
#
# Preconditions:
# 1. Supported radio and audio interface are connected and properly detected
# 2. Appropriate modem is started: Dire Wolf (et-direwolf) or ARDOP (et-ardop).
#
# Postconditions:
# 1. Callsign, Winlink password, and grid are updated are updated
# 2. pat http is started
source /opt/emcomm-tools/bin/et-common
PAT_CONF_FILE=${HOME}/.config/pat/config.json
PAT_CONF_FILE_TEMPLATE=/etc/skel/.config/pat/config.json
usage() {
echo "usage: $(basename $0) <command>"
echo " <command>"
echo " start-ardop - Start Pat Winlink in ardop mode"
echo " start-packet - Start Pat Winlink in packet mode"
echo " start-native-packet - Start Pat Winlink in native AX.25 packet mode"
echo " start-vara-fm - Start Pat Winlink in VARA FM mode"
echo " start-vara-hf - Start Pat Winlink in VARA HF mode"
echo " start-mercury-hf - Start Pat Winlink in Mercury HF mode"
}
if [ $# -ne 1 ]; then
usage
exit 1
fi
notify_user() {
notify-send \
-t 10000 \
--app-name="EmComm Tools" \
"$1"
}
start_ardop() {
ps -ef | grep "[a]rdopcf"
if [ $? -ne 0 ]; then
et-log "Can't start Pat in ARDOP mode. ARDOP not running. Run: et-ardop"
notify_user "ARDOP not running. Run: et-ardop"
exit 1
fi
update_config ardop
CMD="pat http"
et-log "Starting Pat with: ${CMD}"
${CMD}
}
start_packet() {
RIGCTLD_OUT=$(ps -ef | grep "[d]irewolf")
if [ $? -ne 0 ]; then
et-log "Can't start Pat in packet mode. Dire Wolf not running. Run: et-direwolf simple-packet"
notify_user "Dire Wolf not running. Run: et-direwolf simple-packet"
exit 1
fi
update_config packet
CMD="pat http"
et-log "Starting Pat with: ${CMD}"
${CMD}
}
# Only the BTECH UV PRO is supported in this mode
start_native_packet() {
BLUETOOTH_TNC_CHECK=$(ps -ef | grep "[r]fcomm connect")
if [[ $? -ne 0 ]]; then
echo -e "${RED}Can't start Pat in native AX.25 packet mode."
echo -e "If you have a UV Pro, first run: ${YELLOW}et-uv-pro connect${NC}"
exit 1
fi
update_config native-packet
CMD="pat http"
et-log "Starting Pat with: ${CMD}"
${CMD}
}
start_vara_fm() {
update_config vara-fm
CMD="pat http"
et-log "Starting Pat with: ${CMD}"
${CMD}
}
start_vara_hf() {
update_config vara-hf
CMD="pat http"
et-log "Starting Pat with: ${CMD}"
${CMD}
}
start_mercury_hf() {
update_config mercury-hf
CMD="pat http"
et-log "Starting Pat with: ${CMD}"
${CMD}
}
update_config () {
[ -z "$ET_USER_CONFIG" ] && ET_USER_CONFIG="${HOME}/.config/emcomm-tools/user.json"
CALLSIGN=$(cat ${ET_USER_CONFIG} | jq -r .callsign)
GRID=$(cat ${ET_USER_CONFIG} | jq -r .grid)
WINLINK_PASSWD=$(cat ${ET_USER_CONFIG} | jq -r .winlinkPasswd)
if [ "${CALLSIGN}" = "N0CALL" ]; then
notify_user "Can't start Pat. No callsign set. Run: et-user."
exit 1
fi
case $1 in
ardop)
PAT_CONF_FILE_TEMPLATE=/opt/emcomm-tools/conf/template.d/winlink/config.ardop.json
;;
packet)
PAT_CONF_FILE_TEMPLATE=/opt/emcomm-tools/conf/template.d/winlink/config.ax25-agw.json
;;
native-packet)
PAT_CONF_FILE_TEMPLATE=/opt/emcomm-tools/conf/template.d/winlink/config.ax25-native.json
;;
vara-fm)
PAT_CONF_FILE_TEMPLATE=/opt/emcomm-tools/conf/template.d/winlink/config.vara-fm.json
;;
vara-hf)
PAT_CONF_FILE_TEMPLATE=/opt/emcomm-tools/conf/template.d/winlink/config.vara-hf.json
;;
mercury-hf)
PAT_CONF_FILE_TEMPLATE=/opt/emcomm-tools/conf/template.d/winlink/config.vara-hf.json
;;
esac
et-log "Updating Pat configuration file: ${PAT_CONF_FILE}..."
cp -v ${PAT_CONF_FILE_TEMPLATE} ${PAT_CONF_FILE}
sed -i "s|{{ET_CALLSIGN}}|${CALLSIGN}|g" ${PAT_CONF_FILE}
sed -i "s|{{ET_WINLINK_PASSWD}}|${WINLINK_PASSWD}|g" ${PAT_CONF_FILE}
sed -i "s|{{ET_GRID}}|${GRID}|g" ${PAT_CONF_FILE}
}
case $1 in
start-ardop)
start_ardop
;;
start-packet)
start_packet
;;
start-native-packet)
start_native_packet
;;
start-vara-fm)
start_vara_fm
;;
start-vara-hf)
start_vara_hf
;;
start-mercury-hf)
start_mercury_hf
;;
*)
echo "Invalid command."
usage
exit 1
;;
esac