#!/bin/env bash filename="${1}" full_filename="${filename}.pdf" title="${2}" correspondent="${3}" tags="${4}" if [ -z "${filename}" ] || [ -z "${title}" ] || [ -z "${correspondent}" ]; then echo "Usage: ${0} filename title correspondent [tags(csv)]" exit 1 fi echo echo " #######################" echo " # preparing paperless #" echo " #######################" if ! prepare_paperless "${filename}"; then echo "Could not prepare pdf for paperless (scan, shrink)" exit 2 fi echo echo " #######################" echo " # uploading file #" echo " #######################" if [ -n "${tags}" ]; then command="paperless_upload --title \"${title}\" --correspondent \"${correspondent}\" --tags ${tags} ${full_filename}" else command="paperless_upload --title \"${title}\" --correspondent \"${correspondent}\" ${full_filename}" fi command="$(eval "${command}")" echo "${command}" if echo "${command}" | bash > /dev/null; then rm "${full_filename}" echo echo " #######################" echo " # done #" echo " #######################" else echo echo " #######################" echo " # error #" echo " #######################" fi