#!/bin/sh
# Copyright (c) 2002 SuSE GmbH Nuernberg, Germany.  All rights reserved.
#
# Author: Stefan Dirsch, 2002
#
# 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.
#
# 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, write to the Free Software Foundation,
# Inc., 675 Mass Ave, Cambridge MA 02139, USA.

# Returns success, when a requirement for sound of <command> is detected; 
# otherwise an error is returned

if [ $# -ne 1 ]; then
  echo "Usage: `basename $0` <command>"
  exit 1
fi

command=$1

if [ ! -x $command ]; then
  echo "Command \"$command\" not found or not executable"
  exit 1
fi

file $command|grep executable &> /dev/null
if [ $? -eq 0 ]; then
  # for binary executables
  ldd $command | grep -e libasound.so \
                      -e libartsc.so  \
                      -e libesd.so &> /dev/null
else
  # for shell scripts
  package=`rpm -qf $command 2>/dev/null`
  if [ $? -ne 0 ]; then
    echo "Nothing known about $command (sound might be required)"
    exit 1
  fi
  rpm --requires -q $package | grep -e libasound.so \
                                    -e libartsc.so  \
                                    -e libesd.so &>/dev/null
fi

if [ $? -eq 0 ]; then
  echo "Program needs sound"
else
  echo "Program does not need sound"
  exit 1
fi

exit 0

