epm-filelist 3.41 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012-2015  Etersoft
# Copyright (C) 2012-2015  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
#

20
load_helper epm-query
21
load_helper epm-print
22

23 24 25
# TODO: port or rewrite apt-file
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449
# see also epm-search-file
26
__alt_local_content_filelist()
27
{
28
    load_helper epm-sh-altlinux
29

30 31 32
    local CI="$(get_local_alt_contents_index)"

    # TODO: safe way to use less
33 34 35 36 37
    #local OUTCMD="less"
    #[ -n "$USETTY" ] || OUTCMD="cat"
    OUTCMD="cat"

    {
38 39
        [ -n "$USETTY" ] && echo "Search in $CI for $1..."
        grep -h -- ".*$1$" $CI | sed -e "s|\(.*\)\t\(.*\)|\1|g"
40 41 42
    } | $OUTCMD
}

43 44 45 46 47 48
__deb_local_content_filelist()
{
    showcmd "apt-file list $1 | grep '^$1: ' | sed -e 's|$1: ||g'"
    apt-file list "$1" | grep "^$1: " | sed -e "s|$1: ||g"
}

49 50 51 52 53 54 55

__epm_filelist_remote()
{
	[ -z "$*" ] && return

	case $PMTYPE in
		apt-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
56
			# TODO: use RESTful interface to prometeus? See ALT bug #29496
57
			docmd_foreach __alt_local_content_filelist $@
58
			;;
59
		apt-dpkg)
60 61 62
			assure_exists apt-file || return
			# if sudo requires a password, skip autoupdate
			sudo -n true 2>/dev/null && sudocmd apt-file update || info "sudo requires a password, skip apt-file update"
63
			docmd_foreach __deb_local_content_filelist $@
64
			;;
65 66 67 68 69 70
		*)
			fatal "Query filelist for non installed packages does not realized"
			;;
	esac
}

71 72 73 74
__epm_filelist_file()
{
	local CMD

75
	[ -z "$*" ] && return
76

77
	# TODO: allow a new packages
78
	case $(get_package_type $1) in
79
		rpm)
80
			assure_exists rpm
81 82
			CMD="rpm -qlp"
			;;
83
		deb)
84
			assure_exists dpkg
85 86 87
			CMD="dpkg --contents"
			;;
		*)
88
			fatal "Have no suitable query command for $PMTYPE"
89 90 91
			;;
	esac

Vitaly Lipatov's avatar
Vitaly Lipatov committed
92
	docmd $CMD $@ | less
93 94 95 96 97 98
}

__epm_filelist_name()
{
	local CMD

99
	[ -z "$*" ] && return
100 101

	case $PMTYPE in
102
		*-rpm)
103 104
			CMD="rpm -ql"
			;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
105
		*-dpkg)
106 107
			CMD="dpkg -L"
			;;
108 109 110
		android)
			CMD="pm list packages -f"
			;;
111 112 113
		conary)
			CMD="conary query --ls"
			;;
114
		pacman)
115
			docmd pacman -Ql $@ | sed -e "s|.* ||g" | less
116
			return
117
			;;
118 119 120 121
		emerge)
			assure_exists equery
			CMD="equery files"
			;;
122 123 124
		pkgng)
			CMD="pkg info -l"
			;;
125 126 127 128
		aptcyg)
			docmd apt-cyg listfiles $@ | sed -e "s|^|/|g"
			return
			;;
129
		slackpkg)
130
			is_installed $@ || fatal "Query filelist for non installed packages does not realized"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
131
			docmd awk 'BEGIN{desk=1}{if(/^FILE LIST:$/){desk=0} else if (desk==0) {print}}' /var/log/packages/${pkg_filenames}* | less
132 133 134
			return
			;;
		*)
135
			fatal "Have no suitable query command for $PMTYPE"
136 137 138
			;;
	esac

139
	# TODO: add less
140
	docmd $CMD $@ && return
141
	# TODO: may be we need check is installed before prev. line?
142
	is_installed $@ || __epm_filelist_remote $@
143 144 145
}


146
epm_filelist()
147
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
148
	[ -n "$pkg_filenames" ] || fatal "Filelist: missing package(s) name"
149 150 151


	__epm_filelist_file $pkg_files || return
152
	__epm_filelist_name $(print_name $pkg_names) || return
153 154

}