#! /bin/bash

# Johannes Meixner <jsmeix@suse.de>, 2004, 2005, 2006, 2007, 2008, 2010
#
# Copyright (c) 2010 Novell, Inc.
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail,
# you may find current contact information at www.novell.com

#set -x

export PATH="/sbin:/usr/sbin:/usr/bin:/bin"
export LC_ALL="POSIX"
export LANG="POSIX"

MY_NAME=${0##*/}
BACKEND="$1"
[ -z "$BACKEND" ] && { echo -en "\nUsage:\n$MY_NAME backend\n" 1>&2 ; exit 1 ; }

DLL_CONF="/etc/sane.d/dll.conf"
[ -r $DLL_CONF ] || { echo "Cannot read $DLL_CONF" 1>&2 ; exit 2 ; }
[ -w $DLL_CONF ] || { echo "Cannot write $DLL_CONF" 1>&2 ; exit 3 ; }

grep -q "^[[:space:]]*#*[[:space:]]*$BACKEND[[:space:]]*\$" $DLL_CONF || { echo "$BACKEND not found in $DLL_CONF" 1>&2 ; exit 4 ; }

sed -i -e "s/^$BACKEND\$/#$BACKEND/" $DLL_CONF || { echo "Failed to deactivate $BACKEND in $DLL_CONF" 1>&2 ; exit 5 ; }

exit 0

