| 1 | #! /bin/bash |
| 2 | ########################################################################### |
| 3 | # sendfile - LinPac utility for sending 7plus files # |
| 4 | # (c) 2001 by Radek Burget OK2JBG # |
| 5 | # # |
| 6 | # Usage: # |
| 7 | # Create messages from file: sendfile p <file> <addr> [<num_msgs>] # |
| 8 | # Create bulletins from file: sendfile b <file> <addr> [<num_msgs>] # |
| 9 | # Report number of blocks : sendfile r <file> [<num_msgs>] # |
| 10 | # # |
| 11 | # Used variables: # |
| 12 | # BLOCK7P@0 - max. size of block (when num_msgs is not specified) # |
| 13 | ########################################################################### |
| 14 | |
| 15 | # 7plus command |
| 16 | COMMAND="7plus" |
| 17 | |
| 18 | ########################################################################### |
| 19 | LPAPI="lpapi" |
| 20 | TMPDIR=/tmp/sendfile.$$ |
| 21 | MSGLIST=$HOME/LinPac/mail/messages.local |
| 22 | |
| 23 | #Test if LinPac is running |
| 24 | $LPAPI 0 |
| 25 | if [ ! $? -eq 0 ]; then |
| 26 | echo LinPac is not running |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | # Parse arguments |
| 31 | if [ $# -gt 1 ]; then |
| 32 | if [ $1 = 'p' ]; then |
| 33 | if [ $# -eq 3 ]; then |
| 34 | CMD=$1 |
| 35 | FNAME=$2 |
| 36 | ADDR=$3 |
| 37 | MTYPE=p |
| 38 | SIZE=`$LPAPI 0 get BLOCK7P` |
| 39 | BLOCKS=0 |
| 40 | if [ x$SIZE = x ]; then |
| 41 | SIZE=5120 |
| 42 | fi |
| 43 | elif [ $# -eq 4 ]; then |
| 44 | CMD=$1 |
| 45 | FNAME=$2 |
| 46 | ADDR=$3 |
| 47 | SIZE=0 |
| 48 | BLOCKS=$4 |
| 49 | else |
| 50 | echo 'Usage: sendfile p <file> <address> [<num_msgs>]' |
| 51 | exit 1 |
| 52 | fi |
| 53 | elif [ $1 = 'b' ]; then |
| 54 | if [ $# -eq 3 ]; then |
| 55 | CMD=$1 |
| 56 | FNAME=$2 |
| 57 | ADDR=$3 |
| 58 | MTYPE=b |
| 59 | SIZE=`$LPAPI 0 get BLOCK7P` |
| 60 | BLOCKS=0 |
| 61 | if [ x$SIZE = x ]; then |
| 62 | SIZE=5120 |
| 63 | fi |
| 64 | elif [ $# -eq 4 ]; then |
| 65 | CMD=$1 |
| 66 | FNAME=$2 |
| 67 | ADDR=$3 |
| 68 | SIZE=0 |
| 69 | BLOCKS=$4 |
| 70 | else |
| 71 | echo 'Usage: sendfile b <file> <address> [<num_msgs>]' |
| 72 | exit 1 |
| 73 | fi |
| 74 | elif [ $1 = 'r' ]; then |
| 75 | if [ $# -eq 2 ]; then |
| 76 | CMD=$1 |
| 77 | FNAME=$2 |
| 78 | SIZE=`$LPAPI 0 get BLOCK7P` |
| 79 | BLOCKS=0 |
| 80 | if [ x$SIZE = x ]; then |
| 81 | SIZE=5120 |
| 82 | fi |
| 83 | elif [ $# -eq 3 ]; then |
| 84 | CMD=$1 |
| 85 | FNAME=$2 |
| 86 | SIZE=0 |
| 87 | BLOCKS=$3 |
| 88 | else |
| 89 | echo 'Usage: sendfile r <file> [<num_msgs>]' |
| 90 | exit 1 |
| 91 | fi |
| 92 | else |
| 93 | echo 'Usage: sendfile p|b|r <file> ...' |
| 94 | exit 1 |
| 95 | fi |
| 96 | else |
| 97 | echo 'Usage: sendfile p|b|r <file> ...' |
| 98 | exit 1 |
| 99 | fi |
| 100 | |
| 101 | if [ ! -r $FNAME ]; then |
| 102 | echo "File $FNAME not found !" |
| 103 | exit 1 |
| 104 | fi |
| 105 | |
| 106 | rm -rf $TMPDIR |
| 107 | mkdir $TMPDIR |
| 108 | cp $FNAME $TMPDIR |
| 109 | |
| 110 | OLDDIR=`pwd` |
| 111 | cd $TMPDIR |
| 112 | LNAME=`ls` |
| 113 | |
| 114 | if [ $SIZE -eq 0 ]; then |
| 115 | eval $COMMAND -sp $BLOCKS $LNAME >/dev/null 2>/dev/null |
| 116 | else |
| 117 | eval $COMMAND -sb $SIZE $LNAME >/dev/null 2>/dev/null |
| 118 | fi |
| 119 | |
| 120 | rm $LNAME |
| 121 | PARTS=`ls -l | wc -l` |
| 122 | PARTS=$(($PARTS-1)) |
| 123 | |
| 124 | if [ $PARTS -eq 0 ]; then |
| 125 | echo "Error: unable to split the file with $COMMAND" |
| 126 | echo "Make sure the command \"$COMMAND\" is in PATH and is executable!" |
| 127 | echo "Sending aborted." |
| 128 | exit 1 |
| 129 | fi |
| 130 | |
| 131 | if [ $CMD = 'r' ]; then |
| 132 | echo "Attached file $LNAME: will be split to $PARTS parts" |
| 133 | cd $OLDDIR |
| 134 | rm -rf $TMPDIR |
| 135 | fi |
| 136 | |
| 137 | if [ $CMD = 'p' -o $CMD = 'b' ]; then |
| 138 | echo "Attached file $LNAME: will be split to $PARTS parts" |
| 139 | |
| 140 | CNT=1 |
| 141 | for I in *; do |
| 142 | SUBJ="$LNAME part $CNT/$PARTS (7pl)" |
| 143 | CNT=$(($CNT+1)) |
| 144 | echo Creating message from $I |
| 145 | eval $LPAPI $LPCHN do "compose $MTYPE $ADDR '$SUBJ' $TMPDIR/$I" |
| 146 | done |
| 147 | |
| 148 | cd $OLDDIR |
| 149 | rm -rf $TMPDIR |
| 150 | echo "Sending done." |
| 151 | fi |