epm-info 3.45 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2014, 2016  Etersoft
# Copyright (C) 2012, 2014, 2016  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
__epm_info_rpm_low()
{
	if [ -n "$pkg_files" ] ; then
		docmd rpm -qip $pkg_files
	fi
	[ -z "$pkg_names" ] && return
28
	is_installed $pkg_names && docmd rpm -qi $pkg_names && return
29 30
}

31
__epm_info_by_pkgtype()
32
{
33
	[ -n "$pkg_files" ] || return 1
Vitaly Lipatov's avatar
Vitaly Lipatov committed
34

35 36 37 38 39 40 41 42 43 44 45 46
	case $(get_package_type $pkg_files) in
		rpm)
			__epm_info_rpm_low && return
			;;
		deb)
			docmd dpkg -I $pkg_files
			;;
		*)
			return 1
			;;
	esac
}
Vitaly Lipatov's avatar
Vitaly Lipatov committed
47

48 49
__epm_info_by_pmtype()
{
50
case $PMTYPE in
51
	apt-rpm)
52
		__epm_info_rpm_low && return
53 54 55
		docmd apt-cache show $pkg_names
		;;
	apt-dpkg)
56 57 58
		if [ -n "$pkg_files" ] ; then
			docmd dpkg -I $pkg_files
		fi
59
		[ -z "$pkg_names" ] && return
60
		is_installed $pkg_names && docmd dpkg -p $pkg_names && return
61
		docmd apt-cache show $pkg_names
62
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
63 64 65 66 67 68 69
	aptitude-dpkg)
		if [ -n "$pkg_files" ] ; then
			docmd dpkg -I $pkg_files
		fi
		[ -z "$pkg_names" ] && return
		docmd aptitude show $pkg_names
		;;
70
	yum-rpm)
71
		__epm_info_rpm_low && return
72
		docmd yum info $pkg_names
73
		;;
74 75 76 77
	urpmi-rpm)
		__epm_info_rpm_low && return
		docmd urpmq -i $pkg_names
		;;
78 79 80 81
	dnf-rpm)
		__epm_info_rpm_low && return
		docmd dnf info $pkg_names
		;;
82
	zypper-rpm)
83
		__epm_info_rpm_low && return
84 85 86
		docmd zypper info $pkg_names
		;;
	pacman)
87
		is_installed $pkg_names && docmd pacman -Qi $pkg_names && return
88
		docmd pacman -Si $pkg_names
89
		;;
90 91 92 93
	aura)
		is_installed $pkg_names && docmd pacman -Qi $pkg_names && return
		docmd aura -Ai $pkg_names
		;;
94 95 96 97
	npackd)
		# FIXME: --version=
		docmd npackdcl info --package=$pkg_names
		;;
98 99 100 101
	conary)
		is_installed $pkg_names && docmd conary query $pkg_names --info && return
		docmd conary repquery $pkg_names --info
		;;
102 103 104 105 106 107 108
	emerge)
		assure_exists equery
		docmd equery meta $pkg_names
		docmd equery which $pkg_names
		docmd equery uses $pkg_names
		docmd equery size $pkg_names
		;;
109
	slackpkg)
110
		docmd /usr/sbin/slackpkg info $pkg_names
111
		;;
112 113
	opkg)
		docmd opkg info $pkg_names
114
		;;
115 116 117
	pkgng)
		docmd pkg info $pkg_names
		;;
118 119 120
	xbps)
		docmd xbps-query --show $pkg_names
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
121 122 123
	homebrew)
		docmd brew info $pkg_names
		;;
124 125 126
	aptcyg)
		docmd apt-cyg show $pkg_names
		;;
127
	*)
128
		fatal "Have no suitable command for $PMTYPE"
129 130
		;;
esac
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
}


# TODO: separate to _files and _names parts
# implement _files part per package, not by PMTYPE (see filelist)
epm_info()
{

# if possible, it will put pkg_urls into pkg_files or pkg_names
if [ -n "$pkg_urls" ] ; then
    load_helper epm-download
    __handle_pkg_urls_to_checking
fi

[ -n "$pkg_filenames" ] || fatal "Info: missing package(s) name"

__epm_info_by_pkgtype || __epm_info_by_pmtype
148

149 150 151 152
local RETVAL=$?

# TODO: reinvent
[ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
153
[ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
154 155

return $RETVAL
156
}