cleanup scanbuddy script
This commit is contained in:
parent
8542ea2ef7
commit
b421e330f4
1 changed files with 32 additions and 19 deletions
|
|
@ -13,7 +13,6 @@ sides=$simplex_source
|
||||||
mode='c'
|
mode='c'
|
||||||
resolution='300'
|
resolution='300'
|
||||||
|
|
||||||
|
|
||||||
current_page=$(find "$PWD" -name "out*.pdf" | sort | tail -n 1);
|
current_page=$(find "$PWD" -name "out*.pdf" | sort | tail -n 1);
|
||||||
read -r current_pageno <<<"${current_page//[^0-9]/ }"
|
read -r current_pageno <<<"${current_page//[^0-9]/ }"
|
||||||
current_pageno=${current_pageno:-0}
|
current_pageno=${current_pageno:-0}
|
||||||
|
|
@ -77,6 +76,33 @@ scan() {
|
||||||
-x 210 -y 297 # A4
|
-x 210 -y 297 # A4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clean() {
|
||||||
|
echo "Cleaning up..."
|
||||||
|
rm -rfv "$PWD/out*.pdf"
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch() {
|
||||||
|
readarray -d '' out_files < <(find . -regextype posix-awk -regex "\./out[0-9]+\.pdf" -print0 | sort -Vz)
|
||||||
|
combined_file=$(mktemp --suff="_scanbuddy.pdf")
|
||||||
|
gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="$combined_file" -dBATCH "${out_files[@]}"
|
||||||
|
echo "Merged pdf written to $combined_file"
|
||||||
|
|
||||||
|
# send to paperless
|
||||||
|
PAPERLESS_STATUS=$(curl \
|
||||||
|
-H "Authorization: Token $PAPERLESS_TOKEN" \
|
||||||
|
-F document=@"$combined_file" \
|
||||||
|
"$([ -v PAPERLESS_TAG ] && echo "-F tags=$PAPERLESS_TAG")" \
|
||||||
|
"${PAPERLESS_URL}/api/documents/post_document/") || FAILED=1
|
||||||
|
|
||||||
|
if [ -v FAILED ]; then
|
||||||
|
printf "Paperless failed with message:\n%s" "$PAPERLESS_STATUS"
|
||||||
|
else
|
||||||
|
printf "Paperless consumption job: %s\n" "$PAPERLESS_STATUS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
clean
|
||||||
|
}
|
||||||
|
|
||||||
if [ "$#" -lt 1 ]; then
|
if [ "$#" -lt 1 ]; then
|
||||||
echo "You need an argument!"
|
echo "You need an argument!"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -90,25 +116,12 @@ case "$1" in
|
||||||
rm "$last_out_file"
|
rm "$last_out_file"
|
||||||
;;
|
;;
|
||||||
dispatch)
|
dispatch)
|
||||||
readarray -d '' out_files < <(find . -regextype posix-awk -regex "\./out[0-9]+\.pdf" -print0 | sort -Vz)
|
dispatch "${@:2}"
|
||||||
combined_file=$(mktemp --suff="_scanbuddy.pdf")
|
;;
|
||||||
gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="$combined_file" -dBATCH "${out_files[@]}"
|
clean)
|
||||||
echo "Merged pdf written to $combined_file"
|
clean
|
||||||
|
|
||||||
# send to paperless
|
|
||||||
PAPERLESS_STATUS=$(curl \
|
|
||||||
-H "Authorization: Token $PAPERLESS_TOKEN" \
|
|
||||||
-F document=@"$combined_file" \
|
|
||||||
"$([ -v PAPERLESS_TAG ] && echo "-F tags=$PAPERLESS_TAG")" \
|
|
||||||
"${PAPERLESS_URL}/api/documents/post_document/") || FAILED=1
|
|
||||||
|
|
||||||
if [ -v FAILED ]; then
|
|
||||||
printf "Paperless failed with message:\n%s" "$PAPERLESS_STATUS"
|
|
||||||
else
|
|
||||||
printf "Paperless consumption job: %s\n" "$PAPERLESS_STATUS"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: scanbuddy"
|
echo "Usage: scanbuddy scan|unscan|dispatch|clean"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue