epm-filelist 3.96 KB
Newer Older
1 2
#!/bin/sh
#
Vitaly Lipatov's avatar
Vitaly Lipatov committed
3 4
# Copyright (C) 2012-2018  Etersoft
# Copyright (C) 2012-2018  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
load_helper epm-sh-warmup
23

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

32 33
    update_alt_contents_index
    local CI="$(cat $ALT_CONTENTS_INDEX_LIST)"
34 35

    # TODO: safe way to use less
36 37 38 39 40
    #local OUTCMD="less"
    #[ -n "$USETTY" ] || OUTCMD="cat"
    OUTCMD="cat"

    {
Vitaly Lipatov's avatar
Vitaly Lipatov committed
41
        [ -n "$USETTY" ] && info "Search in $CI for $1..."
42
        __local_ercat $CI | grep -h -P -- ".*\t$1$" | sed -e "s|\(.*\)\t\(.*\)|\1|g"
43 44 45
    } | $OUTCMD
}

46 47 48
__deb_local_content_filelist()
{
    showcmd "apt-file list $1 | grep '^$1: ' | sed -e 's|$1: ||g'"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
49
    a='' apt-file list "$1" | grep "^$1: " | sed -e "s|$1: ||g"
50 51
}

52 53 54 55 56 57 58

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

	case $PMTYPE in
		apt-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
59
			# TODO: use RESTful interface to prometeus? See ALT bug #29496
60
			docmd_foreach __alt_local_content_filelist "$@"
61
			;;
62
		apt-dpkg)
63
			assure_exists apt-file || return
64 65
			# TODO: improve me
			if sudorun -n true 2>/dev/null ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
66 67 68 69
				sudocmd apt-file update
			else
				info "sudo requires a password, skip apt-file update"
			fi
70
			docmd_foreach __deb_local_content_filelist "$@"
71
			;;
72
		packagekit)
73 74
			docmd pkcon get-files "$@"
			;;
75 76
		yum-rpm)
			assure_exists yum-utils || return
77
			docmd repoquery -q -l "$@"
78 79 80
			;;
		dnf-rpm)
			assure_exists dnf-plugins-core || return
81 82
			docmd dnf repoquery -l "$@"
			;;
83
		*)
84
			fatal "Query filelist for non installed packages is not implemented yet."
85 86 87 88
			;;
	esac
}

89 90 91 92
__epm_filelist_file()
{
	local CMD

93
	[ -z "$*" ] && return
94

95
	# TODO: allow a new packages
96
	case $(get_package_type $1) in
97
		rpm)
98
			assure_exists rpm
99 100
			CMD="rpm -qlp"
			;;
101
		deb)
102
			assure_exists dpkg
103 104 105
			CMD="dpkg --contents"
			;;
		*)
106
			fatal "Have no suitable query command for $PMTYPE"
107 108 109
			;;
	esac

Vitaly Lipatov's avatar
Vitaly Lipatov committed
110
	docmd $CMD $@ | less
111 112 113 114 115 116
}

__epm_filelist_name()
{
	local CMD

117
	[ -z "$*" ] && return
118

119 120
	warmup_lowbase

121
	case $PMTYPE in
122
		*-rpm)
123 124
			CMD="rpm -ql"
			;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
125
		*-dpkg)
126 127
			CMD="dpkg -L"
			;;
128
		packagekit)
129 130
			CMD="pkcon get-files"
			;;
131 132 133
		android)
			CMD="pm list packages -f"
			;;
134 135 136
		conary)
			CMD="conary query --ls"
			;;
137
		pacman)
138
			docmd pacman -Ql $@ | sed -e "s|.* ||g" | less
139
			return
140
			;;
141 142 143 144
		emerge)
			assure_exists equery
			CMD="equery files"
			;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
145 146 147
		homebrew)
			CMD="brew list"
			;;
148 149 150
		pkgng)
			CMD="pkg info -l"
			;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
151 152 153
		opkg)
			CMD="opkg files"
			;;
154 155 156
		xbps)
			CMD="xbps-query -f"
			;;
157 158 159 160
		aptcyg)
			docmd apt-cyg listfiles $@ | sed -e "s|^|/|g"
			return
			;;
161
		slackpkg)
162
			is_installed $@ || fatal "Query filelist for non installed packages is not implemented yet"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
163
			docmd awk 'BEGIN{desk=1}{if(/^FILE LIST:$/){desk=0} else if (desk==0) {print}}' /var/log/packages/${pkg_filenames}* | less
164 165 166
			return
			;;
		*)
167
			fatal "Have no suitable query command for $PMTYPE"
168 169 170
			;;
	esac

171
	# TODO: add less
172
	docmd $CMD $@ && return
173
	# TODO: may be we need check is installed before prev. line?
174
	is_installed $@ || __epm_filelist_remote $@
175 176 177
}


178
epm_filelist()
179
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
180
	[ -n "$pkg_filenames" ] || fatal "Filelist: package name is missed"
181 182 183


	__epm_filelist_file $pkg_files || return
Vitaly Lipatov's avatar
Vitaly Lipatov committed
184
	# shellcheck disable=SC2046
185
	__epm_filelist_name $(print_name $pkg_names) || return
186 187

}