NBash

Форк
0
374 строки · 7.8 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2020, 2022, 2023  Etersoft
4
# Copyright (C) 2020, 2022, 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
# TODO: move to a common place and use
21
__is_wildcard()
22
{
23
    echo "$1" | grep -q "[*?]"
24
}
25

26
__alt_mark_hold_package()
27
{
28
        local pkg="$1"
29
        showcmd "echo \"RPM::Hold {\"^$pkg\";};\" > /etc/apt/apt.conf.d/hold-$pkg.conf"
30
        echo "RPM::Hold {\"^$pkg\";};" | sudorun tee "/etc/apt/apt.conf.d/hold-$pkg.conf" >/dev/null
31
}
32

33
__alt_test_glob()
34
{
35
    echo "$*" | grep -q "\.[*?]" && warning "Only glob symbols * and ? are supported. Don't use regexp here!"
36
}
37

38
__alt_mark_hold()
39
{
40
    # TODO: do more long checking via apt
41
    local pkg
42
    local i
43
    __alt_test_glob "$*"
44
    for i in "$@" ; do
45
        if __is_wildcard "$i" ; then
46
            local pkglist
47
            pkglist="$(epm qp --short "^$i")" || continue
48
            for pkg in $pkglist ; do
49
                __alt_mark_hold_package $pkg
50
            done
51
            return
52
        else
53
            pkg="$(epm query --short "$i")" || continue
54
        fi
55
        __alt_mark_hold_package $pkg
56
    done
57
}
58

59
__alt_mark_unhold()
60
{
61
    # TODO: do more long checking via apt
62
    local pkg
63
    local i
64
    __alt_test_glob "$*"
65
    for i in "$@" ; do
66
        pkg="$(epm query --short "$i")" || pkg="$i"
67
        sudocmd rm -fv /etc/apt/apt.conf.d/hold-$pkg.conf
68
    done
69
}
70

71
__alt_mark_showhold()
72
{
73
    grep -h "RPM::Hold" /etc/apt/apt.conf.d/hold-*.conf 2>/dev/null | sed -e 's|RPM::Hold {"^\(.*\)";};|\1|'
74
}
75

76
__dnf_assure_versionlock()
77
{
78
    epm assure /etc/dnf/plugins/versionlock.conf 'dnf-command(versionlock)'
79
}
80

81
__dnf_is_supported_versionlock()
82
{
83
    [ -f /etc/dnf/plugins/versionlock.conf ]
84
}
85

86
epm_mark_hold()
87
{
88

89
case $BASEDISTRNAME in
90
    "alt")
91
        __alt_mark_hold "$@"
92
        exit
93
        ;;
94
esac
95

96
case $PMTYPE in
97
    apt-dpkg)
98
        sudocmd apt-mark hold "$@"
99
        ;;
100
    dnf-rpm)
101
        __dnf_assure_versionlock
102
        sudocmd dnf versionlock add "$@"
103
        ;;
104
    zypper-rpm)
105
        sudocmd zypper al "$@"
106
        ;;
107
    emerge)
108
        info "Check /etc/portage/package.mask"
109
        ;;
110
    pacman)
111
        info "Manually: edit /etc/pacman.conf modifying IgnorePkg array"
112
        ;;
113
    *)
114
        fatal "Have no suitable command for $PMTYPE"
115
        ;;
116
esac
117

118
}
119

120

121
epm_mark_unhold()
122
{
123

124
case $BASEDISTRNAME in
125
    "alt")
126
        __alt_mark_unhold "$@"
127
        exit
128
        ;;
129
esac
130

131
case $PMTYPE in
132
    apt-dpkg)
133
        sudocmd apt-mark unhold "$@"
134
        ;;
135
    dnf-rpm)
136
        __dnf_assure_versionlock
137
        sudocmd dnf versionlock delete "$@"
138
        ;;
139
    zypper-rpm)
140
        sudocmd zypper rl "$@"
141
        ;;
142
    emerge)
143
        info "Check /etc/portage/package.mask (package.unmask)"
144
        ;;
145
    pacman)
146
        info "Manually: edit /etc/pacman.conf removing package from IgnorePkg line"
147
        ;;
148
    *)
149
        fatal "Have no suitable command for $PMTYPE"
150
        ;;
151
esac
152

153
}
154

155

156
epm_mark_showhold()
157
{
158

159
case $BASEDISTRNAME in
160
    "alt")
161
        __alt_mark_showhold "$@"
162
        exit
163
        ;;
164
esac
165

166
case $PMTYPE in
167
    apt-dpkg)
168
        docmd apt-mark showhold "$@"
169
        ;;
170
    dnf-rpm)
171
        # there is no hold entries without versionlock
172
        __dnf_is_supported_versionlock || return 0
173
        __dnf_assure_versionlock
174
        if [ -n "$short" ] ; then
175
            load_helper epm-query
176
            docmd dnf versionlock list "$@" | sed -e 's|\.\*$||' | grep -v " " | filter_pkgnames_to_short
177
        else
178
            docmd dnf versionlock list "$@"
179
        fi
180
        ;;
181
    zypper-rpm)
182
        docmd zypper ll "$@"
183
        ;;
184
    emerge)
185
        cat /etc/portage/package.mask
186
        ;;
187
    pacman)
188
        cat /etc/pacman.conf
189
        ;;
190
    *)
191
        fatal "Have no suitable command for $PMTYPE"
192
        ;;
193
esac
194

195
}
196

197
epm_mark_checkhold()
198
{
199
# workaround against epm assure questions
200
case $PMTYPE in
201
    dnf-rpm)
202
        # there is no hold entries without versionlock
203
        __dnf_is_supported_versionlock || return 1
204
        __dnf_assure_versionlock
205
        load_helper epm-query
206
        docmd dnf versionlock list | grep "^$1" | sed -e 's|\.\*$||' | grep -v " " | filter_pkgnames_to_short | grep -q "^$1$"
207
        return
208
        ;;
209
esac
210

211
epm_mark_showhold | grep -q "^$1$"
212

213
}
214

215

216
epm_mark_auto()
217
{
218

219
case $BASEDISTRNAME in
220
    "alt")
221
        sudocmd apt-mark auto "$@"
222
        exit
223
        ;;
224
esac
225

226
case $PMTYPE in
227
    apt-dpkg)
228
        sudocmd apt-mark auto "$@"
229
        ;;
230
    dnf-rpm)
231
        sudocmd dnf mark remove "$@"
232
        ;;
233
    pacman)
234
            sudocmd pacman -D --asdeps "$@"
235
        ;;
236
    emerge)
237
            sudocmd emerge --oneshot "$@"
238
        ;;
239
    *)
240
        fatal "Have no suitable command for $PMTYPE"
241
        ;;
242
esac
243

244
}
245

246

247
epm_mark_manual()
248
{
249

250
case $BASEDISTRNAME in
251
    "alt")
252
        sudocmd apt-mark manual "$@"
253
        exit
254
        ;;
255
esac
256

257
case $PMTYPE in
258
    apt-dpkg)
259
        sudocmd apt-mark manual "$@"
260
        ;;
261
    dnf-rpm)
262
        sudocmd dnf mark install "$@"
263
        ;;
264
    pacman)
265
            sudocmd pacman -D --asexplicit "$@"
266
        ;;
267
    emerge)
268
            sudocmd emerge --select "$@"
269
        ;;
270
    *)
271
        fatal "Have no suitable command for $PMTYPE"
272
        ;;
273
esac
274

275
}
276

277

278
epm_mark_showauto()
279
{
280

281
case $BASEDISTRNAME in
282
    "alt")
283
        sudocmd apt-mark showauto "$@"
284
        exit
285
        ;;
286
esac
287

288
case $PMTYPE in
289
    apt-dpkg)
290
        sudocmd apt-mark showauto "$@"
291
        ;;
292
    dnf-rpm)
293
        sudocmd dnf repoquery --unneeded
294
        ;;
295
    *)
296
        fatal "Have no suitable command for $PMTYPE"
297
        ;;
298
esac
299

300
}
301

302
epm_mark_showmanual()
303
{
304

305
case $BASEDISTRNAME in
306
    "alt")
307
        sudocmd apt-mark showmanual "$@"
308
        exit
309
        ;;
310
esac
311

312
case $PMTYPE in
313
    apt-dpkg)
314
        sudocmd apt-mark showmanual "$@"
315
        ;;
316
    dnf-rpm)
317
        sudocmd dnf repoquery --userinstalled
318
        ;;
319
    *)
320
        fatal "Have no suitable command for $PMTYPE"
321
        ;;
322
esac
323

324
}
325

326
epm_mark_help()
327
{
328
    echo "mark is the interface for marking packages"
329
            get_help HELPCMD $SHAREDIR/epm-mark
330
    cat <<EOF
331
Examples:
332
  epm mark hold mc
333
  epm manual mc
334
EOF
335
}
336

337
epm_mark()
338
{
339
    local CMD="$1"
340
    [ -n "$CMD" ] && shift
341
    case "$CMD" in
342
    ""|"-h"|"--help"|help)               # HELPCMD: help
343
        epm_mark_help
344
        ;;
345
    hold)                             # HELPCMD: mark the given package(s) as held back
346
        epm_mark_hold "$@"
347
        ;;
348
    unhold)                           # HELPCMD: unset the given package(s) as held back
349
        epm_mark_unhold "$@"
350
        ;;
351
    showhold)                         # HELPCMD: print the list of packages on hold
352
        epm_mark_showhold "$@"
353
        ;;
354
    checkhold)                         # HELPCMD: return true if the package is on hold
355
        epm_mark_checkhold "$@"
356
        ;;
357
    auto)                             # HELPCMD: mark the given package(s) as automatically installed
358
        epm_mark_auto "$@"
359
        ;;
360
    manual)                           # HELPCMD: mark the given package(s) as manually installed
361
        epm_mark_manual "$@"
362
        ;;
363
    showauto)                         # HELPCMD: print the list of automatically installed packages
364
        epm_mark_showauto "$@"
365
        ;;
366
    showmanual)                       # HELPCMD: print the list of manually installed packages
367
        epm_mark_showmanual "$@"
368
        ;;
369
    *)
370
        fatal "Unknown command $ epm repo '$CMD'"
371
        ;;
372
esac
373

374
}
375

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

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

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

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