epm-filelist 3.04 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012-2013  Etersoft
# Copyright (C) 2012-2013  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 21
load_helper epm-query

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
# TODO: port or rewrite apt-file
# https://bugzilla.altlinux.org/show_bug.cgi?id=14449
# see also epm-search-file
local_content_filelist()
{
    local SYSARCH
    SYSARCH=$(uname -m)
    [ "$SYSARCH" = "x86_64" ] || SYSARCH=i586

    local REPODIR=/var/ftp/pub/ALTLinux/Sisyphus
    local CI=$REPODIR/$SYSARCH/base/contents_index
    local CINOA=$REPODIR/noarch/base/contents_index
    #local OUTCMD="less"
    #[ -n "$USETTY" ] || OUTCMD="cat"
    OUTCMD="cat"

    test -r $CI && test -r $CINOA || fatal "Can't locate $CI or $CINOA"

    {
        [ -n "$USETTY" ] && echo "Search in $CI and $CINOA for $1..."
        grep -h -- ".*$1$" $CI $CINOA | sed -e "s|\(.*\)\t\(.*\)|\1|g"
    } | $OUTCMD
}


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

	case $PMTYPE in
		apt-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
53
			# TODO: use RESTful interface to prometeus? See ALT bug #29496
54 55 56 57 58 59 60 61
			docmd_foreach local_content_filelist $@
			;;
		*)
			fatal "Query filelist for non installed packages does not realized"
			;;
	esac
}

62 63 64 65
__epm_filelist_file()
{
	local CMD

66
	[ -z "$*" ] && return
67

68
	# TODO: allow a new packages
69
	case $(get_package_type $1) in
70
		rpm)
71 72
			CMD="rpm -qlp"
			;;
73
		deb)
74 75 76
			CMD="dpkg --contents"
			;;
		*)
77
			fatal "Have no suitable query command for $PMTYPE"
78 79 80
			;;
	esac

81
	# TODO: add less
82 83 84 85 86 87 88
	docmd $CMD $@
}

__epm_filelist_name()
{
	local CMD

89
	[ -z "$*" ] && return
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

	case $PMTYPE in
		apt-rpm)
			CMD="rpm -ql"
			;;
		apt-dpkg)
			CMD="dpkg -L"
			;;
		yum-rpm)
			CMD="rpm -ql"
			;;
		urpm-rpm)
			CMD="rpm -ql"
			;;
		zypper-rpm)
			CMD="rpm -ql"
			;;
107 108 109
		conary)
			CMD="conary query --ls"
			;;
110
		pacman)
111 112
			docmd pacman -Ql $pkg_names | sed -e "s|.* ||g"
			return
113
			;;
114 115 116 117
		emerge)
			assure_exists equery
			CMD="equery files"
			;;
118
		slackpkg)
119
			is_installed $pkg_names || fatal "Query filelist for non installed packages does not realized"
120 121 122 123
			docmd awk 'BEGIN{desk=1}{if(/^FILE LIST:$/){desk=0} else if (desk==0) {print}}' /var/log/packages/${pkg_filenames}*
			return
			;;
		*)
124
			fatal "Have no suitable query command for $PMTYPE"
125 126 127
			;;
	esac

128
	# TODO: add less
129
	docmd $CMD $pkg_names && return
130
	is_installed $pkg_names || __epm_filelist_remote $pkg_names
131 132 133
}


134
epm_filelist()
135
{
136 137 138 139 140
	[ -n "$pkg_filenames" ] || fatal "Run query without names"


	__epm_filelist_file $pkg_files || return
	__epm_filelist_name $pkg_names || return
141 142

}