summaryrefslogtreecommitdiffstats
path: root/paperless_pipeline
blob: 52b67d19cc304c46cdfbc743ba5a1b4a1957b284 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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