cleanup scanbuddy script

This commit is contained in:
Prunebutt 2025-09-27 15:51:35 +02:00
parent 8542ea2ef7
commit b421e330f4

View file

@ -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,19 +76,12 @@ scan() {
-x 210 -y 297 # A4 -x 210 -y 297 # A4
} }
if [ "$#" -lt 1 ]; then clean() {
echo "You need an argument!" echo "Cleaning up..."
exit 1 rm -rfv "$PWD/out*.pdf"
fi }
case "$1" in dispatch() {
scan)
scan "${@:2}"
;;
unscan)
rm "$last_out_file"
;;
dispatch)
readarray -d '' out_files < <(find . -regextype posix-awk -regex "\./out[0-9]+\.pdf" -print0 | sort -Vz) readarray -d '' out_files < <(find . -regextype posix-awk -regex "\./out[0-9]+\.pdf" -print0 | sort -Vz)
combined_file=$(mktemp --suff="_scanbuddy.pdf") combined_file=$(mktemp --suff="_scanbuddy.pdf")
gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="$combined_file" -dBATCH "${out_files[@]}" gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE="$combined_file" -dBATCH "${out_files[@]}"
@ -107,8 +99,29 @@ case "$1" in
else else
printf "Paperless consumption job: %s\n" "$PAPERLESS_STATUS" printf "Paperless consumption job: %s\n" "$PAPERLESS_STATUS"
fi fi
clean
}
if [ "$#" -lt 1 ]; then
echo "You need an argument!"
exit 1
fi
case "$1" in
scan)
scan "${@:2}"
;;
unscan)
rm "$last_out_file"
;;
dispatch)
dispatch "${@:2}"
;;
clean)
clean
;; ;;
*) *)
echo "Usage: scanbuddy" echo "Usage: scanbuddy scan|unscan|dispatch|clean"
;; ;;
esac esac