Advertisement
howtophil

minimodembbs.sh

Jan 20th, 2025 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.58 KB | Software | 0 0
  1. #!/bin/bash
  2.  
  3. ########///////////////////////////////////////########
  4. #
  5. # This is a bash script which uses minimodem, fifos,
  6. # cat, and netcat to serve a telnet BBS over an audio
  7. # line. The server and the client each run a pair of
  8. # minimodem instances which read and write to transmit
  9. # and receive fifos.
  10. #
  11. # With mic/phones splitters and some USB sound cards
  12. # a person could connect to a BBS over the audio
  13. # of a pair of cell phones.
  14. #
  15. # Also, just by crossing headphone and mic jacks
  16. # to connect two computers over soundcards for
  17. # tests...
  18. #
  19. # Theoretically could work over radio but
  20. # would add complexity and noise so probably
  21. # not.
  22. #
  23. # Call this script as a server or client from within its
  24. # own directory where only it exists.
  25. #
  26. # As a server:
  27. #    $ ./minimodembbs.sh server [bbsaddress] [bbsport]
  28. #
  29. # As a client:
  30. #    $ ./minimodembbs.sh client [optional: speed] [optional: squeltch]
  31. #
  32. # The "server" side connects to a designated telnet
  33. # BBS and then serves it via minimodem to the client.
  34. # The client receives it via a receiving minimodem
  35. # and sends commands back to the server (and BBS) via
  36. # a transmitting minimodem instance.
  37. #
  38. # A pair of people could set both of their copy of
  39. # this script to "client" mode and directly chat
  40. # that way as well.
  41. #
  42. # Phillip J Rhoades 2022-02-17
  43. #
  44. ########///////////////////////////////////////########
  45.  
  46. ###########################################
  47. # Set some variables for configuration
  48. # and check to see if we are a server
  49. # or a client using command line arguments
  50. ###########################################
  51.  
  52. #----------------------------------------------
  53. # Speed and squeltch. Set as needed for
  54. # line noise conditions.
  55. # (Speed "rtty" has no lower case)
  56. # Can use any of the speeds/formats
  57. # minimodem allows, (baudrate, SAME, RTTY,etc)
  58. #----------------------------------------------
  59. defaultspeed=100
  60. defaultsqueltch=2.00
  61.  
  62. #----------------------------------------------
  63. # Check if server or client and adjust things
  64. # as needed.
  65. #----------------------------------------------
  66. if [ -z "$1" ]; then
  67.     echo ""
  68.     echo "Call this script as a server or client."
  69.     echo ""
  70.     echo "As a server:"
  71.     echo "   $ ./minimodembbs.sh server [bbsaddress] [bbsport] [optional speed] [optional squeltch]"
  72.     echo ""
  73.     echo "As a client:"
  74.     echo "   $ ./minimodembbs.sh client [optional speed] [optional squeltch]"
  75.     echo ""
  76.     echo "-->Note: If you manually set the speed, you have to manually set the squeltch."
  77.     echo ""
  78.     exit
  79. fi
  80.  
  81. if [ "$1" = "server" ]; then
  82.     if [ -z "$2" ] && [ -z "$3" ]; then
  83.         echo ""
  84.         echo "To serve a BBS over twin minimodems, please include"
  85.         echo "a server address and port number of a Telnet BBS to"
  86.         echo "connect to:"
  87.         echo "   $ ./minimodembbs.sh server [bbsaddress] [bbsport] [optional speed] [optional squeltch]"
  88.         echo "-->Note: If you manually set the speed, you have to manually set the squeltch."
  89.         echo ""
  90.         exit
  91.     else
  92.         #----------------------------------------------
  93.         # Telnet address and port of BBS you are
  94.         # connecting to over the audio channels...
  95.         #----------------------------------------------
  96.         bbsaddress=$2
  97.         bbsport=$3 
  98.     fi
  99.     if [ -z "$4" ] && [ -z "$5" ]; then
  100.         speed=$defaultspeed
  101.         squeltch=$defaultsqueltch
  102.     else
  103.         speed=$4
  104.         squeltch=$5
  105.     fi
  106.     echo "Starting as Telnet BBS Over Minimodems Server"
  107. fi
  108.  
  109. if [ "$1" = "client" ]; then
  110.     if [ -z "$2" ] && [ -z "$3" ]; then
  111.         speed=$defaultspeed
  112.         squeltch=$defaultsqueltch
  113.     else
  114.         speed=$2
  115.         squeltch=$3
  116.     fi
  117. fi
  118.  
  119. ###########################################
  120. # Trap ctrl-c for cleanup before exiting.
  121. ###########################################
  122. trap ctrl_c INT
  123. function ctrl_c() {
  124.  
  125.         echo "#################"
  126.         echo "Cleaning up before exit..."
  127.         echo "#################"
  128.  
  129.         echo "#################"
  130.         echo "Deleting fifos..."
  131.         rm $rpipe
  132.         rm $tpipe
  133.  
  134.         echo "#################"
  135.         echo "Exiting..."
  136.         echo "#################"
  137.         kill 0
  138.  
  139. } 2>/dev/null
  140.  
  141. ###########################################
  142. # When working as a server, we need to not
  143. # transmit until there is a client so we
  144. # wait for the client to say it is ready
  145. # to connect to the BBS by listening for
  146. # a short initial transmit from the client
  147. ###########################################
  148. function hello_wait() {
  149.     echo "Waiting for a blip from a connecting client"
  150.     head -n 1 $rpipe
  151. }
  152.  
  153. ###########################################
  154. # Make a temp fifo for
  155. # transmitting via a first minimodem
  156. ###########################################
  157. tpipe=$(mktemp -u)
  158. mkfifo -m 600 "$tpipe"
  159.  
  160. ###########################################
  161. # Make a temp fifo for
  162. # receiving via a second minimodem
  163. ###########################################
  164. rpipe=$(mktemp -u)
  165. mkfifo -m 600 "$rpipe"
  166.  
  167. ###########################################
  168. # Tell the user what the receive pipe
  169. # and the transmit pipe are...
  170. ###########################################
  171. echo "Receive  pipe: $rpipe"
  172. echo "Transmit pipe: $tpipe"
  173.  
  174. ###########################################
  175. # Start the receive minimodem which
  176. # seems to continue until the script
  177. # comes to a stop.
  178. ###########################################
  179. echo "Starting receive"
  180. minimodem -q --print-filter -c $squeltch -r $speed | cat >$rpipe &
  181.  
  182. # Don't move forward until we hear from a client
  183. if [ "$1" = "server" ]; then
  184.     hello_wait
  185. fi
  186.  
  187. ###########################################
  188. # Start the transmit minimodem which
  189. # seems to exit after every successful
  190. # fifo read. So, we keep restarting it
  191. # whenever it stops...
  192. ###########################################
  193.  
  194. while true; do
  195.     echo "(Re)starting transmit"
  196.     minimodem -t $speed <$tpipe &
  197.     transmitPID=$!
  198.     wait $transmitPID
  199. done &
  200.  
  201. ###########################################
  202. # Use netcat to open a Telnet BBS and
  203. # connect it through the minimodems running
  204. # here with the minimodems running on a
  205. # different machine through the fifos
  206. ###########################################
  207.  
  208. #----------------------------------------------
  209. # What to do if called as a server
  210. #----------------------------------------------
  211. if [ "$1" = "server" ]; then
  212.     echo "Serving telnet BBS at $bbsaddress $bbsport over double minimodems"
  213.     cat $rpipe |while true; do netcat $bbsaddress $bbsport | cat >$tpipe; hello_wait; done;
  214.     #cat $rpipe |netcat $bbsaddress $bbsport >$tpipe
  215. fi
  216.  
  217. #----------------------------------------------
  218. # What to do if called as a client
  219. #----------------------------------------------
  220. if [ "$1" = "client" ]; then
  221.     echo "Starting client and connecting to double minimodems BBS server"
  222.     echo "1" >$tpipe
  223.     cat $rpipe & cat >$tpipe
  224. fi
  225.  
  226.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement