epm-checkpkg 2.23 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#
# Copyright (C) 2009, 2012  Etersoft
# Copyright (C) 2009, 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 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
#

check_rpm_integrity()
{
22
	docmd rpm --checksig $@
23 24 25 26
}

check_deb_integrity()
{
27
	# FIXME: debsums -ca package ?
28
	docmd dpkg --contents $@
29 30 31 32
}

check_bz2_integrity()
{
33
	docmd bunzip -t $1
34 35
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
36 37 38 39 40
check_tbz_integrity()
{
	check_bz2_integrity $@
}

41 42
check_gz_integrity()
{
43
	docmd gunzip -t $1
44 45
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
46 47 48 49 50
check_tgz_integrity()
{
	check_gz_integrity $@
}

51 52
check_zip_integrity()
{
53 54 55 56 57 58
	docmd unzip -t $@
}

check_rar_integrity()
{
	docmd unrar t $@
59 60 61 62
}

check_xz_integrity()
{
63 64 65 66 67 68
	docmd xz -t $1
}

check_7z_integrity()
{
	docmd 7z t $1
69 70
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
71 72 73 74 75 76 77 78 79 80 81 82
check_exe_integrity()
{
	# skip
	true
}

check_ebuild_integrity()
{
	# skip
	true
}

83 84 85 86 87
check_pkg_integrity()
{
	local EXT=`echo "$1" | sed -e "s|.*\.\([a-z0-9]*\)\$|\1|g"`
	local PKG="$1"
	local RET
88 89 90 91 92 93 94 95 96 97 98 99
	# TODO: Попробовать здесь оставить возможность перегрузки функций
	case $EXT in
	rpm)
		docmd rpm --checksig $@
		;;
	deb)
		# FIXME: debsums -ca package ?
		docmd dpkg --contents $@
		;;
	bz2)
		docmd bunzip -t $1
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
100 101 102
	*)
		check_${EXT}_integrity "$PKG" || fatal "Unknown package extension '$EXT' in $PKG package"
		;;
103
	esac
104 105
}

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
__epm_check_installed_pkg()
{
case $PMTYPE in
	*-rpm)
		docmd rpm -V $@
		;;
	*-dpkg)
		docmd debsums $@
		;;
	*)
		fatal "Do not known command for $PMTYPE"
		;;
esac

}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
122 123

epm_checkpkg()
124
{
125 126 127 128 129
	if [ -n "$pkg_names" ] ; then
		__epm_check_installed_pkg $pkg_names
		return
	fi

130
	[ -n "$pkg_files" ] || fatal "Run without names"
131 132 133
	local pkg
	for pkg in $pkg_files ; do
		check_pkg_integrity $pkg || fatal "Broken package $pkg"
134 135
	done
}