#!/bin/sh # # vuescan # # Wrapper script for the vuescan scan software from http://www.hamrick.com/ # This fixes some shortcomings vuescan doesn't or hasn't yet addressed. # # INSTALL: # - Put this script into your $PATH. # - Create an empty directory, e.g. /usr/local/pckg/vuescan, # and unpack the vuescan tar file into it. # Edit variable installdir below to the location of this directory. # - Create another empty directory, e.g. /usr/local/pckg/vuescan-bin, # and in it create a symbolic link (ln -s) # called netscape, pointing to this "vuescan" wrapper script. # Edit variable browserbindir below to the location of this directory. # Don't put any other binaries in here. # - Edit variable browser below to the browser you wish to use. # # Copyright (C) by Volker Kuhlmann # Released under the terms of the GNU General Public License (GPL) Version 2. # See http://www.gnu.org/ for details. # # Volker Kuhlmann # 5, 8 Jan; 24 Dec 2003 # 7 Jan; 20 Oct 2004 # 12 Sep; 9 Nov 2005 # 28 May 3006 # 15 May 2011 # chr0(){ echo @;};chr1(){ echo .;} VERSION="2.5, 15 May 2011" AUTHOR="Volker Kuhlmann " COPYRIGHT="Copyright (C) 2003 - 2011" #### #### Constants and initialised variables # # The directory where the vuescan tar file has been unpacked into. # That's the tar file from: http://www.hamrick.com/files/vuesca83.tgz # (from http://www.hamrick.com/vsm.html) installdir="/usr/local/pckg/vuescan" if [ -d "$installdir/vuescan" ]; then installdir="$installdir/vuescan" fi # The browser you want to use with the vuescan help browser="konqueror" # Directory which must contain a binary called "netscape", which will be called # by vuescan. Make this a symlink to this wrapper script, i.e. make a symlink # in this directory called netscape which points to this wrapper script. # NOTE: No longer used with current version of vuescan! browserbindir="/usr/local/pckg/vuescan-bin" if [ ! -d "$browserbindir" ]; then browserbindir="/usr/local/pckg/vuescan/vuescan-bin" fi # Directory which contains the user's vuescan.ini inidir="$HOME/.vuescan" # Name of vuescan's ini file (this must match what's compiled into vuescan!) inifile="vuescan.ini" #### #### Version, Usage, Help # # Call only these from application: Version, Usage, Help # show_version() { echo "`basename $0` wrapper version $VERSION $COPYRIGHT by $AUTHOR" } Version() { show_version; exitwith ErrVersion; } Help() { show_help; exitwith ErrHelp; } show_help() { echo " Usage: `basename $0` [OPTIONS] Wrapper version $VERSION $COPYRIGHT by $AUTHOR Wrapper script for the vuescan scan software from http://www.hamrick.com/ This fixes some shortcomings VueScan doesn't address, namely: 1) User's preferences are splattered all over the filesystem instead of being kept in the same place, like all other well-behaved *ix-applications do it. Since version 8.3, vuescan puts its vuescan.ini into \$HOME - arrrgh, using \$HOME/.vuescan/ would have been fine. Since version 8.3.40, it uses \$HOME/.vuescan/. 2) The help files are only read with a browser 'netscape' which has been history for a few years now. Now it's browser 'mozilla', 'firefox', 'konqueror' or a number of others, and vuescan still doesn't allow you to specify which browser you want to use. (Fixed at some point.) 3) Vuescan doesn't find its auxiliary files unless they're in the same directory; using a wrapper fixes this as a side-effect. (Fixed at some point.) OPTIONS (for the wrapper script, not vuescan itself!): -h|--help Show help. Note: vuescan itself doesn't have any --help. --version Show version --browser PROGRAM Use browser PROGRAM instead (e.g. mozilla) " } #### #### Error/Exit codes # CALL_WITH_HELP_TEXT="Call with --help for help." exitwith() { exec 1>&2 # write stdout on stderr instead case "$1" in ErrVersion|ErrUsage|ErrHelp) # usage already displayed exit 1;; esac } #### #### Parse command line parameters # #### #### Functions # # Obtain the vuescan version, and where it keeps its ini file # As this software doesn't have a --version, we have to pull a trick. get_vuescan_version() { vuescan_version="`strings "$installdir/vuescan" | grep -i 'vuescan .* linux'`" vuescan_version="${vuescan_version#* }" vuescan_version="${vuescan_version% *}" vuescan_inidir="$HOME/.vuescan" # default to the latest version case "$vuescan_version" in 7.*|8.[012].*) vuescan_inidir=".";; 8.3.[0-3]*) vuescan_inidir="$HOME";; *) no_browser_override=1; # Not sure exactly from which version this should be set. esac } # Create user's ini dir if necessary create_ini_dir() { if [ ! -d "$inidir" ]; then echo 1>&2 "Creating user's .ini-file directory: '$inidir'" mkdir -p "$inidir" if [ $? -ne 0 ]; then echo 1>&2 "There was an error creating '$inidir'!" false fi fi } # Copy the user's vuescan.ini into the directory from which the wrapper was # started. # (vuescan can only handle its .ini file in the current directory.) restore_ini() { inifilehome="$inidir/$inifile" # Do nothing if vuescan's vuescan.ini-directory is $inidir. test "$vuescan_inidir" = "$inidir" && return # Create user's ini dir if necessary create_ini_dir # Copy .ini file into its active directory if [ -e "$inifilehome" ]; then cp -p "$inifilehome" "$vuescan_inidir" if [ $? -ne 0 ]; then echo 1>&2 "Couldn't restore '$inifilehome' to '$vuescan_inidir'!!" fi # vuescan needs to write this file chmod 2>/dev/null u+w "$vuescan_inidir/$inifile" else echo 1>&2 "Can't access '$inifilehome'!" echo 1>&2 "\ If vuescan runs for the first time, it will create an .ini file automatically." false fi } # Save the .ini file for the next time backup_ini() { # Do nothing if vuescan's vuescan.ini-directory is $inidir. test "$vuescan_inidir" = "$inidir" && return # Create user's ini dir if necessary create_ini_dir # Copy .ini file from its active location into user's directory if [ -d "$inidir" ]; then if [ -f "$vuescan_inidir/$inifile" ]; then cp -p "$vuescan_inidir/$inifile" "$inidir" rm "$vuescan_inidir/$inifile" else echo 1>&2 "There's no '$vuescan_inidir/$inifile'!!" fi else echo 1>&2 "Can't backup '$vuescan_inidir/$inifile'!" fi } # Start the configured browser. This function never returns. run_browser() { exec "$browser" "$@" exit $? } #### #### Main # case "`basename "$0"`" in mozilla|netscape) run_browser "$@";; esac debug= while [ $# -gt 0 ]; do case "$1" in -h|-help|--help) Help;; --version) Version;; --browser) browser="$2"; shift 2;; --install) installdir="$2"; shift 2;; __browser) shift; run_browser "$@";; # test only --debug) shift; debug="--debug"; set -x;; esac done if [ ! -d "$installdir" ]; then echo 1>&2 " Vuescan directory $installdir doesn't exist. " exit 9 fi backgroundflag__="5e8ba6e8d338bedf77a5c1fb52a1dbc3" if [ "$backgroundflag" != "$backgroundflag__" ]; then # Re-run ourselves in the background, returning the shell prompt export backgroundflag="$backgroundflag__" $0 $debug --browser "$browser" --install "$installdir" "$@" & sleep 1 else installdir="`cd "$installdir"; pwd`" get_vuescan_version restore_ini if [ -z "$no_browser_override" ]; then PATH="$browserbindir:$PATH" export PATH fi "$installdir"/vuescan "$@" ret=$? backup_ini exit $ret fi