packages/easyscan: allow overriding easyscan options

This commit is contained in:
Primrose 2026-02-01 23:40:09 +01:00
parent 25df5b3993
commit 5c311bbfdb
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

48
nix/packages/by-name/easyscan/easyscan.sh Normal file → Executable file
View file

@ -1,11 +1,51 @@
#!/usr/bin/env bash
# This is here because scanimage's batch mode is broken for my scanner
OUTPUT_FILE="${1:-./scan_"$(date)".pdf}"
function help() {
cat <<EOF
easyscan
easyscan wraps scanimage and joins the resulting pdf.
Usage:
easyscan <target_file> [ -- args ]:
Scan a (multi-page) document to <target_file>, passing args to scanimage
EOF
}
if [ $# -lt 1 ]; then
help
exit 1
fi
OUTPUT_FILE="$1.pdf"
if [ -e "$OUTPUT_FILE" ]; then
echo "$OUTPUT_FILE" already exists, you are probably making a mistake!
exit 1
fi
shift
scanimage_args=(
"-x" "210"
"-y" "297"
"--resolution" "300"
)
while [ $# -gt 0 ]; do
case $1 in
--help)
help
exit
;;
--)
shift
scanimage_args+=("$@")
break
;;
*)
shift
;;
esac
done
tempdir="$(mktemp -d)"
filenames=()
@ -26,11 +66,7 @@ while :; do
# If no size is set, the output will be wonky-sized
# 210,297 is the size of A4
scanimage -x 210 -y 297 --resolution 300 -o "$CUR_FNAME" >/dev/null 2>&1 ||
{
echo "Failed to scan page..."
ok="false"
}
scanimage "${scanimage_args[@]}" -o "$CUR_FNAME" || ok="false"
if $ok; then
counter=$((counter += 1))