minimodembbs.sh
howtophil |
PRO |
01/21/25 04:49:43 AM UTC (Edited) |
0 ⭐ |
534 👁️ |
Never ⏰ |
[modem, bbs, Ham radio, minimodem, telnetbbs]
#!/bin/bash
########///////////////////////////////////////########
#
# This is a bash script which uses minimodem, fifos,
# cat, and netcat to serve a telnet BBS over an audio
# line. The server and the client each run a pair of
# minimodem instances which read and write to transmit
# and receive fifos.
#
# With mic/phones splitters and some USB sound cards
# a person could connect to a BBS over the audio
# of a pair of cell phones.
#
# Also, just by crossing headphone and mic jacks
# to connect two computers over soundcards for
# tests...
#
# Theoretically could work over radio but
# would add complexity and noise so probably
# not.
#
# Call this script as a server or client from within its
# own directory where only it exists.
#
# As a server:
# $ ./minimodembbs.sh server [bbsaddress] [bbsport]
#
# As a client:
# $ ./minimodembbs.sh client [optional: speed] [optional: squeltch]
#
# The "server" side connects to a designated telnet
# BBS and then serves it via minimodem to the client.
# The client receives it via a receiving minimodem
# and sends commands back to the server (and BBS) via
# a transmitting minimodem instance.
#
# A pair of people could set both of their copy of
# this script to "client" mode and directly chat
# that way as well.
#
# Phillip J Rhoades 2022-02-17
#
########///////////////////////////////////////########
###########################################
# Set some variables for configuration
# and check to see if we are a server
# or a client using command line arguments
###########################################
#----------------------------------------------
# Speed and squeltch. Set as needed for
# line noise conditions.
# (Speed "rtty" has no lower case)
# Can use any of the speeds/formats
# minimodem allows, (baudrate, SAME, RTTY,etc)
#----------------------------------------------
defaultspeed=100
defaultsqueltch=2.00
#----------------------------------------------
# Check if server or client and adjust things
# as needed.
#----------------------------------------------
if [ -z "$1" ]; then
echo ""
echo "Call this script as a server or client."
echo ""
echo "As a server:"
echo " $ ./minimodembbs.sh server [bbsaddress] [bbsport] [optional speed] [optional squeltch]"
echo ""
echo "As a client:"
echo " $ ./minimodembbs.sh client [optional speed] [optional squeltch]"
echo ""
echo "-->Note: If you manually set the speed, you have to manually set the squeltch."
echo ""
exit
fi
if [ "$1" = "server" ]; then
if [ -z "$2" ] && [ -z "$3" ]; then
echo ""
echo "To serve a BBS over twin minimodems, please include"
echo "a server address and port number of a Telnet BBS to"
echo "connect to:"
echo " $ ./minimodembbs.sh server [bbsaddress] [bbsport] [optional speed] [optional squeltch]"
echo "-->Note: If you manually set the speed, you have to manually set the squeltch."
echo ""
exit
else
#----------------------------------------------
# Telnet address and port of BBS you are
# connecting to over the audio channels...
#----------------------------------------------
bbsaddress=$2
bbsport=$3
fi
if [ -z "$4" ] && [ -z "$5" ]; then
speed=$defaultspeed
squeltch=$defaultsqueltch
else
speed=$4
squeltch=$5
fi
echo "Starting as Telnet BBS Over Minimodems Server"
fi
if [ "$1" = "client" ]; then
if [ -z "$2" ] && [ -z "$3" ]; then
speed=$defaultspeed
squeltch=$defaultsqueltch
else
speed=$2
squeltch=$3
fi
fi
###########################################
# Trap ctrl-c for cleanup before exiting.
###########################################
trap ctrl_c INT
function ctrl_c() {
echo "#################"
echo "Cleaning up before exit..."
echo "#################"
echo "#################"
echo "Deleting fifos..."
rm $rpipe
rm $tpipe
echo "#################"
echo "Exiting..."
echo "#################"
kill 0
} 2>/dev/null
###########################################
# When working as a server, we need to not
# transmit until there is a client so we
# wait for the client to say it is ready
# to connect to the BBS by listening for
# a short initial transmit from the client
###########################################
function hello_wait() {
echo "Waiting for a blip from a connecting client"
head -n 1 $rpipe
}
###########################################
# Make a temp fifo for
# transmitting via a first minimodem
###########################################
tpipe=$(mktemp -u)
mkfifo -m 600 "$tpipe"
###########################################
# Make a temp fifo for
# receiving via a second minimodem
###########################################
rpipe=$(mktemp -u)
mkfifo -m 600 "$rpipe"
###########################################
# Tell the user what the receive pipe
# and the transmit pipe are...
###########################################
echo "Receive pipe: $rpipe"
echo "Transmit pipe: $tpipe"
###########################################
# Start the receive minimodem which
# seems to continue until the script
# comes to a stop.
###########################################
echo "Starting receive"
minimodem -q --print-filter -c $squeltch -r $speed | cat >$rpipe &
# Don't move forward until we hear from a client
if [ "$1" = "server" ]; then
hello_wait
fi
###########################################
# Start the transmit minimodem which
# seems to exit after every successful
# fifo read. So, we keep restarting it
# whenever it stops...
###########################################
while true; do
echo "(Re)starting transmit"
minimodem -t $speed <$tpipe &
transmitPID=$!
wait $transmitPID
done &
###########################################
# Use netcat to open a Telnet BBS and
# connect it through the minimodems running
# here with the minimodems running on a
# different machine through the fifos
###########################################
#----------------------------------------------
# What to do if called as a server
#----------------------------------------------
if [ "$1" = "server" ]; then
echo "Serving telnet BBS at $bbsaddress $bbsport over double minimodems"
cat $rpipe |while true; do netcat $bbsaddress $bbsport | cat >$tpipe; hello_wait; done;
#cat $rpipe |netcat $bbsaddress $bbsport >$tpipe
fi
#----------------------------------------------
# What to do if called as a client
#----------------------------------------------
if [ "$1" = "client" ]; then
echo "Starting client and connecting to double minimodems BBS server"
echo "1" >$tpipe
cat $rpipe & cat >$tpipe
fi
Comments