epm-packages 2.75 KB
Newer Older
Danil Mikhailov's avatar
Danil Mikhailov committed
1 2 3 4 5
#!/bin/sh
#
# Copyright (C) 2012  Etersoft
# Copyright (C) 2012  Vitaly Lipatov <lav@etersoft.ru>
#
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
Danil Mikhailov's avatar
Danil Mikhailov committed
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.
Danil Mikhailov's avatar
Danil Mikhailov committed
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/>.
Danil Mikhailov's avatar
Danil Mikhailov committed
18 19
#

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
__epm_packages_sort()
{
# FIXME: sort depends on --sort value
case $PMTYPE in
	apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
		docmd rpm -qa --queryformat "%{size} %{name}-%{version}-%{release}\n" $pkg_filenames | sort -n
		;;
	apt-dpkg)
		docmd dpkg-query -W --showformat="\${Size} \${Package}-\${Version}\n" $pkg_filenames | sort -n
		;;
	*)
		fatal "Sorted package list are not realized for $PMTYPE"
		;;
esac
}

Danil Mikhailov's avatar
Danil Mikhailov committed
36
epm_packages()
Danil Mikhailov's avatar
Danil Mikhailov committed
37
{
38
	local CMD
39
	[ -n "$sort" ] && __epm_packages_sort && return
Danil Mikhailov's avatar
Danil Mikhailov committed
40

Vitaly Lipatov's avatar
Vitaly Lipatov committed
41 42
case $PMTYPE in
	apt-rpm)
43
		CMD="rpm -qa $pkg_filenames"
44
		[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
Danil Mikhailov's avatar
Danil Mikhailov committed
45
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
46
	*-dpkg)
47 48
		#CMD="dpkg -l $pkg_filenames"
		CMD="dpkg-query -W --showformat=\${Package}-\${Version}\n $pkg_filenames"
49
		[ -n "$short" ] && CMD="dpkg-query -W --showformat=\${Package}\n $pkg_filenames"
Danil Mikhailov's avatar
Danil Mikhailov committed
50
		;;
51
	yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
52
		CMD="rpm -qa $pkg_filenames"
53
		[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
Danil Mikhailov's avatar
Danil Mikhailov committed
54
		;;
55
	emerge)
56 57 58
		CMD="qlist -I -C"
		# print with colors for console output
		isatty && CMD="qlist -I"
59
		;;
60
	pkgsrc)
61 62
		CMD="pkg_info"
		;;
63
	pacman)
64 65 66 67 68
		CMD="pacman -Qs $pkg_filenames"
		if [ -n "$short" ] ; then
			docmd $CMD | sed -e "s| .*||g" -e "s|.*/||g" | grep -v "^$"
			return
		fi
69
		;;
70
	npackd)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
71 72
		CMD="npackdcl list --status=installed"
		# TODO: use search if pkg_filenames is not empty
73
		;;
74 75 76
	conary)
		CMD="conary query"
		;;
77 78 79
#	chocolatey)
#		CMD="chocolatey list"
#		;;
80
	slackpkg)
81
		CMD="ls -1 /var/log/packages/"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
82
		if [ -n "$short" ] ; then
83 84 85 86
			# FIXME: does not work for libjpeg-v8a
			# TODO: remove last 3 elements (if arch is second from the last?)
			# FIXME this hack
			docmd ls -1 /var/log/packages/ | sed -e "s|-[0-9].*||g" | sed -e "s|libjpeg-v8a.*|libjpeg|g"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
87 88
			return
		fi
89
		;;
90
	homebrew)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
91
		CMD="brew list $pkg_filenames"
92 93 94 95
		;;
	ipkg)
		CMD="ipkg list"
		;;
96 97 98
	guix)
		CMD="guix package -I"
		;;
99 100 101 102 103
	android)
		CMD="pm list packages"
		docmd $CMD | sed -e "s|^package:||g"
		return
		;;
Danil Mikhailov's avatar
Danil Mikhailov committed
104
	*)
105
		fatal "Have no suitable query command for $PMTYPE"
Danil Mikhailov's avatar
Danil Mikhailov committed
106 107 108 109 110 111
		;;
esac

docmd $CMD

}