summaryrefslogblamecommitdiffstats
path: root/paperless_pipeline
blob: 52b67d19cc304c46cdfbc743ba5a1b4a1957b284 (plain) (tree)




















































                                                                                                                      
#!/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

echo "command: ${command}"
command="$(eval "${command}")"

echo
echo " #######################"
echo "${command}"
echo " #######################"

if echo "${command}" | bash; then
  rm "${full_filename}"
  echo
  echo " #######################"
  echo " #        done         #"
  echo " #######################"
else
  echo
  echo " #######################"
  echo " #       error         #"
  echo " #######################"
fi