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

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
    local CI="$(get_local_alt_contents_index)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
31
    [ -n "$CI" ] || fatal "Have no local contents index"
32 33

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

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

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

50 51 52 53 54 55 56

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

	case $PMTYPE in
		apt-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
57
			# TODO: use RESTful interface to prometeus? See ALT bug #29496
58
			docmd_foreach __alt_local_content_filelist $@
59
			;;
60
		apt-dpkg)
61 62 63
			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"
64
			docmd_foreach __deb_local_content_filelist $@
65
			;;
66
		*)
67
			fatal "Query filelist for non installed packages is not implemented yet."
68 69 70 71
			;;
	esac
}

72 73 74 75
__epm_filelist_file()
{
	local CMD

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

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

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

__epm_filelist_name()
{
	local CMD

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

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

146
	# TODO: add less
147
	docmd $CMD $@ && return
148
	# TODO: may be we need check is installed before prev. line?
149
	is_installed $@ || __epm_filelist_remote $@
150 151 152
}


153
epm_filelist()
154
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
155
	[ -n "$pkg_filenames" ] || fatal "Filelist: missing package(s) name"
156 157 158


	__epm_filelist_file $pkg_files || return
159
	__epm_filelist_name $(print_name $pkg_names) || return
160 161

}