epm-packages 4.26 KB
Newer Older
Danil Mikhailov's avatar
Danil Mikhailov committed
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2016  Etersoft
# Copyright (C) 2012, 2016  Vitaly Lipatov <lav@etersoft.ru>
Danil Mikhailov's avatar
Danil Mikhailov committed
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
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
__epm_packages_sort()
{
# FIXME: sort depends on --sort value
case $PMTYPE in
	apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
25 26
		# FIXME: space with quotes problems, use point instead
		docmd rpm -qa --queryformat "%{size}.%{name}-%{version}-%{release}\n" $pkg_filenames | sort -n
27 28
		;;
	apt-dpkg)
29
		docmd dpkg-query -W --showformat="\${Size}.\${Package}-\${Version}\n" $pkg_filenames | sort -n
30 31 32 33 34 35 36
		;;
	*)
		fatal "Sorted package list are not realized for $PMTYPE"
		;;
esac
}

37 38 39 40 41 42 43
__aptcyg_print_full()
{
	#showcmd apt-cyg show
	local VERSION=$(apt-cyg show "$1" | grep -m1 "^version: " | sed -e "s|^version: ||g")
	echo "$1-$VERSION"
}

44 45 46 47 48
__fo_pfn()
{
	grep -v "^$" | grep -- "$pkg_filenames"
}

49
# TODO: we have a problem with error status here
Danil Mikhailov's avatar
Danil Mikhailov committed
50
epm_packages()
Danil Mikhailov's avatar
Danil Mikhailov committed
51
{
52
	local CMD
53
	[ -n "$sort" ] && __epm_packages_sort && return
Danil Mikhailov's avatar
Danil Mikhailov committed
54

Vitaly Lipatov's avatar
Vitaly Lipatov committed
55 56
case $PMTYPE in
	apt-rpm)
57
		# FIXME: strong equal
58
		CMD="rpm -qa $pkg_filenames"
59
		[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
60 61
		docmd $CMD
		return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
62
	*-dpkg)
63
		# FIXME: strong equal
64
		#CMD="dpkg -l $pkg_filenames"
65 66
		CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}-\${Version}\n $pkg_filenames"
		[ -n "$short" ] && CMD="dpkg-query -W --showformat=\${db:Status-Abbrev}\${Package}\n $pkg_filenames"
67 68 69
		showcmd $CMD
		$CMD | grep "^i" | sed -e "s|.* ||g" | __fo_pfn
		return ;;
70 71 72
	snappy)
		CMD="snappy info"
		;;
73
	yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
74
		# FIXME: strong equal
75
		CMD="rpm -qa $pkg_filenames"
76
		[ -n "$short" ] && CMD="rpm -qa --queryformat %{name}\n $pkg_filenames"
77 78
		docmd $CMD
		return ;;
79
	emerge)
80 81 82
		CMD="qlist -I -C"
		# print with colors for console output
		isatty && CMD="qlist -I"
83
		;;
84
	pkgsrc)
85
		CMD="pkg_info"
86 87 88
		showcmd $CMD
		$CMD | sed -e "s| .*||g" | __fo_pfn
		return ;;
89
	pkgng)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
90 91 92 93 94
		if [ -n "$pkg_filenames" ] ; then
			CMD="pkg info -E $pkg_filenames"
		else
			CMD="pkg info"
		fi
95
		showcmd $CMD
96
		if [ -n "$short" ] ; then
97
		    $CMD | sed -e "s| .*||g" | sed -e "s|-[0-9].*||g" | __fo_pfn
98
		else
99
		    $CMD | sed -e "s| .*||g" | __fo_pfn
100
		fi
101
		return ;;
102
	pacman)
103
		CMD="pacman -Qs $pkg_filenames"
104
		showcmd $CMD
105
		if [ -n "$short" ] ; then
106
			$CMD | sed -e "s| .*||g" -e "s|.*/||g" | __fo_pfn
107 108
			return
		fi
109
		;;
110
	npackd)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
111 112
		CMD="npackdcl list --status=installed"
		# TODO: use search if pkg_filenames is not empty
113
		;;
114 115 116
	conary)
		CMD="conary query"
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
117 118 119
	chocolatey)
		CMD="chocolatey list"
		;;
120
	slackpkg)
121
		CMD="ls -1 /var/log/packages/"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
122
		if [ -n "$short" ] ; then
123 124 125
			# FIXME: does not work for libjpeg-v8a
			# TODO: remove last 3 elements (if arch is second from the last?)
			# FIXME this hack
126
			docmd ls -1 /var/log/packages/ | sed -e "s|-[0-9].*||g" | sed -e "s|libjpeg-v8a.*|libjpeg|g" | __fo_pfn
Vitaly Lipatov's avatar
Vitaly Lipatov committed
127 128
			return
		fi
129
		;;
130
	homebrew)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
131
		docmd brew list | xargs -n1 echo
132 133 134 135
		;;
	ipkg)
		CMD="ipkg list"
		;;
136 137 138
	apk)
		CMD="apk info"
		;;
139 140 141
	tce)
		CMD="ls -1 /usr/local/tce.installed"
		;;
142 143 144
	guix)
		CMD="guix package -I"
		;;
145 146
	xbps)
		CMD="xbps-query -l"
147 148 149 150 151 152 153
		showcmd $CMD
		if [ -n "$short" ] ; then
			$CMD | sed -e "s|^ii ||g" -e "s| .*||g" -e "s|\(.*\)-.*|\1|g" | __fo_pfn
		else
			$CMD | sed -e "s|^ii ||g" -e "s| .*||g" | __fo_pfn
		fi
		return 0
154
		;;
155 156
	android)
		CMD="pm list packages"
157 158
		showcmd $CMD
		$CMD | sed -e "s|^package:||g" | __fo_pfn
159 160
		return
		;;
161
	aptcyg)
162 163 164
		CMD="apt-cyg list $pkg_filenames"
		if [ -z "$short" ] ; then
			showcmd $CMD
Vitaly Lipatov's avatar
Vitaly Lipatov committed
165
			# TODO: fix this slow way
166 167 168 169 170
			for i in $($CMD) ; do
				__aptcyg_print_full $i
			done
			return
		fi
171
		;;
Danil Mikhailov's avatar
Danil Mikhailov committed
172
	*)
173
		fatal "Have no suitable query command for $PMTYPE"
Danil Mikhailov's avatar
Danil Mikhailov committed
174 175 176
		;;
esac

Vitaly Lipatov's avatar
Vitaly Lipatov committed
177
docmd $CMD | __fo_pfn
178
# FIXME: we print empty lines, but will lost error status
Danil Mikhailov's avatar
Danil Mikhailov committed
179 180

}