fax api improved

added options -help and -handle
This commit is contained in:
Gandalf 2021-04-07 18:23:29 +02:00
parent 996c524b0e
commit 19279eefc3
3 changed files with 51 additions and 7 deletions

View file

@ -3,6 +3,7 @@ This is a small hack to send faxes via the sipgate REST API from the command lin
## Deployment ## Deployment
Add your login credentials to `login_credentials_muster.sh` and rename the file to `.env` Add your login credentials to `login_credentials_muster.sh` and rename the file to `.env`
If you use Letterheads Address database, uncomment the last line of that file and add `your/path/to/Letterhead`
## Usage ## Usage
`./fax.sh <letter.pdf> <recipient>` `./fax.sh <letter.pdf> <recipient>`

53
fax.sh
View file

@ -1,19 +1,60 @@
#! /bin/bash #! /bin/bash
#Check if I have enough parameters: function usage {
if [ -z "$2" ]
then
echo "Usage: echo "Usage:
$ ./fax.sh <letter.pdf> <recipient> $ ./fax.sh <letter.pdf> <recipient>
where <recipient> has to be a german faxline number" where <recipient> has to be a german faxline number
$ ./fax.sh <letter.pdf> -handle <handle>
Asks Letterhead's address database for <handle>'s fax number.
$ ./fax.sh -help
Print this Message and exit"
exit 1 exit 1
fi }
function abort {
echo "Letterhead API not available"
exit 1
}
BASEPATH=$(dirname $(realpath $0)) BASEPATH=$(dirname $(realpath $0))
. $BASEPATH/.env
#Parsing Parameters:
unset $GETOPT_COMPATIBLE
ARGV=$(getopt -n "$0" -a -o "" -l "help,handle:" -- "$@")
if [ $? -ne 0 ]
then
usage
fi
eval set -- "$ARGV"
REC0=
#Now we have $@ clean and tidy and begin parsing
while :
do
case "$1" in
"--help") usage ;;
"--handle")
$LETTERHEAD_PATH/Adressen/address.sh -l > /dev/null || abort
REC0=$($LETTERHEAD_PATH/Adressen/address.sh -f $2 2>\dev\null | sed 's: ::g')
shift
shift ;;
"--")
shift
break ;;
esac
done
#Check if you have enough parameters
if [ -z $REC0 ]
then
REC0=$2
fi
if [[ -z $REC0 || -z $1 ]]
then
usage
fi
. $BASEPATH/authorization.sh . $BASEPATH/authorization.sh
#Prepare fax credentials: #Prepare fax credentials:
FILE=$1 FILE=$1
echo -n "Sending file ${FILE} " echo -n "Sending file ${FILE} "
REC=$(echo "$2" | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:') REC=$(echo "$REC0" | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:')
echo "to $REC" echo "to $REC"
#Checking for file size: #Checking for file size:
SIZE=$(ls -l $FILE | cut -d " " -f5) SIZE=$(ls -l $FILE | cut -d " " -f5)

View file

@ -1,3 +1,5 @@
#Add your sipgate username and password here: #Add your sipgate username and password here:
SIPUSER= SIPUSER=
SIPPWD= SIPPWD=
#uncomment if you use Letterheads Address database
#LETTERHEAD_PATH=