#!/bin/sh
# User configuration.
XFBB_BASEDIR='/var/ax25/fbb'        # Path of the XFBB dir on your system.
XFBB_FILESDIR="$XFBB_BASEDIR/fbbdos/"  # Path to the downloadable files.
XFBB_7PLDIR="$XFBB_BASEDIR/7pl"
XFBB_MAILIN="$XFBB_BASEDIR/mail"
XFBB_7PLUS="/usr/lib/fbb/tool/7plus"
 
# End of user config stuff.

CALL=`echo $1 | cut -d- -f1 `
PROGNAME=`basename "$5"`
VERSION='V0.99'

# Some autor's indentification. 

   echo ' ' 
   echo 'The 7plus server for Linux and XFBB.'
   echo 'Version '$VERSION' made by Twan van der Meer the PE1NHL. '
   echo ' ' 

# Check if PROGNAME is not empty, otherwise print help message.

if [ "$5" = '' ]
 then
   echo 'To use the 7plserv, type:  7plserv <filename>'
   echo '<filename> is the file to download, including the path.'
 elif [ -d "$XFBB_FILESDIR$5" ]               # Check if file is not a directory
 then
   echo 'You typed a directory name!'
 elif [ -f "$XFBB_FILESDIR$5" ]               # Check if file exists
  then
   # Welcome and activation

   echo 'The  7plus server is now processing '$PROGNAME 'requested by '$CALL
   echo ' '

 # Copy file to /tmp dir to work on it.
 
   cp $XFBB_FILESDIR$5 $XFBB_7PLDIR
   cd $XFBB_7PLDIR

 # 7plus the programm.

   $XFBB_7PLUS $PROGNAME 1> grep successful && echo 'Processing succesfull!'

 # Throw used program in the bin.

  rm $PROGNAME

# Check if there is only one *.7pl file, or multiple *.p?? files.
# After checking copy the files in the mail.in and append it
# to the FBB mail.in.

  if [ -f *.7pl ]
  then
     echo 'sp ' $CALL '< 7plsrv' > mail.in
     echo '7plus file: ' $PROGNAME >> mail.in
       echo ' ' >> mail.in 
       echo 'The 7plus server for Linux and XFBB.' >> mail.in 
       echo 'Version '$VERSION' made by Twan van der Meer the PE1NHL. ' >> mail.in 
       echo ' ' >> mail.in 
     cat *.7pl >> mail.in
     echo '/ex' >> mail.in
     cat mail.in >> "$XFBB_MAILIN/mail.in"
     rm *.7pl
     rm mail.in
     if [ "$?" = 0 ]
     then
       echo 'The 7plus mail will be ready for download in a few seconds.'
     fi
  else
     echo 'sp ' $CALL '< 7plsrv' > mail.in
     echo '7plus file: ' $PROGNAME >> mail.in
       echo ' ' >> mail.in 
       echo 'The 7plus server for Linux and XFBB.' >> mail.in 
       echo 'Version '$VERSION' made by Twan van der Meer the PE1NHL. ' >> mail.in 
       echo ' ' >> mail.in 
     cat *.p?? >> mail.in
     echo '/ex' >> mail.in
     cat mail.in >> "$XFBB_MAILIN/mail.in"
     rm *.p??
     rm mail.in
     if [ "$?" = 0 ]
     then
       echo 'The 7plus mail will be ready for download in a few seconds.'
     fi
  fi 
  else
   echo 'That file does not exist!'

# Tell user 7plserv is finished.

 fi
exit 0

