You need to sign in or sign up before continuing.
epm-provides 4.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/bin/sh
#
# Copyright (C) 2013  Etersoft
# Copyright (C) 2013  Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

Vitaly Lipatov's avatar
Vitaly Lipatov committed
20
load_helper epm-query
21
load_helper epm-print
Vitaly Lipatov's avatar
Vitaly Lipatov committed
22

23
epm_provides_files()
24
{
25 26
    local pkg_files="$*"
    [ -n "$pkg_files" ] || return
27

28
    local PKGTYPE="$(get_package_type $pkg_files)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
29

30 31 32
    case $PKGTYPE in
        rpm)
            assure_exists rpm
33 34 35 36 37
            if [ -n "$short" ] ; then
                docmd rpm -q --provides -p $pkg_files | sed -e 's| .*||'
            else
                docmd rpm -q --provides -p $pkg_files
            fi
38 39 40 41 42 43 44
            ;;
        deb)
            assure_exists dpkg
            # FIXME: will we provide ourself?
            docmd dpkg -I $pkg_files | grep "^ *Provides:" | sed "s|^ *Provides:||g"
            ;;
        *)
45
            fatal 'Have no suitable command for $PMTYPE'
46 47
            ;;
    esac
48
}
49

50 51 52

epm_provides_names()
{
53 54 55
    local pkg_names="$*"
    local CMD
    [ -n "$pkg_names" ] || return
56 57 58

# by package name
case $PMTYPE in
59 60 61 62 63 64 65
    apt-rpm)
        # FIXME: need fix for a few names case
        # TODO: separate this function to two section
        if is_installed $pkg_names ; then
            CMD="rpm -q --provides"
        else
            EXTRA_SHOWDOCMD=' | grep "Provides:"'
66 67 68 69 70
            if [ -n "$short" ] ; then
                docmd apt-cache show $pkg_names | grep "Provides:" | sed -e 's|, |\n|g' -e 's|Provides: ||' -e 's| .*||'
            else
                docmd apt-cache show $pkg_names | grep "Provides:" | sed -e 's|, |\n|g' -e 's|Provides: ||'
            fi
71 72 73
            return
        fi
        ;;
74
    urpm-rpm)
75 76 77
        if is_installed $pkg_names ; then
            CMD="rpm -q --provides"
        else
78 79 80 81 82 83 84
            CMD="urpmq --provides"
        fi
        ;;
    zypper-rpm)
        if is_installed $pkg_names ; then
            CMD="rpm -q --provides"
        else
85
            fixme "FIXME: use hi level commands or download firstly"
86 87 88 89 90 91
        fi
        ;;
    yum-rpm)
        if is_installed $pkg_names ; then
            CMD="rpm -q --provides"
        else
92
            fixme "FIXME: use hi level commands or download firstly"
93 94
        fi
        ;;
95
    dnf-rpm|dnf5-rpm)
96 97 98 99
        if is_installed $pkg_names ; then
            CMD="rpm -q --provides"
        else
            CMD="dnf repoquery --provides"
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        fi
        ;;
    emerge)
        assure_exists equery
        CMD="equery files"
        ;;
#    yum-rpm)
#        CMD="yum deplist"
#        ;;
    pkgng)
        CMD="pkg info -b"
        ;;
    apt-dpkg)
        # FIXME: need fix for a few names case
        if is_installed $pkg_names ; then
            showcmd dpkg -s $pkg_names
            a='' dpkg -s $pkg_names | grep "^Provides:" | sed "s|^Provides:||g"
            return
        else
            EXTRA_SHOWDOCMD=' | grep "Provides:"'
            docmd apt-cache show $pkg_names | grep "Provides:" | sed -e 's|, |\n|g' | grep -v "^Provides:"
            return
        fi
        ;;
    *)
125
        fatal 'Have no suitable command for $PMTYPE'
126
        ;;
127 128
esac

129 130 131 132 133
if [ -n "$direct" ] && [ "$CMD" = "rpm -q --provides" ] ; then
    # do universal provides
    docmd $CMD $pkg_names | sed -e 's| .*||' | grep -F "()"
    a= $CMD $pkg_names | sed -e 's| .*||' | grep -v -E "^(lib|ld-linux)"
elif [ -n "$short" ] ; then
134 135 136 137
    docmd $CMD $pkg_names | sed -e 's| .*||'
else
    docmd $CMD $pkg_names
fi
138 139

}
140 141 142

epm_provides()
{
143 144 145 146 147 148
    # if possible, it will put pkg_urls into pkg_files or pkg_names
    if [ -n "$pkg_urls" ] ; then
        load_helper epm-download
        __handle_pkg_urls_to_checking
    fi

149
    [ -n "$pkg_filenames" ] || fatal "Provides: package name is missed"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
150

151 152 153
    epm_provides_files $pkg_files
    # shellcheck disable=SC2046
    epm_provides_names $(print_name $pkg_names)
154
}