#! /bin/bash #---------------------------------------------------------------------------- # /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 # # 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 packageName='sane' if [ -f /etc/sane.d/scan.ini ] then use_ini='true' # include scan.ini . /etc/sane.d/scan.ini fi _sane_devices_tmpfile=`mktemp -t sane_devices_tmpfile.XXXXXXXXXX` _sane_scanimage_tmpfile=`mktemp -t sane_scanimage_tmpfile.XXXXXXXXXX` scanimage -L | grep -v 'net' | cut -f2- -d'`' | tr ' ' '_'> ${_sane_devices_tmpfile} Choose_Device() { count=`wc -l ${_sane_devices_tmpfile} | cut -f1 -d' '` idx=1 while read devices do eval DEVICE_${idx}_1=`echo ${devices//\'*}` eval DEVICE_${idx}_2=`echo $devices | cut -f4- -d"_"` export DEVICE_${idx}_1 export DEVICE_${idx}_2 idx=`/usr/bin/expr ${idx} + 1` done < ${_sane_devices_tmpfile} SCAN_DEV=${DEVICE_1_1} SCAN_MOD=`echo ${DEVICE_1_2} | tr "_" " "` if [ "${count}" -gt '1' ] then _sane_choose_tmpfile=`mktemp -t sane_choose_tmpfile.XXXXXXXXXX` DEVICE_TITLE="SANE - Frontend for scanimage" DEVICE_SUBTITLE="Choose Scanner" DEVICE_QUESTION="Select" DEVICE_COLS='25 25*' DEVICE_ROWS=${count} DEVICE_FLAGS='- indent 12' DEVICE_CAPTION_1='-warn "Device"' DEVICE_CAPTION_2='-warn "Name"' export DEVICE_TITLE export DEVICE_SUBTITLE export DEVICE_QUESTION export DEVICE_COLS export DEVICE_ROWS export DEVICE_FLAGS export DEVICE_CAPTION_1 export DEVICE_CAPTION_2 /var/install/bin/choose DEVICE > ${_sane_choose_tmpfile} idy=`cat ${_sane_choose_tmpfile}` eval SCAN_DEV='${DEVICE_'${idy}'_1}' eval SCAN_MOD='${DEVICE_'${idy}'_2}' SCAN_MOD=`echo ${SCAN_MOD} | tr "_" " "` fi } Choose_Resolution() { scanimage -h -d ${SCAN_DEV} > ${_sane_scanimage_tmpfile} options=`grep '\--resolution' ${_sane_scanimage_tmpfile}` if [ ! "${use_ini}" == 'true' ] then SCAN_RES=`echo ${options} | cut -f3 -d' ' | sed 's/\[//g' | sed 's/\]//g'` fi options=`echo ${options} | cut -f2 -d' ' | tr '|' ' ' | sed '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}" -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 SCAN_RES=`/var/install/bin/ask "Resolution" "${SCAN_RES}" ${options}` res_col='-info' } Choose_Mode() { options=`grep '\--mode' ${_sane_scanimage_tmpfile}` if [ ! "${use_ini}" == 'true' ] then SCAN_MODE=`echo ${options} | cut -f3 -d' ' | sed 's/\[//g' | sed '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} SCAN_MODE=`/var/install/bin/ask "Mode" "${SCAN_MODE}" ${options}` mode_col='-info' } 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}" == 'true' ] then SCAN_TLX=`echo ${tlx} | cut -f4 -d' ' | sed 's/\[//g' | sed 's/\]//g'` SCAN_TLY=`echo ${tlx} | cut -f13 -d' ' | sed 's/\[//g' | sed 's/\]//g'` fi mecho -info "Value must be between ${tlx}" SCAN_TLX=`/var/install/bin/ask "Top left x position of scan area" "${SCAN_TLX}" ${options}` tlx_col='-info' Show_Head mecho -info "Value must be between ${tly}" SCAN_TLX=`/var/install/bin/ask "Top left y position of scan area" "${SCAN_TLY}" ${options}` tly_col='-info' } Choose_WidthHeight() { Show_Head Width=`echo $options_helper | cut -f21 -d' ' | sed 's/mm//g'` Height=`echo $options_helper | cut -f27 -d' ' | sed 's/mm//g'` if [ ! "${use_ini}" == 'true' ] then SCAN_WIDTH=`echo ${Width} | cut -f22 -d' ' | sed 's/\[//g' | sed 's/\]//g'` SCAN_HEIGHT=`echo ${Height} | cut -f28 -d' ' | sed 's/\[//g' | sed 's/\]//g'` fi mecho -info "Value must be between ${Width}" SCAN_WIDTH=`/var/install/bin/ask "Width of scan area" "${SCAN_WIDTH}" ${options}` width_col='-info' Show_Head mecho -info "Value must be between ${Height}" SCAN_HEIGHT=`/var/install/bin/ask "Height of scan area" "${SCAN_HEIGHT}" ${options}` height_col='-info' } Choose_Geometry() { _sane_geometry_tmpfile=`mktemp -t sane_geometry_tmpfile.XXXXXXXXXX` options_helper=`grep 'Geometry' -A 8 ${_sane_scanimage_tmpfile}` Width=`echo ${options_helper} | cut -f21 -d' ' | sed 's/mm//g'` Height=`echo ${options_helper} | cut -f27 -d' ' | sed 's/mm//g'` if [ ${use_ini} == 'true' ] 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' 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}" ] || [ "${Height//0..}" -lt "${guik2}" ] then eval GEOMETRY_${idx}_ACTIVE="no" export GEOMETRY_${idx}_ACTIVE fi export GEOMETRY_${idx}_1 export GEOMETRY_${idx}_2 export GEOMETRY_${idx}_3 idx=`/usr/bin/expr ${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 > ${_sane_geometry_tmpfile} idy=`cat ${_sane_geometry_tmpfile}` eval SCAN_PAGE='${GEOMETRY_'${idy}'_1}' eval SCAN_WIDTH='${GEOMETRY_'${idy}'_2}' eval SCAN_HEIGHT='${GEOMETRY_'${idy}'_3}' if [ -z "${idy}" ] then SCAN_WIDTH="${w}" SCAN_HEIGHT="${h}" fi if [ "${SCAN_PAGE}" == 'custom' ] then Choose_TLXY Choose_WidthHeight else tlx_col='-info' width_col='-info' tly_col='-info' height_col='-info' fi } Choose_Type() { if [ ! "${use_ini}" == 'true' ] then SCAN_TYPE='pnm' fi SCAN_TYPE=`/var/install/bin/ask "Image type" "${SCAN_TYPE}" "tif" "pnm" "png" "jpg" "pdf"` type_col='-info' } Choose_Name(){ SCAN_NAME=`/var/install/bin/ask "Image name" "ImageScan-${EISDATE}" "*"` name_col='-info' } Choose_Path(){ if [ ! "${use_ini}" == 'true' ] then SCAN_PATH=$(pwd) fi SCAN_PATH=`/var/install/bin/ask "Full path " "${SCAN_PATH}" "*"` path_col='-info' } MakeINI() { ini_file='/etc/sane.d/scan.ini' { echo '# ------------------------------------------------------------------------' echo '# /etc/sane.d/scan.ini - Eisfair scanimage frontend ini' echo '#' echo "# Creation : ${EISDATE} dr_snuggles" 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" printvar "SCAN_PATH" # ------------------------------------------------------------------------ printend # ------------------------------------------------------------------------ } > ${ini_file} # Set rights chmod 0600 ${ini_file} chown root ${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' Show_Head() { clrhome mecho -n "Scanner: "; mecho -warn -n "${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}" techo row "Image name:" ${name_col} "${SCAN_NAME}" techo row "Image path:" ${path_col} "${SCAN_PATH}" techo end mecho } ScanImage() { Show_Head mecho -info "Scanning in progress ..." scanimage -d ${SCAN_DEV} --resolution ${SCAN_RES} \ --mode ${SCAN_MODE} -i ${SCAN_TLX} -t ${SCAN_TLY} \ -x ${SCAN_WIDTH} -y ${SCAN_HEIGHT} -p \ > ${SCAN_PATH}/${SCAN_NAME}.${SCAN_TYPE} Do_Check } Do_Check() { Check=`wc -c ${SCAN_PATH}/${SCAN_NAME}.${SCAN_TYPE} | cut -f1 -d' '` if [ "${Check}" -gt '50' ] then mecho mecho -info "...done" else mecho mecho -error "...failure" if /var/install/bin/ask "Retry" "yes" then SCAN_DEV='' SCAN_MOD='' Choose_Device ScanImage fi fi } # --------------------------------------------------------------------------- if [ ! -f /etc/sane.d/scan.ini ] then Choose_Device Show_Head Choose_Resolution Show_Head Choose_Mode Show_Head Choose_Geometry Show_Head Choose_Type Show_Head Choose_Name Show_Head Choose_Path Show_Head if /var/install/bin/ask "Do you want to save these settings" "yes" then MakeINI fi ScanImage else Choose_Device Show_Head if /var/install/bin/ask "Do you want to use these settings" "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' Choose_Name ScanImage else clrhome Choose_Device Show_Head Choose_Resolution Show_Head Choose_Mode Show_Head Choose_Geometry Show_Head Choose_Type Show_Head Choose_Name Show_Head Choose_Path Show_Head if /var/install/bin/ask "Do you want to save these settings" "yes" then MakeINI fi ScanImage fi fi rm -f ${_sane_devices_tmpfile} rm -f ${_sane_scanimage_tmpfile} rm -f ${_sane_choose_tmpfile} rm -f ${_sane_geometry_tmpfile}