epm-filelist 4.06 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
			if sudo_allowed ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
65 66 67 68
				sudocmd apt-file update
			else
				info "sudo requires a password, skip apt-file update"
			fi
69
			docmd_foreach __deb_local_content_filelist "$@"
70
			;;
71
		packagekit)
72 73
			docmd pkcon get-files "$@"
			;;
74 75
		yum-rpm)
			assure_exists yum-utils || return
76
			docmd repoquery -q -l "$@"
77 78 79
			;;
		dnf-rpm)
			assure_exists dnf-plugins-core || return
80 81
			docmd dnf repoquery -l "$@"
			;;
82
		*)
83
			fatal "Query filelist for non installed packages is not implemented yet."
84 85 86 87
			;;
	esac
}

88 89 90 91
__epm_filelist_file()
{
	local CMD

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

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

Vitaly Lipatov's avatar
Vitaly Lipatov committed
113
	docmd $CMD $@ | less
114 115 116 117 118 119
}

__epm_filelist_name()
{
	local CMD

120
	[ -z "$*" ] && return
121

122 123
	warmup_lowbase

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

178
	# TODO: add less
179
	docmd $CMD $@ && return
180
	# TODO: may be we need check is installed before prev. line?
181
	is_installed $@ || __epm_filelist_remote $@
182 183 184
}


185
epm_filelist()
186
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
187
	[ -n "$pkg_filenames" ] || fatal "Filelist: package name is missed"
188 189 190


	__epm_filelist_file $pkg_files || return
Vitaly Lipatov's avatar
Vitaly Lipatov committed
191
	# shellcheck disable=SC2046
192
	__epm_filelist_name $(print_name $pkg_names) || return
193 194

}