From 19279eefc33c096edc9e2a34189fed05ba370de1 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 7 Apr 2021 18:23:29 +0200 Subject: [PATCH] fax api improved added options -help and -handle --- README.md | 1 + fax.sh | 55 ++++++++++++++++++++++++++++++++----- login_credentials_muster.sh | 2 ++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f0147f2..29cac69 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ This is a small hack to send faxes via the sipgate REST API from the command lin ## Deployment 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 `./fax.sh ` diff --git a/fax.sh b/fax.sh index d616237..248f92f 100755 --- a/fax.sh +++ b/fax.sh @@ -1,19 +1,60 @@ #! /bin/bash -#Check if I have enough parameters: -if [ -z "$2" ] -then +function usage { echo "Usage: $ ./fax.sh - where has to be a german faxline number" - exit 1 -fi + where has to be a german faxline number + $ ./fax.sh -handle + Asks Letterhead's address database for 's fax number. + $ ./fax.sh -help + Print this Message and exit" + exit 1 +} +function abort { + echo "Letterhead API not available" + exit 1 +} 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 #Prepare fax credentials: FILE=$1 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" #Checking for file size: SIZE=$(ls -l $FILE | cut -d " " -f5) diff --git a/login_credentials_muster.sh b/login_credentials_muster.sh index a84e54e..d0ac3b4 100755 --- a/login_credentials_muster.sh +++ b/login_credentials_muster.sh @@ -1,3 +1,5 @@ #Add your sipgate username and password here: SIPUSER= SIPPWD= +#uncomment if you use Letterheads Address database +#LETTERHEAD_PATH=