NBash

Форк
0
363 строки · 9.4 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2012-2014, 2016, 2017, 2019-2021  Etersoft
4
# Copyright (C) 2012-2014, 2016, 2017, 2019-2021  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-sh-altlinux
21
load_helper epm-query
22
load_helper epm-print
23
load_helper epm-sh-warmup
24
load_helper epm-sh-install
25

26
RPMISNOTINSTALLED=202
27

28
__check_rpm_e_result()
29
{
30
    grep -q "is not installed" $1 && return $RPMISNOTINSTALLED
31
    return $2
32
}
33

34

35
# Try remove with low level removing
36
epm_remove_low()
37
{
38
    [ -z "$1" ] && return
39

40
    warmup_lowbase
41

42
    case $PMTYPE in
43
        *-rpm)
44
            cd /tmp || fatal
45
            __epm_check_vendor $@
46
            store_output sudocmd rpm -ev $noscripts $nodeps $@
47
            # rpm returns number of packages if failed on removing
48
            __check_rpm_e_result $RC_STDOUT $?
49
            RES=$?
50
            clean_store_output
51
            cd - >/dev/null
52
            return $RES ;;
53
        *-dpkg|-dpkg)
54
            # shellcheck disable=SC2046
55
            sudocmd dpkg -P $(subst_option nodeps --force-all) $(print_name "$@")
56
            return ;;
57
        pkgsrc)
58
            sudocmd pkg_delete -r $@
59
            return ;;
60
        pkgng)
61
            sudocmd pkg delete -R $@
62
            return ;;
63
        emerge)
64
            sudocmd emerge --unmerge $@
65
            return ;;
66
        pacman)
67
            sudocmd pacman -R $@
68
            return ;;
69
        eopkg)
70
            sudocmd eopkg $(subst_option nodeps --ignore-dependency) remove $@
71
            return ;;
72
        appget|winget)
73
            sudocmd $PMTYPE uninstall $@
74
            return ;;
75
        slackpkg)
76
            sudocmd /sbin/removepkg $@
77
            return ;;
78
    esac
79
    return 1
80
}
81

82
epm_remove_names()
83
{
84
    [ -z "$1" ] && return
85

86
    warmup_bases
87

88
    local APTOPTIONS="$(subst_option non_interactive -y)"
89

90
    case $PMTYPE in
91
        apt-dpkg)
92
            sudocmd apt-get remove --purge $APTOPTIONS $@
93
            return ;;
94
        aptitude-dpkg)
95
            sudocmd aptitude purge $@
96
            return ;;
97
        apt-rpm)
98
            sudocmd apt-get remove $APTOPTIONS $@
99
            return ;;
100
        packagekit)
101
            docmd pkcon remove $@
102
            return ;;
103
        deepsolver-rpm)
104
            sudocmd ds-remove $@
105
            return ;;
106
        urpm-rpm)
107
            sudocmd urpme $@
108
            return ;;
109
        pkgsrc) # without dependencies
110
            sudocmd pkg_delete $@
111
            return ;;
112
        pkgng)
113
            sudocmd pkg delete -R $@
114
            return ;;
115
        emerge)
116
            #sudocmd emerge --unmerge $@
117
            sudocmd emerge -aC $@
118
            return ;;
119
        pacman)
120
            sudocmd pacman -Rc $@
121
            return ;;
122
        yum-rpm)
123
            sudocmd yum remove $@
124
            return ;;
125
        dnf-rpm)
126
            sudocmd dnf remove $@
127
            return ;;
128
        snappy)
129
            sudocmd snappy uninstall $@
130
            return ;;
131
        zypper-rpm)
132
            sudocmd zypper remove --clean-deps $@
133
            return ;;
134
        mpkg)
135
            sudocmd mpkg remove $@
136
            return ;;
137
        eopkg)
138
            sudocmd eopkg $(subst_option nodeps --ignore-dependency) remove $@
139
            return ;;
140
        conary)
141
            sudocmd conary erase $@
142
            return ;;
143
        npackd)
144
            sudocmd npackdcl remove --package=$1
145
            return ;;
146
        nix)
147
            sudocmd nix-env --uninstall $@
148
            return ;;
149
        apk)
150
            sudocmd apk del $@
151
            return ;;
152
        guix)
153
            sudocmd guix package -r $@
154
            return ;;
155
        android)
156
            sudocmd pm uninstall $@
157
            return ;;
158
        termux-pkg)
159
            sudocmd pkg uninstall $@
160
            return ;;
161
        choco)
162
            sudocmd choco uninstall $@
163
            return ;;
164
        slackpkg)
165
            sudocmd /usr/sbin/slackpkg remove $@
166
            return ;;
167
        homebrew)
168
            docmd brew remove $@
169
            return ;;
170
        aptcyg)
171
            sudocmd apt-cyg remove $@
172
            return ;;
173
        xbps)
174
            sudocmd xbps remove -R $@
175
            return ;;
176
        appget|winget)
177
            sudocmd $PMTYPE uninstall $@
178
            return ;;
179
        opkg)
180
            # shellcheck disable=SC2046
181
            sudocmd opkg $(subst_option force -force-depends) remove $@
182
            return ;;
183
        *)
184
            fatal "Have no suitable command for $PMTYPE"
185
            ;;
186
    esac
187
}
188

189
# TODO
190
epm_remove_nonint()
191
{
192
    warmup_bases
193

194
    case $PMTYPE in
195
        apt-dpkg)
196
            sudocmd apt-get -y --force-yes remove --purge $@
197
            return ;;
198
        aptitude-dpkg)
199
            sudocmd aptitude -y purge $@
200
            return ;;
201
        apt-rpm)
202
            sudocmd apt-get -y --force-yes remove $@
203
            return ;;
204
        packagekit)
205
            docmd pkcon remove --noninteractive $@
206
            return ;;
207
        urpm-rpm)
208
            sudocmd urpme --auto $@
209
            return ;;
210
        pacman)
211
            sudocmd pacman -Rc --noconfirm $@
212
            return ;;
213
        yum-rpm)
214
            sudocmd yum -y remove $@
215
            return ;;
216
        dnf-rpm)
217
            sudocmd dnf remove --assumeyes $@
218
            return ;;
219
        zypper-rpm)
220
            sudocmd zypper --non-interactive remove --clean-deps $@
221
            return ;;
222
        slackpkg)
223
            sudocmd /usr/sbin/slackpkg -batch=on -default_answer=yes remove $@
224
            return ;;
225
        pkgng)
226
            sudocmd pkg delete -y -R $@
227
            return ;;
228
        opkg)
229
            sudocmd opkg -force-defaults remove $@
230
            return ;;
231
        eopkg)
232
            sudocmd eopkg $(subst_option nodeps --ignore-dependency) --yes-all remove $@
233
            return ;;
234
        appget|winget)
235
            sudocmd $PMTYPE uninstall -s $@
236
            return ;;
237
        xbps)
238
            sudocmd xbps remove -y $@
239
            return ;;
240
    esac
241
    return 5
242
}
243

244
epm_print_remove_command()
245
{
246
    case $PMTYPE in
247
        *-rpm)
248
            echo "rpm -ev $nodeps $*"
249
            ;;
250
        *-dpkg)
251
            echo "dpkg -P $*"
252
            ;;
253
        packagekit-*)
254
            echo "pkcon remove --noninteractive $*"
255
            ;;
256
        pkgsrc)
257
            echo "pkg_delete -r $*"
258
            ;;
259
        pkgng)
260
            echo "pkg delete -R $*"
261
            ;;
262
        pacman)
263
            echo "pacman -R $*"
264
            ;;
265
        emerge)
266
            echo "emerge --unmerge $*"
267
            ;;
268
        slackpkg)
269
            echo "/sbin/removepkg $*"
270
            ;;
271
        opkg)
272
            echo "opkg remove $*"
273
            ;;
274
        eopkg)
275
            echo "eopkg remove $*"
276
            ;;
277
        aptcyg)
278
            echo "apt-cyg remove $*"
279
            ;;
280
        xbps)
281
            echo "xbps remove -y $*"
282
            ;;
283
        appget|winget)
284
            echo "$PMTYPE uninstall -s $*"
285
            ;;
286
        *)
287
            fatal "Have no suitable appropriate remove command for $PMTYPE"
288
            ;;
289
    esac
290
}
291

292

293
epm_remove()
294
{
295
    if [ -n "$show_command_only" ] ; then
296
        epm_print_remove_command $pkg_filenames
297
        return
298
    fi
299

300
    # TODO: add support for --no-scripts to all cases
301

302
    if [ "$BASEDISTRNAME" = "alt" ] ; then
303
        load_helper epm-sh-altlinux
304
        if tasknumber "$pkg_names" >/dev/null ; then
305
            assure_exists apt-repo
306
            pkg_names="$(get_task_packages $pkg_names)"
307
        fi
308
    fi
309

310
    # TODO: fix pkg_names override
311
    # get full package name(s) from the package file(s)
312
    [ -n "$pkg_files" ] && pkg_names="$pkg_names $(epm query $pkg_files)"
313
    pkg_files=''
314

315
    if [ -z "$pkg_names" ] ; then
316
        warning "no package(s) to remove."
317
        return
318
    fi
319
    # remove according current arch (if x86_64) by default
320
    pkg_names="$(echo $pkg_names | exp_with_arch_suffix)"
321

322
    if [ -n "$dryrun" ] ; then
323
        info "Packages for removing:"
324
        echo "$pkg_names"
325
        case $PMTYPE in
326
            apt-rpm)
327
                nodeps="--test"
328
                APTOPTIONS="--simulate"
329
                ;;
330
            apt-deb)
331
                nodeps="--simulate"
332
                APTOPTIONS="--simulate"
333
                ;;
334
            *)
335
                fatal "don't yet support --simulate for $PMTYPE"
336
                return
337
                ;;
338
        esac
339
    fi
340

341
    if [ -n "$skip_missed" ] ; then
342
        pkg_names="$(get_only_installed_packages $pkg_names)"
343
    fi
344

345
    epm_remove_low $pkg_names && return
346
    local STATUS=$?
347

348
    if [ -n "$direct" ] || [ -n "$nodeps" ] || [ "$STATUS" = "$RPMISNOTINSTALLED" ]; then
349
        [ -n "$force" ] || return $STATUS
350
    fi
351

352
    # get package name for hi level package management command (with version if supported and if possible)
353
    pkg_names=$(__epm_get_hilevel_name $pkg_names)
354

355
    if [ -n "$non_interactive" ] ; then
356
        epm_remove_nonint $pkg_names
357
        local RET=$?
358
        # if not separate command, use usual command
359
        [ "$RET" = "5" ] || return $RET
360
    fi
361

362
    epm_remove_names $pkg_names
363
}
364

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

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

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

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