| 1 | #!/bin/bash |
| 2 | ########################################################################### |
| 3 | # LinPac - packet radio terminal for Linux |
| 4 | # (c) 2020 Martin Cooper |
| 5 | # |
| 6 | # This script provides an integrated BBS mail retrieval system. |
| 7 | # |
| 8 | # Usage: getmail [<bbs_call>] |
| 9 | ########################################################################### |
| 10 | |
| 11 | # Check that Linpac is running |
| 12 | # |
| 13 | LPAPI=lpapi |
| 14 | $LPAPI 0 |
| 15 | if [ ! $? -eq 0 ]; then |
| 16 | echo "Linpac is not running" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | # Check that axgetlist is available |
| 21 | # |
| 22 | AXGETLIST=`which axgetlist` |
| 23 | if [ -z $AXGETLIST ]; then |
| 24 | echo "axgetlist is not available" |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | # Get BBS call from command line or init.mac |
| 29 | # |
| 30 | if [ "$#" -eq 1 ]; then |
| 31 | BBS_CALL=$1 |
| 32 | else |
| 33 | # Sleep for 1 second to allow earlier LPAPI call to complete. This works |
| 34 | # around a timing issue where Linpac is still working after the client |
| 35 | # believes everything has completed. |
| 36 | sleep 1 |
| 37 | HOME_ADDR=`$LPAPI 0 get HOME_ADDR` |
| 38 | BBS_CALL=`echo $HOME_ADDR | tr "." "," | sed s/,.*//` |
| 39 | fi |
| 40 | if [ -z $BBS_CALL ]; then |
| 41 | echo "Usage: getmail [<bbs_call>]" |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | # Run axgetlist to get the TOC |
| 46 | # |
| 47 | $AXGETLIST -b $BBS_CALL |
| 48 | if [ $? -ne 0 ]; then |
| 49 | echo "axgetlist failed" |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
| 53 | # Determine which messages we don't yet have |
| 54 | # |
| 55 | TOGET=() |
| 56 | TOC="/var/ax25/ulistd/${BBS_CALL}" |
| 57 | MSGS="/var/ax25/mail/${BBS_CALL}" |
| 58 | while read -r line |
| 59 | do |
| 60 | read -ra COLS <<< "$line" |
| 61 | if [ ! -f "${MSGS}/${COLS[0]}" ]; then |
| 62 | TOGET+=( ${COLS[0]} ) |
| 63 | fi |
| 64 | done < "$TOC" |
| 65 | |
| 66 | # Invoke the Linpac getmsg command with the list |
| 67 | # |
| 68 | if [ "${#TOGET[@]}" -ne 0 ]; then |
| 69 | eval $LPAPI $LPCHN do "getmsg ${TOGET[@]}" |
| 70 | fi |
| 71 | |
| 72 | # Note: No message to tell the user getmail is done, because getmsg is run |
| 73 | # asynchronously, and will not complete until after this script has exited. |