epm-packages 4.52 KB
Newer Older
Danil Mikhailov's avatar
Danil Mikhailov committed
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2016, 2017  Etersoft
# Copyright (C) 2012, 2016, 2017  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
load_helper epm-sh-warmup

22 23 24 25 26
__epm_packages_sort()
{
# FIXME: sort depends on --sort value
case $PMTYPE in
	apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
27
		# FIXME: space with quotes problems, use point instead
28
		warmup_rpmbase
29
		docmd rpm -qa --queryformat "%{size}@%{name}-%{version}-%{release}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1
30 31
		;;
	apt-dpkg)
32
		warmup_dpkgbase
33
		docmd dpkg-query -W --showformat="\${Installed-Size}@\${Package}-\${Version}:\${Architecture}\n" $pkg_filenames | sed -e "s|@| |g" | sort -n -k1
34 35
		;;
	*)
36
		fatal "Sorted package list function is not implemented for $PMTYPE"
37 38 39 40
		;;
esac
}

41 42 43 44 45 46 47
__aptcyg_print_full()
{
	#showcmd apt-cyg show
	local VERSION=$(apt-cyg show "$1" | grep -m1 "^version: " | sed -e "s|^version: ||g")
	echo "$1-$VERSION"
}

48 49 50 51 52
__fo_pfn()
{
	grep -v "^$" | grep -- "$pkg_filenames"
}

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

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

Vitaly Lipatov's avatar
Vitaly Lipatov committed
185
docmd $CMD | __fo_pfn
186
# FIXME: we print empty lines, but will lost error status
Danil Mikhailov's avatar
Danil Mikhailov committed
187 188

}