epm-search 2.01 KB
Newer Older
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
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
__epm_search_output()
21
{
22 23
local CMD
local string="$1"
24 25
case $PMTYPE in
	apt-rpm|apt-dpkg)
26 27
		CMD="apt-cache search"
		;;
28
	urpm-rpm)
29
		CMD="urpmq -y"
30
		;;
31
	pkgsrc)
32 33 34 35
		CMD="pkg_info -x"
		;;
	emerge)
		CMD="emerge --search"
36
		;;
37 38 39
	pacman)
		CMD="pacman -Ss"
		;;
40 41 42
	aura)
		CMD="aura -As"
		;;
43 44 45
	yum-rpm)
		CMD="yum search"
		;;
46 47 48
	dnf-rpm)
		CMD="dnf search"
		;;
49 50 51 52 53 54
	zypper-rpm)
		CMD="zypper search"
		;;
	mpkg)
		CMD="mpkg search"
		;;
55
	npackd)
56
		docmd npackdcl search --query="$string" --status=all
Vitaly Lipatov's avatar
Vitaly Lipatov committed
57
		return
58
		;;
59 60 61
	chocolatey)
		CMD="chocolatey list"
		;;
62
	slackpkg)
63 64
		# FIXME
		echo "FIXME: need case insensitive search"
65
		docmd_foreach "/usr/sbin/slackpkg search" $string
66
		return
67
		;;
68 69 70
	homebrew)
		CMD="brew search"
		;;
71
	*)
72
		fatal "Have no suitable search command for $PMTYPE"
73 74 75
		;;
esac

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
docmd $CMD $string
}

# produce grep sequence
__epm_search_make_grep()
{
	local i
	local string="$1"
	shift
	echo -n "\"$string\""
	for i in $@ ; do
		local NOR=${i/^/}
		if [ "$NOR" = "$i" ] ; then
			echo -n " | grep -- \"$i\""
		else
			echo -n " | grep -v -- \"$NOR\""
		fi
	done
}

# copied from korinf/tools/run-script/scripts/search
97

98 99 100 101 102
epm_search()
{
	[ -n "$pkg_filenames" ] || fatal "Run search without any string"
	# FIXME: do it better
	eval "__epm_search_output $(eval __epm_search_make_grep $quoted_args)"
103
}