NBash

Форк
0
264 строки · 7.2 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2023  Etersoft
4
# Copyright (C) 2023  Vitaly Lipatov <lav@etersoft.ru>
5
#
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.
10
#
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.
15
#
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/>.
18
#
19

20
load_helper epm-query
21

22

23
__convert_pkgallowscripts_to_regexp()
24
{
25
    local tmpalf
26
    tmpalf="$(mktemp)" || fatal
27
    # copied from eget's filter_glob
28
    # check man 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
31
    echo "$tmpalf"
32
}
33

34
__epm_package_name_ok_scripts()
35
{
36
    local name="$1"
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
43
    local res=$?
44
    rm $tmpalf
45
    return $res
46
}
47

48
__epm_package_ok_scripts()
49
{
50
    local pkg="$1"
51
    local name
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"
56
}
57

58
__epm_vendor_ok_scripts()
59
{
60
    local vendor="$1"
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
67
    local res=$?
68
    rm $tmpalf
69
    return $res
70
}
71

72

73
epm_status_installable()
74
{
75
    local pkg="$1"
76
    #LANG=C epm policy "$pkg" | grep Candidate >/dev/null 2>/dev/null
77
    if [ -n "$verbose" ] ; then
78
        docmd epm install --simulate "$pkg"
79
    else
80
        epm install --simulate "$pkg" 2>/dev/null >/dev/null
81
    fi
82
}
83

84
# allowed to use scripts 
85
epm_status_certified()
86
{
87
    local pkg="$1"
88
    load_helper epm-install
89
    __epm_package_ok_scripts "$pkg" && return
90

91
    local vendor
92
    vendor="$(epm print field Vendor for "$pkg" 2>/dev/null)"
93
    [ -n "$vendor" ] || return
94
    __epm_vendor_ok_scripts "$vendor" && return
95
}
96

97

98
# check if the package is really package (check accessibility)
99
epm_status_validate()
100
{
101
    local pkg="$1"
102
    local rpmversion="$(epm print field Version for "$pkg" 2>/dev/null)"
103
    [ -n "$rpmversion" ]
104
}
105

106
epm_status_original()
107
{
108
    local pkg="$1"
109

110
    #is_installed $pkg || fatal "FIXME: implemented for installed packages as for now"
111

112
    case $DISTRNAME in
113
        ALTLinux)
114
            epm_status_validate $pkg || return 1
115
            epm_status_repacked $pkg && return 1
116

117
            # not for all packages
118
            #[ "$(epm print field Vendor for package $pkg)" = "ALT Linux Team" ] || return
119

120
            local distribution
121
            distribution="$(epm print field Distribution for "$pkg" 2>/dev/null )"
122
            echo "$distribution" | grep -q "^ALT" || return 1
123

124
            # mc in Sisyphus has not a signature
125
            #local sig
126
            #sig="$(epm print field sigpgp for "$pkg" 2>/dev/null )"
127
            #[ "$sig" = "(none)" ] && return 1
128

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
132
            return 0
133
            ;;
134
        *)
135
            fatal "Unsupported $DISTRNAME"
136
            ;;
137
    esac
138
    return 1
139
}
140

141
epm_status_repacked()
142
{
143
    local pkg="$1"
144

145
    #is_installed $pkg || fatal "FIXME: implemented for installed packages as for now"
146

147
    case $BASEDISTRNAME in
148
        alt)
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
153
            ;;
154
        *)
155
            fatal "Unsupported $BASEDISTRNAME"
156
            ;;
157
    esac
158
    return 1
159
}
160

161

162
epm_status_thirdparty()
163
{
164
    local pkg="$1"
165

166
    #is_installed $pkg || fatal "FIXME: implemented for installed packages as for now"
167

168
    case $BASEDISTRNAME in
169
        alt)
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
175

176
            local distribution
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
180
            return 0
181
            ;;
182
        *)
183
            fatal "Unsupported $BASEDISTRNAME"
184
            ;;
185
    esac
186
    return 1
187
}
188

189

190
epm_status_help()
191
{
192
    cat <<EOF
193

194
epm status - check status of the package and return result via exit code
195
Usage: epm status [options] <package>
196

197
Options:
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)
205

206
EOF
207
}
208

209
epm_status()
210
{
211
    local option="$1"
212

213
    if [ -z "$1" ] ; then
214
        epm_status_help >&2
215
        exit 1
216
    fi
217

218
    shift
219

220
    # TODO: allow both option
221
    case "$option" in
222
        -h|--help)
223
            epm_status_help
224
            return
225
            ;;
226
        --installed)
227
            is_installed "$@"
228
            return
229
            ;;
230
        --original)
231
            epm_status_original "$@"
232
            return
233
            ;;
234
        --certified|--allowed-scripts)
235
            epm_status_certified "$@"
236
            return
237
            ;;
238
         --third-party|--thirdparty|--thirdpart)
239
            epm_status_thirdparty "$@"
240
            return
241
            ;;
242
        --repacked)
243
            epm_status_repacked "$@"
244
            return
245
            ;;
246
        --validate)
247
            epm_status_validate "$@"
248
            return
249
            ;;
250
        --installable)
251
            epm_status_installable "$@"
252
            return
253
            ;;
254
        -*)
255
            fatal "Unknown option $option, use epm status --help to get info"
256
            ;;
257
        *)
258
            fatal "No option before $option, use epm status --help to get info"
259
            ;;
260
    esac
261

262
    epm_status_help >&2
263
    fatal "Run with appropriate option"
264
}
265

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.