You need to sign in or sign up before continuing.
epm-search_file 2.52 KB
Newer Older
1 2
#!/bin/sh
#
Vitaly Lipatov's avatar
Vitaly Lipatov committed
3 4
# Copyright (C) 2012, 2016, 2017  Etersoft
# Copyright (C) 2012, 2016, 2017  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 26 27
# 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
    __local_ercat $1 | grep -h -- ".*$2.*[[:space:]]" | sed -e "s|\(.*\)\t\(.*\)|\2: \1|g" $3
}
28

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

34
    info "Locate contents index file(s) ..."
35
    local CI="$(get_local_alt_contents_index)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
36
    # TODO use something like
Vitaly Lipatov's avatar
Vitaly Lipatov committed
37
    [ -n "$CI" ] || fatal "Have no local contents index"
38 39 40 41

    info "Searching in"
    echo "$CI"
    echo "for $1... "
42

Vitaly Lipatov's avatar
Vitaly Lipatov committed
43 44 45 46 47
    # 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"
48 49
}

50 51
epm_search_file()
{
52
	local CMD
Vitaly Lipatov's avatar
Vitaly Lipatov committed
53
	[ -n "$pkg_filenames" ] || fatal "Search file: missing file name(s)"
54 55

case $PMTYPE in
56
	apt-rpm)
57
		__alt_local_content_search $pkg_filenames
58
		return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
59
	apt-dpkg|aptitude-dpkg)
60
		assure_exists apt-file
61
		sudocmd apt-file update
62 63 64
		docmd apt-file search $pkg_filenames
		return ;;
	yum-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
65
		# TODO
66
		info "Search by full packages list is not implemented yet"
67
		CMD="yum provides"
68
		;;
69
	dnf-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
70
		# TODO
Vitaly Lipatov's avatar
Vitaly Lipatov committed
71
		info "Search by full packages list is not implemented yet"
72 73
		CMD="dnf provides"
		;;
74 75 76
	urpm-rpm)
		CMD="urpmf"
		;;
77
	zypper-rpm)
78 79
		CMD="zypper wp vi"
		;;
80 81 82
	pacman)
		CMD="pacman -Qo"
		;;
83
	slackpkg)
84
		CMD="/usr/sbin/slackpkg file-search"
85
		;;
86
	opkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
87
		CMD="opkg -A search"
88
		;;
89 90 91
	xbps)
		CMD="xbps-query -Ro"
		;;
92
	aptcyg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
93
		docmd apt-cyg searchall "$(echo " $pkg_filenames" | sed -e "s| /| |g")"
94 95
		return
		;;
96
	*)
97
		fatal "Have no suitable search file command for $PMTYPE"
98 99 100 101 102 103
		;;
esac

docmd $CMD $pkg_filenames

}