epm-checkpkg 1.7 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2009, 2012, 2013  Etersoft
# Copyright (C) 2009, 2012, 2013  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 15 16 17
# GNU Affero General Public License for more details.
#
# 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 22 23 24
#

check_pkg_integrity()
{
	local EXT=`echo "$1" | sed -e "s|.*\.\([a-z0-9]*\)\$|\1|g"`
	local PKG="$1"
	local RET
25

26 27
	case $EXT in
	rpm)
28
		docmd rpm --checksig $PKG
29 30 31
		;;
	deb)
		# FIXME: debsums -ca package ?
32 33 34 35
		docmd dpkg --contents $PKG >/dev/null && echo "Package $PKG is correct."
		;;
	exe)
		true
36
		;;
37 38
	ebuild)
		true
39
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
40
	*)
41 42 43
		docmd erc test "$PKG" && return
		which erc >/dev/null 2>/dev/null && fatal "Check failed"
		fatal "Install erc package."
Vitaly Lipatov's avatar
Vitaly Lipatov committed
44
		;;
45
	esac
46 47
}

48 49 50 51 52 53 54 55 56 57
__epm_check_installed_pkg()
{
case $PMTYPE in
	*-rpm)
		docmd rpm -V $@
		;;
	*-dpkg)
		docmd debsums $@
		;;
	*)
58
		fatal "Have no suitable command for $PMTYPE"
59 60 61 62 63
		;;
esac

}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
64 65

epm_checkpkg()
66
{
67
	if [ -n "$pkg_names" ] ; then
68
		echo "Suggest $pkg_names are names of installed packages"
69 70 71 72
		__epm_check_installed_pkg $pkg_names
		return
	fi

73
	[ -n "$pkg_files" ] || fatal "Run without names"
74 75 76
	local pkg
	for pkg in $pkg_files ; do
		check_pkg_integrity $pkg || fatal "Broken package $pkg"
77 78
	done
}