epm-search_file 3.24 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2016, 2017, 2019  Etersoft
# Copyright (C) 2012, 2016, 2017, 2019  Vitaly Lipatov <lav@etersoft.ru>
5
#
6 7 8
# 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
9 10 11 12 13
# (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
14
# GNU Affero General Public License for more details.
15
#
16 17
# 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/>.
18 19
#

Vitaly Lipatov's avatar
Vitaly Lipatov committed
20 21 22 23 24 25
# TODO: see epm-search (colorify for all distro)

# args: index_lists word grep_string
__alt_search_file_output()
{
    # grep only on left part (filename), then revert order and grep with color
26
    ercat $quiet $1 | grep -h -- ".*$2.*[[:space:]]" | sed -e "s|\(.*\)\t\(.*\)|\2: \1|g" $3
Vitaly Lipatov's avatar
Vitaly Lipatov committed
27
}
28

29
__alt_local_content_search()
30
{
31
    load_helper epm-sh-altlinux
32
    load_helper epm-sh-altlinux-contents-index
Vitaly Lipatov's avatar
Vitaly Lipatov committed
33
    load_helper epm-search
34

35 36 37
    check_alt_contents_index || init_alt_contents_index
    update_repo_if_needed

38
    if [ ! -s "$ALT_CONTENTS_INDEX_LIST" ] ; then
39
        fatal "There was some error in contents index retrieving. Try run 'epm update' again."
40 41
    fi

42
    local CI="$(ls $(cat $ALT_CONTENTS_INDEX_LIST) 2>/dev/null)"
43

44
    info "Searching for" "$1... "
45

Vitaly Lipatov's avatar
Vitaly Lipatov committed
46 47 48 49 50
    # FIXME: do it better
    local MGS
    MGS=$(eval __epm_search_make_grep $quoted_args)
    showcmd "$ cat contents_index $MGS"
    eval "__alt_search_file_output \"$CI\" \"$(eval get_firstarg $quoted_args)\" $MGS"
51 52
}

53 54
epm_search_file()
{
55 56
    local CMD
    [ -n "$pkg_filenames" ] || fatal "Search file: file name is missed"
57

58 59
case $BASEDISTRNAME in
    "alt")
60 61
        __alt_local_content_search $pkg_filenames
        return ;;
62 63 64
esac

case $PMTYPE in
65
    apt-dpkg|aptitude-dpkg)
66 67 68 69
        if ! is_command apt-file ; then
            assure_exists apt-file
            sudocmd apt-file update
        else
Vitaly Lipatov's avatar
Vitaly Lipatov committed
70
            load_helper epm-check_updated_repo
71 72
            update_repo_if_needed
        fi
73 74 75 76 77 78 79 80 81 82
        docmd apt-file search $pkg_filenames
        return ;;
    packagekit)
        CMD="pkcon search file"
        ;;
    yum-rpm)
        # TODO
        info "Search by full packages list is not implemented yet"
        CMD="yum provides"
        ;;
83
    dnf-rpm|dnf5-rpm)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
        # TODO
        info "Search by full packages list is not implemented yet"
        CMD="dnf provides"
        ;;
    urpm-rpm)
        CMD="urpmf"
        ;;
    zypper-rpm)
        CMD="zypper search --file-list"
        ;;
    pacman)
        CMD="pacman -Qo"
        ;;
    slackpkg)
        CMD="/usr/sbin/slackpkg file-search"
        ;;
    opkg)
        CMD="opkg -A search"
        ;;
    eopkg)
        CMD="eopkg search-file"
        ;;
106 107 108
    pisi)
        CMD="pisi search-file"
        ;;
109 110 111 112 113 114 115 116
    xbps)
        CMD="xbps-query -Ro"
        ;;
    aptcyg)
        docmd apt-cyg searchall $(echo " $pkg_filenames" | sed -e "s| /| |g")
        return
        ;;
    *)
117
        fatal 'Have no suitable search file command for $PMTYPE'
118
        ;;
119 120 121 122 123
esac

docmd $CMD $pkg_filenames

}