2024-11-06 11:18:15 -07:00
#!/bin/bash
#
# Author : Gaston Gonzalez
# Date : 6 November 2024
2026-08-12 18:30:46 -07:00
# Updated : 12 August 2026
2024-11-06 11:18:15 -07:00
# Purpose : Configures the system for a specific mode of operation
2024-11-07 08:41:39 -07:00
# Use a simple text file to save the state of the last mode selected
2024-11-06 11:58:40 -07:00
MODE_STATUS_FILE = " ${ HOME } /.config/emcomm-tools/et-mode "
2025-02-08 04:45:23 -07:00
QTTERMTCP_CONF_FILE = " ${ HOME } /.config/QtTermTCP.ini "
2024-11-07 08:41:39 -07:00
# List of supported modes of operation
2024-11-06 11:18:15 -07:00
MODE_ID_NONE = "none"
MODE_ID_APRS_DIGIPEATER = "aprs-digipeater"
MODE_ID_APRS_CLIENT = "aprs-client"
2024-12-03 05:50:39 -07:00
MODE_ID_BBS_CLIENT = "bbs-client"
2024-12-17 06:24:26 -07:00
MODE_ID_BBS_CLIENT2 = "bbs-client2"
2025-03-25 07:09:48 -07:00
MODE_ID_BBS_SERVER = "bbs-server"
2024-12-05 04:46:01 -07:00
MODE_ID_CHAT_CLIENT = "chat-chattervox"
2024-11-08 14:39:49 -07:00
MODE_ID_PACKET_DIGIPEATER = "packet-digipeater"
2024-11-06 11:18:15 -07:00
MODE_ID_WINLINK_ARDOP = "winlink-ardop"
2026-08-12 18:30:46 -07:00
MODE_ID_WINLINK_MERCURY = "winlink-mercury"
2024-11-06 11:18:15 -07:00
MODE_ID_WINLINK_PACKET = "winlink-packet"
2025-02-07 02:30:32 -07:00
MODE_ID_WINLINK_VARA_HF = "winlink-vara-hf"
MODE_ID_WINLINK_VARA_FM = "winlink-vara-fm"
2026-04-16 16:28:22 -07:00
MODE_ID_TIME_WWV = "time-wwv"
2024-11-06 11:18:15 -07:00
2025-02-08 04:45:23 -07:00
# Default to 1200 baud packet for terminal sessions
TERM_MODE = 1200
2025-01-14 02:10:22 -07:00
2024-11-12 07:43:20 -07:00
# Attempt to stop all EmComm Tools services regardless if they are running.
2024-11-06 11:52:52 -07:00
stop_all_services( ) {
2024-11-12 07:43:20 -07:00
et-kill-all
2024-11-06 11:52:52 -07:00
}
2024-11-07 09:31:11 -07:00
exit_on_service_failure( ) {
local systemd_unit_name = " $1 "
systemctl is-active --user --quiet " ${ systemd_unit_name } "
if [ $? -ne 0 ] ; then
et-log " Can't start mode. ${ systemd_unit_name } failed to start. "
exit 1
fi
}
2024-11-07 08:41:39 -07:00
TIMEOUT = 15 # Total time to wait in seconds
INTERVAL = 2 # Interval between checks in seconds
start_and_wait_for_service( ) {
local systemd_unit_name = " $1 "
local elapsed = 0
et-log " Starting ${ systemd_unit_name } ... "
systemctl --user start ${ systemd_unit_name }
et-log " Waiting for ${ systemd_unit_name } to become active... "
while ! systemctl is-active --user --quiet " ${ systemd_unit_name } " ; do
sleep " $INTERVAL "
elapsed = $(( elapsed + INTERVAL))
if [ " $elapsed " -ge " $TIMEOUT " ] ; then
et-log " Timeout reached. ${ systemd_unit_name } failed to start. "
exit 1
fi
et-log " Waiting for ${ systemd_unit_name } to become active... "
done
# Some applications even when started still need a bit of extra time to be available.
# Add a short think time of 2 seconds. The ARDOP modem requies extra time.
sleep 2
2024-11-07 09:31:11 -07:00
# Do one more check to ensure that we are running, otherwise exit.
exit_on_service_failure ${ systemd_unit_name }
2024-11-07 08:41:39 -07:00
}
2025-02-07 02:30:32 -07:00
start_and_wait_for_vara( ) {
local vara_cmd = " $1 "
local elapsed = 0
et-log " Starting ${ vara_cmd } ... "
${ vara_cmd } &
et-log " Waiting for ${ vara_cmd } to become active... "
while true; do
CHECK_VARA = $( ps -ef | grep "[V]ARA" )
if [ $? -eq 0 ] ; then
break
fi
sleep " $INTERVAL "
elapsed = $(( elapsed + INTERVAL))
if [ " $elapsed " -ge " $TIMEOUT " ] ; then
et-log " Timeout reached. ${ systemd_unit_name } failed to start. "
exit 1
fi
et-log " Waiting for ${ vara_cmd } to become active... "
done
}
2025-02-08 04:45:23 -07:00
select_term_mode ( ) {
term_mode = ( )
term_mode += ( "1200" "1200 baud (default for VHF/UHF)" )
term_mode += ( "9600" "9600 baud (VHF/UHF)" )
term_mode += ( "300" "300 baud (HF)" )
2025-01-14 02:10:22 -07:00
2025-02-09 09:36:49 -07:00
# Only allow VARA terminal modes when using QtTermTCP
if [ [ " ${ SELECTED_MODE } " = = " ${ MODE_ID_BBS_CLIENT2 } " ] ] ; then
if [ -e " ${ HOME } /.wine32/drive_c/VARA FM/VARAFM.exe " ] ; then
term_mode += ( "vara-fm" "VARA FM" )
fi
2025-02-08 04:45:23 -07:00
2025-02-09 09:36:49 -07:00
if [ -e " ${ HOME } /.wine32/drive_c/VARA/VARA.exe " ] ; then
term_mode += ( "vara-hf" "VARA HF" )
fi
2025-02-08 04:45:23 -07:00
fi
TERM_MODE = $( dialog --clear --menu "Select a modem" 13 60 10 " ${ term_mode [@] } " 3>& 1 1>& 2 2>& 3)
2025-01-14 02:10:22 -07:00
exit_status = $?
2025-02-08 04:45:23 -07:00
if [ " ${ TERM_MODE } " = = "9600" ] ; then
2025-01-14 02:27:16 -07:00
dialog --title "Note on 9600 Baud" --msgbox "9600 baud is only supported on limited radios and typically requires a special cable.\n\nDon't forget to set the packet settings to 9600 on the radio." 0 0
fi
2025-01-14 02:10:22 -07:00
tput sgr 0 && clear
if [ ${ exit_status } -ne 0 ] ; then
et-log "No modem selected. Mode will not be started."
exit 1
fi
}
2026-04-16 16:28:22 -07:00
wwv_mode ( ) {
dialog --title "Note on WWV" --msgbox "Manually set your radio to AM and tune it to one of the WWV frequencies appropriate for this operating time.\n\nTry: 2.5, 5, 10, 15 or 20 MHz." 0 0
tput sgr 0 && clear
}
2024-11-07 08:41:39 -07:00
# Build list of options
2024-11-06 11:18:15 -07:00
options = ( )
options += ( " ${ MODE_ID_NONE } " "No mode selected" )
2024-11-06 11:52:52 -07:00
options += ( " ${ MODE_ID_APRS_CLIENT } " "APRS Client (YAAC)" )
2024-12-03 05:50:39 -07:00
options += ( " ${ MODE_ID_BBS_CLIENT } " "BBS Client (Paracon)" )
2024-12-17 06:24:26 -07:00
options += ( " ${ MODE_ID_BBS_CLIENT2 } " "BBS Client (QtTermTCP)" )
2025-03-25 07:09:48 -07:00
options += ( " ${ MODE_ID_BBS_SERVER } " "BBS Server (LinBPQ)" )
2024-12-05 04:46:01 -07:00
options += ( " ${ MODE_ID_CHAT_CLIENT } " "Chat (chattervox)" )
2024-11-06 11:18:15 -07:00
options += ( " ${ MODE_ID_APRS_DIGIPEATER } " "APRS Digipeater" )
2024-11-08 14:39:49 -07:00
options += ( " ${ MODE_ID_PACKET_DIGIPEATER } " "Packet Digipeater" )
2024-11-20 16:54:50 -07:00
options += ( " ${ MODE_ID_WINLINK_PACKET } " "Winlink over VHF/UHF (AX.25 Packet)" )
2024-11-06 11:18:15 -07:00
2025-02-07 02:30:32 -07:00
if [ -e " ${ HOME } /.wine32/drive_c/VARA FM/VARAFM.exe " ] ; then
options += ( " ${ MODE_ID_WINLINK_VARA_FM } " "Winlink over VHF/UHF (VARA FM)" )
fi
2026-08-12 18:30:46 -07:00
options += ( " ${ MODE_ID_WINLINK_MERCURY } " "Winlink over HF (Mercury)" )
2025-02-07 02:30:32 -07:00
options += ( " ${ MODE_ID_WINLINK_ARDOP } " "Winlink over HF (ARDOP)" )
if [ -e " ${ HOME } /.wine32/drive_c/VARA/VARA.exe " ] ; then
options += ( " ${ MODE_ID_WINLINK_VARA_HF } " "Winlink over HF (VARA HF)" )
fi
2026-04-16 16:28:22 -07:00
options += ( " ${ MODE_ID_TIME_WWV } " "Sync clock to WWV" )
2024-11-07 08:41:39 -07:00
# Prompt user for option and save exit status
2025-02-07 02:30:32 -07:00
SELECTED_MODE = $( dialog --clear --menu "Select a mode:" 18 65 10 " ${ options [@] } " 3>& 1 1>& 2 2>& 3)
2024-11-06 11:18:15 -07:00
exit_status = $?
tput sgr 0 && clear
if [ $exit_status -eq 0 ] ; then
2024-11-06 11:52:52 -07:00
stop_all_services
2024-11-06 11:18:15 -07:00
2024-11-07 09:51:45 -07:00
echo ${ SELECTED_MODE } > ${ MODE_STATUS_FILE }
2024-11-06 11:18:15 -07:00
case ${ SELECTED_MODE } in
2024-11-06 11:52:52 -07:00
${ MODE_ID_NONE } )
et-log "No mode selected"
; ;
${ MODE_ID_APRS_DIGIPEATER } )
2024-11-08 14:39:49 -07:00
systemctl --user start et-service-direwolf-aprs-digipeater
2024-11-07 08:41:39 -07:00
et-log "APRS digipeater now running."
2024-11-06 11:52:52 -07:00
; ;
${ MODE_ID_APRS_CLIENT } )
2024-11-07 08:41:39 -07:00
start_and_wait_for_service et-service-direwolf-simple
2024-11-06 11:52:52 -07:00
et-yaac start
; ;
2024-12-03 05:50:39 -07:00
${ MODE_ID_BBS_CLIENT } )
2025-02-08 04:45:23 -07:00
select_term_mode
et-log " Using ${ TERM_MODE } as the modem speed. "
2025-01-14 02:10:22 -07:00
2025-02-17 16:57:52 -07:00
case " ${ TERM_MODE } " in
"1200" )
start_and_wait_for_service et-service-direwolf-simple
; ;
"9600" )
start_and_wait_for_service et-service-direwolf-9600
; ;
"300" )
start_and_wait_for_service et-service-direwolf-300
; ;
esac
2024-12-03 05:50:39 -07:00
et-log "Starting Paracon."
et-paracon start
; ;
2024-12-17 06:24:26 -07:00
${ MODE_ID_BBS_CLIENT2 } )
2025-02-08 04:45:23 -07:00
select_term_mode
et-log " Using ${ TERM_MODE } as the modem. "
2025-01-14 02:10:22 -07:00
2025-02-08 04:45:23 -07:00
case " ${ TERM_MODE } " in
"1200" )
start_and_wait_for_service et-service-direwolf-simple
; ;
"9600" )
start_and_wait_for_service et-service-direwolf-9600
; ;
"300" )
start_and_wait_for_service et-service-direwolf-300
; ;
"vara-fm" )
sed -i "s|^VARAFM=.*|VARAFM=1|g" ${ QTTERMTCP_CONF_FILE }
sed -i "s|^VARAHF=.*|VARAHF=0|g" ${ QTTERMTCP_CONF_FILE }
start_and_wait_for_vara et-vara-fm
; ;
"vara-hf" )
sed -i "s|^VARAFM=.*|VARAFM=0|g" ${ QTTERMTCP_CONF_FILE }
sed -i "s|^VARAHF=.*|VARAHF=1|g" ${ QTTERMTCP_CONF_FILE }
start_and_wait_for_vara et-vara-hf
; ;
esac
2025-01-14 02:10:22 -07:00
2024-12-17 06:24:26 -07:00
et-log "Starting QtTermTCP."
et-qttermtcp start
; ;
2025-03-25 07:09:48 -07:00
${ MODE_ID_BBS_SERVER } )
start_and_wait_for_service et-service-direwolf-simple
et-log "Starting BBS server."
et-bbs-server start
; ;
2024-12-05 04:46:01 -07:00
${ MODE_ID_CHAT_CLIENT } )
start_and_wait_for_service et-service-direwolf-simple
et-log "Starting chattervox"
2024-12-05 05:22:40 -07:00
et-chattervox start
2024-12-05 04:46:01 -07:00
; ;
2024-11-08 14:39:49 -07:00
${ MODE_ID_PACKET_DIGIPEATER } )
systemctl --user start et-service-direwolf-packet-digipeater
et-log "Packet digipeater now running."
; ;
2024-11-06 11:52:52 -07:00
${ MODE_ID_WINLINK_ARDOP } )
2025-02-08 04:45:23 -07:00
et-log "Using ARDOP as the modem."
2024-11-07 08:41:39 -07:00
start_and_wait_for_service et-service-ardop
start_and_wait_for_service et-service-winlink-ardop
2024-11-06 11:52:52 -07:00
min http://localhost:8080
; ;
2026-08-12 18:30:46 -07:00
${ MODE_ID_WINLINK_MERCURY } )
et-log "Using Mercury as the modem."
start_and_wait_for_service et-service-mercury-winlink
start_and_wait_for_service et-service-winlink-mercury
min http://localhost:8080
; ;
2024-11-06 11:52:52 -07:00
${ MODE_ID_WINLINK_PACKET } )
2024-11-07 08:41:39 -07:00
start_and_wait_for_service et-service-direwolf-simple
start_and_wait_for_service et-service-winlink-packet
2024-11-06 11:52:52 -07:00
min http://localhost:8080
; ;
2025-02-07 02:30:32 -07:00
${ MODE_ID_WINLINK_VARA_FM } )
dialog --title "User Action Required" --msgbox "VARA FM is not a plug and play mode. You must configure VARA manually." 10 50
tput sgr 0 && clear
start_and_wait_for_vara et-vara-fm
et-winlink start-vara-fm &
sleep 1
min http://localhost:8080 2>/dev/null
; ;
${ MODE_ID_WINLINK_VARA_HF } )
dialog --title "User Action Required" --msgbox "VARA HF is not a plug and play mode. You must configure VARA manually." 10 50
tput sgr 0 && clear
start_and_wait_for_vara et-vara-hf
et-winlink start-vara-hf &
sleep 1
2025-02-08 03:33:38 -07:00
min http://localhost:8080 2>/dev/null
2025-02-07 02:30:32 -07:00
; ;
2026-04-16 16:28:22 -07:00
${ MODE_ID_TIME_WWV } )
wwv_mode
sudo /opt/emcomm-tools/sbin/wrapper-et-wwv.sh
; ;
2024-11-06 11:18:15 -07:00
*)
2024-11-06 11:52:52 -07:00
et-log " Mode ${ SELECTED_MODE } not yet supported "
2024-11-06 11:18:15 -07:00
exit 1
; ;
esac
else
et-log "No mode selected"
2024-11-06 11:58:40 -07:00
echo ${ MODE_ID_NONE } > ${ MODE_STATUS_FILE }
2024-11-06 11:18:15 -07:00
exit 1
fi