Echo dependencies of an installed rpm package over Linux bash shell

Script:

#!/bin/bash
# File: rpmdeps.sh
#set -x

RTVAL=0; export RTVAL

cd `dirname $0`
WORKDIR=$PWD; export WORKDIR

test ! -z "$1" || {
    echo "Error, RPM name is required."
    exit 1
}

TMPFILE=`mktemp /tmp/known_rpms.XXXXXX` || {
    echo "Error, $TMPFILE can't be generated."
    exit 1
}
export TMPFILE
echo "temp file: '$TMPFILE'"

rpmdeps()
{
    rpm_name_current=$1

    # return if current is not a rpm name
    rpm -q "$rpm_name_current" >/dev/null || {
        return 1;
    }

    grep "$rpm_name_current" $TMPFILE >/dev/null && {
        return 0;
    }
    echo "$rpm_name_current" | tee -a $TMPFILE

    for rpmname in $(rpm -qR $rpm_name_current | grep -v '([^()]*)' | grep -o '^[^<>= /]*' | tr '\n' '\t'); do
        rpmdeps $rpmname
    done

    return 0
}

rpmdeps "$1" || {
    echo "rpm $1 is not exists."
    RTVAL=1
}

rm -f $TMPFILE
exit $RTVAL

Usage:

$ ./rpmdeps.sh <rpmname>



你可能感兴趣的:(Echo dependencies of an installed rpm package over Linux bash shell)