You are not logged in.

#1 2009-08-04 20:23:47

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,732
Website

pacman to query what has package X as a dep

Sorry for the newbie question, but who is the syntax to have pacman show me what installed packages are needing a particular package?  I know I can go and attempt to remove the package in question, but I'm sure there's a better way smile

Offline

#2 2009-08-04 20:44:47

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: pacman to query what has package X as a dep

Here are some functions from my .bashrc. The earlier ones depend on the later ones. You could of course simplify; I'll leave that to you. If I left any dependencies out, left me know.

pac-requiredby () 
{ 
    if [[ $# -eq 0 ]]; then
        echo -e "Usage: $FUNCNAME [-r] PKG\n\tlist other installed packages that depend on PKG\n\toption -r makes the list recursive" 1>&2;
        return 1;
    fi;
    local RECURSIVE;
    if [[ "$1" == -r ]]; then
        RECURSIVE=1;
        shift;
    fi;
    if [[ $# -ne 1 ]]; then
        echo "$FUNCNAME only works on single package" 1>&2;
        return 1;
    fi;
    local next i j;
    if pac-installed "$@"; then
        _pac_first=($(pacman -Qi "$@" 2>/dev/null | sed -nr -e '/^Required By\s*: / {s///; /^None$/q; h; :a; n; /:/!{H; ba}; g; s/\s*\n\s*/ /g; p}'));
        if [[ RECURSIVE -eq 1 ]]; then
            function lambda () 
            { 
                _pac_next=($(pac-requiredby "${1%>*}"));
                if [[ ${#_pac_next[@]} -gt 0 ]]; then
                    _pac_first=($(arrayunion _pac_first _pac_next));
                fi
            };
            arrayall _pac_first lambda;
        fi;
        arrayecho _pac_first;
    else
        if pacman -Si "$*" > /dev/null 2>&1; then
            echo "error: package '$*' is not installed" 1>&2;
            return 1;
        else
            echo "error: package '$*' was not found" 1>&2;
            return 1;
        fi;
    fi
}

pac-installed () 
{ 
    if [[ $# -eq 0 ]]; then
        echo -e "Usage: $FUNCNAME PKGS\n\ttest whether packages are installed" 1>&2;
        return 1;
    fi;
    pacman -Q "$@" > /dev/null 2>&1
}

arrayunion () 
{ 
    local full line=0;
    full=$(arrayecho -d'
' "$@");
    echo "$full" | while read first; do
        ((line++));
        echo "$full" | for ((j=0; j<line-1; j++))
        do
            read second;
            if [[ "$first" == "$second" ]]; then
                return 1;
            fi;
        done;
        if [[ $? -eq 0 ]]; then
            echo "$first";
        fi;
    done
}

arrayecho () 
{ 
    OPTIND=1;
    local DELIM=" " opt delim f i;
    while getopts "d:" opt; do
        case "$opt" in 
            d)
                DELIM="$OPTARG"
            ;;
        esac;
    done;
    shift $((OPTIND-1));
    for f in "$@";
    do
        for ((i=0; i<$(arraylen "$f"); i++))
        do
            eval echo -n "\"${delim}\${$f[$i]}\"";
            delim="$DELIM";
        done;
    done;
    echo
}

arraylen () 
{ 
    [[ $# -eq 1 ]] || { 
        echo "$FUNCNAME: requires one argument" 1>&2;
        return 2
    };
    eval echo "\"\${#$1[@]}\""
}

Offline

#3 2009-08-04 20:45:54

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: pacman to query what has package X as a dep

The easier, by-hand, way is to do "pacman -Qi PACKAGE_NAME" and inspect the "Required By:" field. :-)

Offline

#4 2009-08-04 20:54:19

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,732
Website

Re: pacman to query what has package X as a dep

Thank, Profjim.

Offline

#5 2009-08-04 21:58:41

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: pacman to query what has package X as a dep

There is also the "whoneeds" script that was sucked into the pkgtools package, it works quite well.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#6 2009-08-05 00:08:29

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: pacman to query what has package X as a dep

It's in git right now, but I was actually working on it the other day to see if I can get it ready with a new release.

Offline

Board footer

Powered by FluxBB