3
# Copyright (C) 2023 Etersoft
4
# Copyright (C) 2023 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
__convert_pkgallowscripts_to_regexp()
26
tmpalf="$(mktemp)" || fatal
27
# copied from eget's filter_glob
29
# remove commentы and translate glob to regexp
30
grep -v "^[[:space:]]*#" "$1" | grep -v "^[[:space:]]*$" | sed -e "s|\*|.*|g" -e "s|?|.|g" -e "s|^|^|" -e "s|$|\$|" >$tmpalf
34
__epm_package_name_ok_scripts()
37
local alf="$CONFIGDIR/pkgallowscripts.list"
38
[ -s "$alf" ] || return 1
39
[ -n "$name" ] || return 1
40
local tmpalf=$(__convert_pkgallowscripts_to_regexp "$alf")
41
remove_on_exit $tmpalf
42
echo "$name" | grep -q -f $tmpalf
48
__epm_package_ok_scripts()
52
# TODO: improve epm print name and use it here
53
name="$(epm print field Name for "$pkg" 2>/dev/null)"
54
[ -n "$name" ] || return 1
55
__epm_package_name_ok_scripts "$name"
58
__epm_vendor_ok_scripts()
61
local alf="$CONFIGDIR/vendorallowscripts.list"
62
[ -s "$alf" ] || return 1
63
[ -n "$vendor" ] || return 1
64
local tmpalf=$(__convert_pkgallowscripts_to_regexp "$alf")
65
remove_on_exit $tmpalf
66
echo "$vendor" | grep -q -f $tmpalf
73
epm_status_installable()
76
#LANG=C epm policy "$pkg" | grep Candidate >/dev/null 2>/dev/null
77
if [ -n "$verbose" ] ; then
78
docmd epm install --simulate "$pkg"
80
epm install --simulate "$pkg" 2>/dev/null >/dev/null
84
# allowed to use scripts
88
load_helper epm-install
89
__epm_package_ok_scripts "$pkg" && return
92
vendor="$(epm print field Vendor for "$pkg" 2>/dev/null)"
93
[ -n "$vendor" ] || return
94
__epm_vendor_ok_scripts "$vendor" && return
98
# check if the package is really package (check accessibility)
102
local rpmversion="$(epm print field Version for "$pkg" 2>/dev/null)"
110
#is_installed $pkg || fatal "FIXME: implemented for installed packages as for now"
114
epm_status_validate $pkg || return 1
115
epm_status_repacked $pkg && return 1
117
# not for all packages
118
#[ "$(epm print field Vendor for package $pkg)" = "ALT Linux Team" ] || return
121
distribution="$(epm print field Distribution for "$pkg" 2>/dev/null )"
122
echo "$distribution" | grep -q "^ALT" || return 1
124
# mc in Sisyphus has not a signature
126
#sig="$(epm print field sigpgp for "$pkg" 2>/dev/null )"
127
#[ "$sig" = "(none)" ] && return 1
129
# FIXME: how to check if the package is from ALT repo (verified)?
130
local release="$(epm print release from package "$pkg" 2>/dev/null )"
131
echo "$release" | grep -q "^alt" || return 1
135
fatal "Unsupported $DISTRNAME"
145
#is_installed $pkg || fatal "FIXME: implemented for installed packages as for now"
147
case $BASEDISTRNAME in
149
epm_status_validate $pkg || return
150
local packager="$(epm print field Packager for "$1" 2>/dev/null)"
151
[ "$packager" = "EPM <support@etersoft.ru>" ] && return 0
152
[ "$packager" = "EPM <support@eepm.ru>" ] && return 0
155
fatal "Unsupported $BASEDISTRNAME"
162
epm_status_thirdparty()
166
#is_installed $pkg || fatal "FIXME: implemented for installed packages as for now"
168
case $BASEDISTRNAME in
170
## FIXME: some repo packages have wrong Packager
171
#local packager="$(epm print field Packager for "$1" 2>/dev/null)"
172
#echo "$packager" && grep -q "altlinux" && return 0
173
#echo "$packager" && grep -q "basealt" && return 0
174
epm_status_validate $pkg || return 1
177
distribution="$(epm print field Distribution for "$pkg" 2>/dev/null )"
178
echo "$distribution" | grep -q "^ALT" && return 1
179
echo "$distribution" | grep -q "^EEPM" && return 1
183
fatal "Unsupported $BASEDISTRNAME"
194
epm status - check status of the package and return result via exit code
195
Usage: epm status [options] <package>
198
--installed check if <package> is installed
199
--installable check if <package> can be installed from the repo
200
--original check if <package> is from distro repo
201
--certified check if <package> is certified that it can be installed without repacking
202
--thirdparty check if <package> from a third-party source (didn't packed for this distro)
203
--repacked check if <package> was repacked with epm repack
204
--validate check if <package> is accessible (we can get a fields from it)
213
if [ -z "$1" ] ; then
220
# TODO: allow both option
231
epm_status_original "$@"
234
--certified|--allowed-scripts)
235
epm_status_certified "$@"
238
--third-party|--thirdparty|--thirdpart)
239
epm_status_thirdparty "$@"
243
epm_status_repacked "$@"
247
epm_status_validate "$@"
251
epm_status_installable "$@"
255
fatal "Unknown option $option, use epm status --help to get info"
258
fatal "No option before $option, use epm status --help to get info"
263
fatal "Run with appropriate option"