#! /usr/bin/env dash # shellcheck disable=SC2086 # shellcheck source=/dev/null . %SHELL_LIBRARY_PATH # Vars counter=0; a_set=false; pw=$(pwd) usage() { cat << EOF This is a help doc! -p for path -h for help -n for name -g gen pdf dir -r for number of pages per pdf EOF exit 0; } # Ops while getopts ":hp:n:gr:" flag;do case "$flag" in p) Command_path=$OPTARG ;; n) name=$OPTARG ;; g) gen=true ;; r) pages=$OPTARG ;; h) usage;; *) usage;; esac done [ -z "$pages" ] && die "No pages set" # Scan if [ -z $Command_path ];then tm=$(mktemp -d) cd $tm || die "Bug" for i in $(seq $pages);do scanimage --format=tiff --progress \ --source ADF --device="airscan:w1:Brother DCP-9022CDW" \ --batch=%d.tif --batch-increment=$pages --batch-start=$i [ $? -ne 0 ] && scanimage --format=tiff --progress \ --source ADF --device="airscan:w1:Brother DCP-9022CDW" \ --batch=%d.tif --batch-increment=$pages --batch-start=$i if [ $pages -ge 2 ];then msg "Finished first turn, please change side!"; readp "Ready to continue?" noop fi done else tm=$Command_path; fi cd $pw || die "Bug" # mk pdf if [ "$gen" = true ];then mkdir pdfs cd pdfs/ || die "Bug" fi while IFS= read -r i;do if [ $pages -ge 2 ];then a_set=false; if [ -z "$a" ];then a="$i" a_set=true; : $((counter += 1)) fi if [ -n "$a" ] && ! [ "$a_set" = true ];then convert "$a" "$i" -compress jpeg -quality 70 "$name"_"$counter".pdf a= fi else : $((counter += 1)) convert "$i" -compress jpeg -quality 70 "$name"_"$counter".pdf fi done < "$(tmp "ls $tm | sort -n | awk -v a=$tm -v c='/' '{printf a} {printf c} {print \$0}' ")" rm -r $tm if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi