epm-filelist 3.92 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

31
    local CI="$(get_local_alt_contents_index)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
32
    [ -n "$CI" ] || fatal "Have no local contents index"
33 34

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

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

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

51 52 53 54 55 56 57

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

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

87 88 89 90
__epm_filelist_file()
{
	local CMD

91
	[ -z "$*" ] && return
92

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

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

__epm_filelist_name()
{
	local CMD

115
	[ -z "$*" ] && return
116

117 118
	warmup_lowbase

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

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


176
epm_filelist()
177
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
178
	[ -n "$pkg_filenames" ] || fatal "Filelist: missing package(s) name"
179 180 181


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

}