From acd576dd3dbbed3805a7cab59bee2e0bf697ea63 Mon Sep 17 00:00:00 2001 From: Franco Masotti Date: Sat, 8 Dec 2018 22:27:08 +0100 Subject: [PATCH] Simplified controls. Added a configuration file. Fixes. --- fbopt | 10 ++--- spectrscan | 65 +++++++------------------------ spectrscan.HP_Officejet_2620.conf | 7 ++++ spectrscan.conf | 1 + 4 files changed, 27 insertions(+), 56 deletions(-) create mode 100644 spectrscan.HP_Officejet_2620.conf create mode 120000 spectrscan.conf diff --git a/fbopt b/fbopt index 0c3804e..8c4a433 100644 --- a/fbopt +++ b/fbopt @@ -95,11 +95,11 @@ main() local getopt_long_options='help,imagemagick:,list-modes,list-resolutions,list-sources,mode:,print-flags,resolution:,source:,two-sided,two-sided-reverse,unpaper::' # Set the default values for the flags. - local imagemagick='-normalize -level 70%,100%,1.0' - local mode='Lineart' - local resolution='300' - local source='ADF' - local unpaper='false' + local imagemagick="${IMAGEMAGICK}" + local mode="${MODE}" + local resolution="${RESOLUTION}" + local source="${SOURCE}" + local unpaper="${UNPAPER}" local program_name="${0}" opts="$(getopt \ diff --git a/spectrscan b/spectrscan index f5051e1..de4a50e 100755 --- a/spectrscan +++ b/spectrscan @@ -24,8 +24,7 @@ set -x -TMP_DIR="$(pwd)/.spectrscan-$RANDOM" -SRC_DIR="$(pwd)" +. ./spectrscan.conf check_software() { @@ -67,16 +66,18 @@ scan() batch_increment=1 fi - printf "%s\n" 'Scanning...' # Put source option before resolution to avoid the error: # https://bugs.launchpad.net/simple-scan/+bug/983441 + scan_command='' + [ "${scanner_support_source}" = 'true' ] && scan_command=""${scan_command}" --source "${source}"" + [ "${scanner_supports_resolution}" = 'true' ] && scan_command=""${scan_command}" --resolution "${resolution}"" + [ "${scanner_supports_mode}" = 'true' ] && scan_command=""${scan_command}" --mode "${mode}"" + scanimage \ - --source "$source" \ + ${scan_command} \ --batch=spectrscan_out%08d.pnm \ --batch-start ${batch_start} \ --batch-increment ${batch_increment} \ - --resolution "$resolution" \ - --mode "$mode" \ --progress \ --format=pnm } @@ -90,7 +91,7 @@ exists_output_file() printf 'true' else # Not a pdf file. - printf "error" + printf 'error' fi else printf 'false' @@ -130,8 +131,6 @@ convert_single() pnm_to_pdf() { - printf "%s\n" 'PNM to PDF...' - # A hack to avoid GNU Parallel's message mkdir -p ~/.parallel && touch ~/.parallel/will-cite # n = number of new pages @@ -144,7 +143,7 @@ pnm_to_pdf() pdf_cat() { - printf "%s\n" 'Assembling PDF...' + printf "%s\n" 'assembling PDF...' # O(n) # Always cat to the output file. # Unlike pdfunite, pdftk does not corrupt the pdf. @@ -175,7 +174,7 @@ get_supported_parameters() get_supported_resolutions() { - echo "${supported_params}" | awk '{print $2}' | tr '|' ' ' | tr -d 'dpi' + echo "${supported_params}" | grep resolution | awk '{print $2}' | tr '|' ' ' | tr -d 'dpi' } get_supported_modes() @@ -188,33 +187,6 @@ get_supported_sources() echo "${supported_params}" | grep source | awk '{print $2}' | tr '|' ' ' } -check_supported_parameters() -{ - local parameter="${1}" - local value="${2}" - local supported_parameters="${3}" - local counter=0 - local parameter_full_name='' - local p='' - - parameter_full_name="supported_${parameter}" - eval "$parameter_full_name='$(get_supported_"${parameter}" "${supported_parameters}")'" - for p in ${!parameter_full_name}; do - if [ "$value" = "$p" ]; then - counter=$(($counter+1)) - fi - done - if [ $counter -eq 0 ]; then - printf "error: supported $parameter: ${!parameter_full_name}\n" 1>&2- - return 1 - fi -} - -cleanup() -{ - rm -rf "$TMP_DIR" -} - chain() { mkdir "$TMP_DIR" @@ -240,15 +212,9 @@ chain() scan fi - # Feeder out of documents unexpectedly. -# if [ ${?} -eq 7 ]; then -# cleanup -# return 1 -# fi - pnm_to_pdf pdf_cat - cleanup + rm -rf "$TMP_DIR" popd } @@ -265,14 +231,11 @@ preliminary_checks() output_file="${7}" # Get the parameters and check that the scanner is connected. supported_params="$(get_supported_parameters)" - [ ${?} -ne 0 ] && return ${?} - { check_supported_parameters 'modes' "${mode}" \ - && check_supported_parameters 'resolutions' "${resolution}" \ - && check_supported_parameters 'sources' "${source}"; } \ - || return 1 - + [ -n "$(get_supported_resolutions)" ] && scanner_supports_resolution='true' + [ -n "$(get_supported_modes)" ] && scanner_supports_mode='true' + [ -n "$(get_supported_sources)" ] && scanner_support_source='true' chain } diff --git a/spectrscan.HP_Officejet_2620.conf b/spectrscan.HP_Officejet_2620.conf new file mode 100644 index 0000000..7a48464 --- /dev/null +++ b/spectrscan.HP_Officejet_2620.conf @@ -0,0 +1,7 @@ +TMP_DIR="$(pwd)/.spectrscan-$RANDOM" +SRC_DIR="$(pwd)" +IMAGEMAGICK='-normalize -level 70%,100%,1.0' +MODE='Lineart' +RESOLUTION='300' +SOURCE='ADF' +UNPAPER='false' diff --git a/spectrscan.conf b/spectrscan.conf new file mode 120000 index 0000000..3700e56 --- /dev/null +++ b/spectrscan.conf @@ -0,0 +1 @@ +spectrscan.HP_Officejet_2620.conf \ No newline at end of file