#!/usr/bin/sh #---------------------------------------------------------------------------- # /var/install/bin/sane-scanimage - scanimage frontend # # Creation : 2010-07-14 dr_snuggles # Last Update: $Id$ # # Copyright (c) 2010 the eisfair team, team(at)eisfair(dot)org # Copyright (c) 2012-@@YEAR@q Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include libs . /var/install/include/eislib . /var/install/include/configlib # set package name package_name='sane' ASK='/var/install/bin/ask' MKTEMP='/usr/bin/mktemp' spool_path=/var/spool/scan #debug=true if ${debug:-false} then exec 2>/tmp/$(basename ${0})-trace$$.log set -x ask_debug=true export ask_debug fi # --------------------------------------------------------------------------- # check user # --------------------------------------------------------------------------- # get user to work _user=$(whoami) _user_id=$(/usr/bin/gawk -F: '/^'${_user}':/ { print $3 }' /etc/passwd) if [ ${_user_id} -eq 0 ] then old_ini_file='/etc/sane.d/scan.ini' ini_file="/${_user}/.config/sane/scan.ini" mkdir -p -m 700 /${_user}/.config/sane if [ ! -f ${ini_file} -a -f ${old_ini_file} ] then mv ${old_ini_file} ${ini_file} fi scan_path='/tmp' elif [ "${_user}" = "saned" ] then old_ini_file='/etc/sane.d/scan.ini' ini_file="/var/spool/scan/.config/sane/scan.ini" mkdir -p -m 700 /var/spool/scan/.config/sane if [ ! -f ${ini_file} -a -f ${old_ini_file} ] then mv ${old_ini_file} ${ini_file} fi mkdir -p /public/scans scan_path='/public/scans' cmd_sudo=sudo else old_ini_file="/home/${_user}/sane.d/scan.ini" ini_file="/home/${_user}/.config/sane/scan.ini" mkdir -p -m 700 /home/${_user}/.config/sane if [ ! -f ${ini_file} -a -f ${old_ini_file} ] then mv ${old_ini_file} ${ini_file} rmdir --ignore-fail-on-non-empty /home/${_user}/sane.d fi mkdir -p /home/${_user}/scans scan_path="/home/${_user}/scans" cmd_sudo=sudo fi if [ -f ${ini_file} ] then use_ini='true' # include scan.ini . ${ini_file} fi _sane_devices_tmpfile=$(${MKTEMP} -t sane_devices_tmpfile.XXXXXXXXXX) _sane_scanimage_tmpfile=$(${MKTEMP} -t sane_scanimage_tmpfile.XXXXXXXXXX) scanimage -L | grep '^device' | tr '`' "'" | cut -d' ' -f2- > ${_sane_devices_tmpfile} # --------------------------------------------------------------------------- # choose device # --------------------------------------------------------------------------- choose_device() { count=$(wc -l ${_sane_devices_tmpfile} | cut -f1 -d' ') idx=1 while read devices do eval DEVICE_${idx}_1=\"$(echo ${devices} | cut -d"'" -f2)\" eval DEVICE_${idx}_2=\"$(echo ${devices} | cut -d"'" -f3- | cut -d' ' -f4-)\" idx=$((${idx} + 1)) done < ${_sane_devices_tmpfile} SCAN_DEV="${DEVICE_1_1}" SCAN_MOD="${DEVICE_1_2}" if [ ${count:-0} -gt 1 ] then clrhome mecho --info "SANE - Frontend for scanimage" mecho --info "Choose Scanner" techo --begin '3 3 1 34 2 30*' techo --row '' --warn 'Nr' '' --warn 'Device' '' --warn 'Name' echo idx=1 while [ ${idx} -le ${count} ] do eval SHOW_DEV='${DEVICE_'${idx}'_1}' eval SHOW_MOD='${DEVICE_'${idx}'_2}' techo --row '' "${idx}." '' "${SHOW_DEV}" '' "${SHOW_MOD}" idx=$((${idx} + 1)) done techo --end echo _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) /var/install/bin/ask 'Select' '' "1-${count}" '^$=Return' '0=Exit' >${_ask_tmpfile} rc=${?} read idy < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc:-0} = 255 ] then idy=0 fi case ${idy} in '') remove_temp_file exit 0 ;; 0) remove_temp_file exit 127 ;; esac eval SCAN_DEV='${DEVICE_'${idy}'_1}' eval SCAN_MOD='${DEVICE_'${idy}'_2}' SCAN_MOD="${SCAN_MOD}" fi } # --------------------------------------------------------------------------- # choose resulution # --------------------------------------------------------------------------- choose_resolution() { options=$(grep -- '--resolution' ${_sane_scanimage_tmpfile}) if ! "${use_ini:-false}" then SCAN_RES=$(echo ${options} | cut -f3 -d' ' | sed 's/\[//g; s/\]//g') fi options=$(echo ${options} | cut -f2 -d' ' | sed 's/|/ /g; s/dpi//g') helper_a='' ; helper_b='' for helper_a in ${options} do helper_b=$(echo "${helper_a} ${helper_b}") done options=${helper_b} x=${options//[!' ']/} x="${#x}" if [ ${x:-2} -le 1 ] then options_min=$(echo ${options//..*}) options_max=$(echo ${options//*..}) options='' List='10 20 30 40 50 75 100 150 200 300 600 1200 2400 4800 9600' for op in ${List} do if [ ${op} -ge ${options_min} ] && [ ${op} -le ${options_max} ] then options=$(echo "${op} ${options}") fi done fi _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Resolution" "${SCAN_RES:-100}" ${options} > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_RES="${a}" res_col='--info' } # --------------------------------------------------------------------------- # choose mode # --------------------------------------------------------------------------- choose_mode() { options=$(grep -- '--mode' ${_sane_scanimage_tmpfile}) if ! "${use_ini:-false}" then SCAN_MODE=$(echo ${options} | cut -f3 -d' ' | sed 's/\[//g; s/\]//g') fi options=$(echo ${options} | cut -f2 -d' ' | tr '|' ' ') helper_a='' ; helper_b='' for helper_a in ${options} do helper_b=$(echo "${helper_a} ${helper_b}") done options=${helper_b} _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Mode" "${SCAN_MODE:-Gray}" ${options} > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_MODE="${a}" mode_col='--info' } # --------------------------------------------------------------------------- # choose tlxy # --------------------------------------------------------------------------- choose_TLXY() { show_head # options_helper=`grep 'Geometry' -A 8 ${_sane_scanimage_tmpfile}` options=+ # tlx=`echo $options_helper | cut -f3 -d' ' | sed 's/mm//g'` # tly=`echo $options_helper | cut -f12 -d' ' | sed 's/mm//g'` if ! "${use_ini:-false}" then SCAN_TLX=$(echo ${tlx} | cut -f4 -d' ' | sed 's/\[//g; s/\]//g') SCAN_TLY=$(echo ${tly} | cut -f13 -d' ' | sed 's/\[//g; s/\]//g') fi mecho --info "Value must be between ${tlx}" _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Top left x position of scan area" "${SCAN_TLX}" ${options} > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_TLX="${a}" tlx_col='--info' show_head mecho --info "Value must be between ${tly}" _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Top left y position of scan area" "${SCAN_TLY}" ${options} > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_TLY="${a}" tly_col='--info' } # --------------------------------------------------------------------------- # choose width/heigth # --------------------------------------------------------------------------- choose_width_height() { show_head if ! "${use_ini:-false}" then SCAN_WIDTH=$(echo ${Width} | cut -f22 -d' ' | sed 's/\[//g; s/\]//g') SCAN_HEIGHT=$(echo ${Height} | cut -f28 -d' ' | sed 's/\[//g: s/\]//g') fi mecho --info "Value must be between ${Width}" _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Width of scan area" "${SCAN_WIDTH}" ${options} > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_WIDTH="${a}" width_col='--info' show_head mecho --info "Value must be between ${Height}" _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Height of scan area" "${SCAN_HEIGHT}" ${options} > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_HEIGHT="${a}" height_col='--info' } # --------------------------------------------------------------------------- # choose geometry # --------------------------------------------------------------------------- choose_geometry() { _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) if "${use_ini:-false}" then w=${SCAN_WIDTH} h=${SCAN_HEIGHT} else w=${Width} h=${Height} fi GEOMETRY_TITLE="SANE - Frontend for scanimage" GEOMETRY_SUBTITLE="Choose Geometry" GEOMETRY_QUESTION="Select scan size" GEOMETRY_COLS='12 12 12' GEOMETRY_ROWS=12 GEOMETRY_FLAGS='--indent 12 --default 1' GEOMETRY_CAPTION_1='--warn "Page"' GEOMETRY_CAPTION_2='--warn "Width"' GEOMETRY_CAPTION_3='--warn "Height"' GEOMETRY_1_1='A0' ; GEOMETRY_1_2='841' ; GEOMETRY_1_3='1189' GEOMETRY_2_1='A1' ; GEOMETRY_2_2='594' ; GEOMETRY_2_3='841' GEOMETRY_3_1='A2' ; GEOMETRY_3_2='420' ; GEOMETRY_3_3='594' GEOMETRY_4_1='A3' ; GEOMETRY_4_2='297' ; GEOMETRY_4_3='420' GEOMETRY_5_1='A4' ; GEOMETRY_5_2='210' ; GEOMETRY_5_3='297' GEOMETRY_6_1='A5' ; GEOMETRY_6_2='148' ; GEOMETRY_6_3='210' GEOMETRY_7_1='A6' ; GEOMETRY_7_2='105' ; GEOMETRY_7_3='148' GEOMETRY_8_1='US-Letter' ; GEOMETRY_8_2='216' ; GEOMETRY_8_3='279' GEOMETRY_9_1='US-Legal' ; GEOMETRY_9_2='216' ; GEOMETRY_9_3='356' GEOMETRY_10_1='US-Ledger' ; GEOMETRY_10_2='432' ; GEOMETRY_10_3='279' GEOMETRY_11_1="US-Tabloid" ; GEOMETRY_11_2='279' ; GEOMETRY_11_3='432' GEOMETRY_12_1="custom" ; GEOMETRY_12_2="${SCAN_WIDTH}" ; GEOMETRY_12_3="${SCAN_HEIGHT}" idx=1 while [ ${idx} -le 12 ] do eval guik='${GEOMETRY_'${idx}'_2}' eval guik2='${GEOMETRY_'${idx}'_3}' if [ "${Width//0..}" -lt "${guik:-0}" ] || [ "${Height//0..}" -lt "${guik2:-0}" ] then eval GEOMETRY_${idx}_ACTIVE="no" export GEOMETRY_${idx}_ACTIVE fi export GEOMETRY_${idx}_1 export GEOMETRY_${idx}_2 export GEOMETRY_${idx}_3 idx=$((${idx} + 1)) done export GEOMETRY_TITLE export GEOMETRY_SUBTITLE export GEOMETRY_QUESTION export GEOMETRY_COLS export GEOMETRY_ROWS export GEOMETRY_FLAGS export GEOMETRY_CAPTION_1 export GEOMETRY_CAPTION_2 export GEOMETRY_CAPTION_3 /var/install/bin/choose GEOMETRY > ${_ask_tmpfile} rc=${?} read idy < ${_ask_tmpfile} rm -f ${_ask_tmpfile} eval SCAN_PAGE='${GEOMETRY_'${idy}'_1}' eval SCAN_WIDTH='${GEOMETRY_'${idy}'_2}' eval SCAN_HEIGHT='${GEOMETRY_'${idy}'_3}' if [ ${idy:-1} -eq 0 ] then remove_temp_file exit 127 fi if [ -z "${idy}" ] then SCAN_WIDTH="${w}" SCAN_HEIGHT="${h}" fi if [ "${SCAN_PAGE}" = "custom" ] then choose_TLXY choose_width_height else SCAN_TLX='' SCAN_TLY='' tlx_col='--info' width_col='--info' tly_col='--info' height_col='--info' fi } # --------------------------------------------------------------------------- # choose type # --------------------------------------------------------------------------- choose_type() { _out_type="pnm:Netpbm image data:pnm tiff:TIFF picture:tiff jpg:JPEG picture:pnm png:PNG picture:pnm pdf:PDF document:tiff ps:PostScript document:tiff" techo --begin '3 3r 7 30' idx=1 echo "${_out_type}" | while read line do _f_type="$(echo "${line}" | /usr/bin/gawk -F: '{ print $1 }')" _f_mesg="$(echo "${line}" | /usr/bin/gawk -F: '{ print $2 }')" techo --row "" "${idx}." "${_f_type}" "${_f_mesg}" idx=$((${idx} + 1)) done techo --end echo _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Select image type" "$(echo "${_out_type}" | grep -n "${SCAN_TYPE:-pnm}:"| cut -d':' -f1)" "1-$(echo "${_out_type}" | wc -l)" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi action_line="$(echo "${_out_type}" | sed -n "${a}p" | sed 's/^ *//')" SCAN_TYPE="$(echo "${action_line}" | /usr/bin/gawk -F: '{ print $1 }')" _scan_type="$(echo "${action_line}" | /usr/bin/gawk -F: '{ print $3 }')" _file_out="$(echo "${action_line}" | /usr/bin/gawk -F: '{ print $1 }')" type_col='--info' } # --------------------------------------------------------------------------- # choose compress # --------------------------------------------------------------------------- choose_compress() { _out_type="uncompressed:n compress with JPEG:j compress with Zip/Deflate:z" techo --begin '3 3r 30' idx=1 echo "${_out_type}" | while read line do _f_compress="$(echo "${line}" | /usr/bin/gawk -F: '{ print $1 }')" techo --row "" "${idx}." "${_f_compress}" idx=$((${idx} + 1)) done techo --end echo _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Select compress type" "$(echo "${_out_type}" | grep -n ":${SCAN_COMPRESS:-j}"| cut -d':' -f1)" "1-$(echo "${_out_type}" | wc -l)" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi action_line="$(echo "${_out_type}" | sed -n "${a}p" | sed 's/^ *//')" SCAN_COMPRESS="$(echo "${action_line}" | /usr/bin/gawk -F: '{ print $2 }')" compress_col='--info' } # --------------------------------------------------------------------------- # choose jpeg quality # --------------------------------------------------------------------------- choose_jpeg_quality() { _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "JPEG scan quality" "${SCAN_QUALITY:-30}" "1-100" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_QUALITY="${a}" jpeg_quality_col='--info' } # --------------------------------------------------------------------------- # choose name # --------------------------------------------------------------------------- choose_name() { _time=$(echo "${EISTIME}" | tr ':' '-') _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Image name" "ImageScan-${EISDATE}-${_time}" "*" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_NAME="${a}" name_col='--info' } # --------------------------------------------------------------------------- # choose path # --------------------------------------------------------------------------- choose_path() { _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Full path " "${SCAN_PATH:-${scan_path}}" "*" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi SCAN_PATH="${a}" if [ "${_user}" = "root" ] || [ "${_user}" = "saned" ] then ${cmd_sudo} /var/install/bin/check-folder -f ${SCAN_PATH} fi path_col='--info' } # --------------------------------------------------------------------------- # choose user # --------------------------------------------------------------------------- choose_user() { _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Scan for user (default root) " "${SCAN_USER:-root}" "*" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi if ! getent passwd ${a} >/dev/null 2>&1 then mecho --error "User: ${a} dosn't exist" anykey choose_user fi SCAN_USER="${a:-root}" user_col='--info' } # --------------------------------------------------------------------------- # choose group # --------------------------------------------------------------------------- choose_group() { _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Scan for group (default root) " "${SCAN_GROUP:-root}" "*" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi if ! getent group ${a} >/dev/null 2>&1 then mecho --error "Group: ${a} dosn't exist" anykey choose_group fi SCAN_GROUP="${a:-root}" group_col='--info' } # --------------------------------------------------------------------------- # choose filemode # --------------------------------------------------------------------------- choose_filemode() { _out_type='1600:only the user can read and remove 0600:the user can read and write 0660:the group can read and write 0666:all can read and write 0640:the group can read 0644:all can read' techo --begin '3 3r 7 34' idx=1 echo "${_out_type}" | while read line do _f_mode="$(echo "${line}" | /usr/bin/gawk -F: '{ print $1 }')" _f_mesg="$(echo "${line}" | /usr/bin/gawk -F: '{ print $2 }')" techo --row "" "${idx}." "${_f_mode}" "${_f_mesg}" idx=$((${idx} + 1)) done techo --end echo _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Select scan filemode" "$(echo "${_out_type}" | grep -n "${SCAN_FILEMODE:-0600}:"| cut -d':' -f1)" "1-$(echo "${_out_type}" | wc -l)" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then remove_temp_file exit 127 fi action_line="$(echo "${_out_type}" | sed -n "${a}p" | sed 's/^ *//')" SCAN_FILEMODE="$(echo "${action_line}" | /usr/bin/gawk -F: '{ print $1 }')" filemode_col='--info' } # --------------------------------------------------------------------------- # make ini # --------------------------------------------------------------------------- make_ini() { { echo '# -----------------------------------------------------------------------------' echo "# ${ini_file} - eisfair 'scanimage' frontend ini" echo '#' echo "# Creation : ${EISDATE} ${EISTIME}" echo '# -----------------------------------------------------------------------------' printvar 'SCAN_DEV' printvar 'SCAN_MOD' printvar 'SCAN_RES' printvar 'SCAN_MODE' printvar 'SCAN_TLX' printvar 'SCAN_TLY' printvar 'SCAN_WIDTH' printvar 'SCAN_HEIGHT' printvar 'SCAN_TYPE' if [ "${SCAN_TYPE}" = "pdf" ] then printvar 'SCAN_COMPRESS' if [ "${SCAN_COMPRESS}" = "j" ] then printvar 'SCAN_QUALITY' fi fi printvar 'SCAN_PATH' if [ "${_user}" = "root" ] || [ "${_user}" = "saned" ] then printvar 'SCAN_USER' printvar 'SCAN_GROUP' printvar 'SCAN_FILEMODE' fi # ------------------------------------------------------------------------ printend # ------------------------------------------------------------------------ } > ${ini_file} # Set rights chmod 0640 ${ini_file} chown ${_user} ${ini_file} } res_col='--error' mode_col='--error' tlx_col='--error' tly_col='--error' width_col='--error' height_col='--error' type_col='--error' name_col='--error' path_col='--error' user_col='--error' group_col='--error' filemode_col='--error' compress_col='--error' jpeg_quality_col='--error' # --------------------------------------------------------------------------- # show head # --------------------------------------------------------------------------- show_head() { clrhome mecho -n "Scanner: " mecho --warn "${SCAN_MOD}" mecho -n "on : " mecho --warn "${SCAN_DEV}" mecho techo --begin '25 30r 5' techo --row "Resolution:" ${res_col} "${SCAN_RES}" "dpi" techo --row "Mode:" ${mode_col} "${SCAN_MODE}" "" techo --row "Top-left x position:" ${tlx_col} "${SCAN_TLX}" techo --row "Top-left y position:" ${tly_col} "${SCAN_TLY}" techo --row "Width:" ${width_col} "${SCAN_WIDTH}" techo --row "Height:" ${height_col} "${SCAN_HEIGHT}" techo --row "Image type:" ${type_col} "${SCAN_TYPE}" if [ "${SCAN_TYPE}" = "pdf" ] then case "${SCAN_COMPRESS}" in n) comp_text='uncompressed' ;; j) comp_text='compress with JPEG' ;; z) comp_text='compress with Zip/Deflate' ;; esac techo --row "Image compressed:" ${compress_col} "${comp_text}" if [ "${SCAN_COMPRESS}" = "j" ] then techo --row "Image JPEG quality:" ${jpeg_quality_col} "${SCAN_QUALITY}" fi fi techo --row "Image name:" ${name_col} "${SCAN_NAME}" techo --row "Image path:" ${path_col} "${SCAN_PATH}" if [ "${_user}" = "root" ] || [ "${_user}" = "saned" ] then techo --row 'Scan for user:' ${user_col} "${SCAN_USER}" techo --row 'Scan for group:' ${group_col} "${SCAN_GROUP}" techo --row 'Scan filemode:' ${filemode_col} "${SCAN_FILEMODE}" fi techo --end echo } # --------------------------------------------------------------------------- # scanimage # --------------------------------------------------------------------------- ScanImage() { if [ -n "${SCAN_TLX}" ] then _scan_tlxy="-i ${SCAN_TLX} -t ${SCAN_TLY}" fi show_head mecho --info "Scanning in progress ..." /usr/bin/scanimage -d "${SCAN_DEV}" \ --resolution ${SCAN_RES} \ --format=${_scan_type} \ --mode ${SCAN_MODE} \ -x ${SCAN_WIDTH} \ -y ${SCAN_HEIGHT} \ ${_scan_tlxy} -p \ > ${spool_path}/${SCAN_NAME}.${_scan_type} do_check } # --------------------------------------------------------------------------- # do check # --------------------------------------------------------------------------- do_check() { tmp_image=${spool_path}/${SCAN_NAME}.${_scan_type} image_file=${SCAN_PATH}/${SCAN_NAME}.${_file_out} check=$(wc -c ${tmp_image} | cut -f1 -d' ') if [ ${check:-5} -gt 50 ] then echo case ${_file_out} in tiff) ${cmd_sudo} /usr/bin/cp ${tmp_image} ${image_file} rm -f ${tmp_image} ;; png) ${cmd_sudo} /usr/bin/pnmtopng ${tmp_image} > ${image_file} rm -f ${tmp_image} ;; jpg) ${cmd_sudo} /usr/bin/pnmtojpeg ${tmp_image} > ${image_file} rm -f ${tmp_image} ;; pdf) scan_jpeg='' if [ "${SCAN_COMPRESS}" = "j" ] && [ -n "${SCAN_QUALITY}" ] then scan_jpeg="-q ${SCAN_QUALITY}" fi ${cmd_sudo} /usr/bin/tiff2pdf -${SCAN_COMPRESS} ${scan_jpeg} -o ${image_file} ${tmp_image} 2>/dev/null rm -f ${tmp_image} ;; pnm) ${cmd_sudo} /usr/bin/cp ${tmp_image} ${image_file} rm -f ${tmp_image} ;; ps) ${cmd_sudo} /usr/bin/tiff2ps -2 ${tmp_image} -O ${image_file} rm -f ${tmp_image} ;; esac if [ "${_user}" = "root" ] || [ "${_user}" = "saned" ] then ${cmd_sudo} /usr/bin/chown ${SCAN_USER:-root}:${SCAN_GROUP:-root} ${image_file} ${cmd_sudo} /usr/bin/chmod ${SCAN_FILEMODE:-0600} ${image_file} fi mecho --info "...done" remove_temp_file else echo mecho --error "...failure" _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Retry" "yes" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then a=no fi if [ "${a}" = "yes" ] then # SCAN_DEV='' # SCAN_MOD='' # Choose_Device ScanImage else remove_temp_file fi fi } # --------------------------------------------------------------------------- # get scanner info # --------------------------------------------------------------------------- get_scanner_info() { scanimage --help -d "${SCAN_DEV}" > ${_sane_scanimage_tmpfile} 2>/dev/null options_helper=$(grep 'Geometry' -A 8 ${_sane_scanimage_tmpfile}) Width=$(echo "${options_helper}" | grep -- '-x ' | sed 's#.*\(0\..[0-9]\+\).*$#\1#') Height=$(echo "${options_helper}" | grep -- '-y ' | sed 's#.*\(0\..[0-9]\+\).*$#\1#') tlx=$(echo "${options_helper}" | grep -- '-l ' | sed 's#.*\(0\..[0-9]\+\).*$#\1#') tly=$(echo "${options_helper}" | grep -- '-t ' | sed 's#.*\(0\..[0-9]\+\).*$#\1#') } # --------------------------------------------------------------------------- # remove twmpfile # --------------------------------------------------------------------------- remove_temp_file() { rm -f ${_sane_devices_tmpfile} rm -f ${_sane_scanimage_tmpfile} rm -f ${_sane_choose_tmpfile} rm -f ${_sane_geometry_tmpfile} } # --------------------------------------------------------------------------- # list options # --------------------------------------------------------------------------- list_options() { choose_device get_scanner_info show_head choose_resolution show_head choose_mode show_head choose_geometry show_head choose_type show_head if [ "${SCAN_TYPE}" = "pdf" ] then choose_compress show_head if [ "${SCAN_COMPRESS}" = "j" ] then choose_jpeg_quality show_head fi fi choose_name show_head choose_path show_head if [ "${_user}" = "root" ] || [ "${_user}" = "saned" ] then choose_user show_head choose_group show_head choose_filemode show_head fi } # --------------------------------------------------------------------------- # ask options # --------------------------------------------------------------------------- ask_options() { _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Do you want to save these settings" "yes" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then a=no fi if [ "${a}" = "yes" ] then make_ini fi } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- if [ ! -f ${ini_file} ] then list_options ask_options ScanImage else choose_device show_head _ask_tmpfile=$(${MKTEMP} -t XXXXXXXXXXXXX) ${ASK} "Do you want to use these settings" "yes" > ${_ask_tmpfile} rc=${?} read a < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then a=no fi if [ "${a}" = "yes" ] then res_col='--info' mode_col='--info' tlx_col='--info' tly_col='--info' width_col='--info' height_col='--info' type_col='--info' #name_col='-info' path_col='--info' user_col='--info' group_col='--info' filemode_col='--info' compress_col='--info' jpeg_quality_col='--info' echo case ${SCAN_TYPE} in pnm) _scan_type="pnm" _file_out="pnm" ;; tiff) _scan_type="tiff" _file_out="tiff" ;; jpg) _scan_type="pnm" _file_out="jpg" ;; png) _scan_type="pnm" _file_out="png" ;; pdf) _scan_type="tiff" _file_out="pdf" ;; ps) _scan_type="tiff" _file_out="ps" ;; esac # for the name ask always choose_name ScanImage else list_options ask_options ScanImage fi fi remove_temp_file if "${scanbd_stopped:-false}" then if [ "${_user}" = "root" ] || [ "${_user}" = "saned" ] then cat /usr/share/sane/scanbd-start | grep -v '^#' | while read s_unit do ${cmd_sudo} /usr/sbin/service --quiet start ${s_unit} done fi fi exit 0 # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------