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

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
		yum-rpm)
			assure_exists yum-utils || return
72
			docmd repoquery -q -l "$@"
73 74 75
			;;
		dnf-rpm)
			assure_exists dnf-plugins-core || return
76 77
			docmd dnf repoquery -l "$@"
			;;
78
		*)
79
			fatal "Query filelist for non installed packages is not implemented yet."
80 81 82 83
			;;
	esac
}

84 85 86 87
__epm_filelist_file()
{
	local CMD

88
	[ -z "$*" ] && return
89

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

Vitaly Lipatov's avatar
Vitaly Lipatov committed
105
	docmd $CMD $@ | less
106 107 108 109 110 111
}

__epm_filelist_name()
{
	local CMD

112
	[ -z "$*" ] && return
113

114 115
	warmup_lowbase

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

160
	# TODO: add less
161
	docmd $CMD $@ && return
162
	# TODO: may be we need check is installed before prev. line?
163
	is_installed $@ || __epm_filelist_remote $@
164 165 166
}


167
epm_filelist()
168
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
169
	[ -n "$pkg_filenames" ] || fatal "Filelist: missing package(s) name"
170 171 172


	__epm_filelist_file $pkg_files || return
Vitaly Lipatov's avatar
Vitaly Lipatov committed
173
	# shellcheck disable=SC2046
174
	__epm_filelist_name $(print_name $pkg_names) || return
175 176

}