1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/bin/sh
#
# Copyright (C) 2012-2014, 2016, 2017, 2019-2021 Etersoft
# Copyright (C) 2012-2014, 2016, 2017, 2019-2021 Vitaly Lipatov <lav@etersoft.ru>
#
# 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
# (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
# 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/>.
#
load_helper epm-sh-altlinux
load_helper epm-query
load_helper epm-print
load_helper epm-sh-warmup
load_helper epm-sh-install
RPMISNOTINSTALLED=202
__check_rpm_e_result()
{
grep -q "is not installed" $1 && return $RPMISNOTINSTALLED
return $2
}
# Try remove with low level removing
epm_remove_low()
{
[ -z "$1" ] && return
warmup_lowbase
case $PMTYPE in
*-rpm)
cd /tmp || fatal
__epm_check_vendor $@
set_sudo
store_output sudocmd rpm -ev $noscripts $nodeps $@
# rpm returns number of packages if failed on removing
__check_rpm_e_result $RC_STDOUT $?
RES=$?
clean_store_output
cd - >/dev/null
return $RES ;;
*-dpkg|-dpkg)
# shellcheck disable=SC2046
sudocmd dpkg -P $(subst_option nodeps --force-all) $(print_name "$@")
return ;;
pkgsrc)
sudocmd pkg_delete -r $@
return ;;
pkgng)
sudocmd pkg delete -R $@
return ;;
emerge)
sudocmd emerge --unmerge $@
return ;;
pacman)
sudocmd pacman -R $@
return ;;
eopkg)
sudocmd eopkg $(subst_option nodeps --ignore-dependency) remove $@
return ;;
appget|winget)
sudocmd $PMTYPE uninstall $@
return ;;
slackpkg)
sudocmd /sbin/removepkg $@
return ;;
esac
return 1
}
epm_remove_names()
{
[ -z "$1" ] && return
warmup_bases
local APTOPTIONS="$(subst_option non_interactive -y)"
case $PMTYPE in
apt-dpkg)
sudocmd apt-get remove --purge $APTOPTIONS $@
return ;;
aptitude-dpkg)
sudocmd aptitude purge $@
return ;;
apt-rpm)
sudocmd apt-get remove $APTOPTIONS $@
return ;;
packagekit)
docmd pkcon remove $@
return ;;
deepsolver-rpm)
sudocmd ds-remove $@
return ;;
urpm-rpm)
sudocmd urpme $@
return ;;
pkgsrc) # without dependencies
sudocmd pkg_delete $@
return ;;
pkgng)
sudocmd pkg delete -R $@
return ;;
emerge)
#sudocmd emerge --unmerge $@
sudocmd emerge -aC $@
return ;;
pacman)
sudocmd pacman -Rc $@
return ;;
yum-rpm)
sudocmd yum remove $@
return ;;
dnf-rpm)
sudocmd dnf remove $@
return ;;
snappy)
sudocmd snappy uninstall $@
return ;;
zypper-rpm)
sudocmd zypper remove --clean-deps $@
return ;;
mpkg)
sudocmd mpkg remove $@
return ;;
eopkg)
sudocmd eopkg $(subst_option nodeps --ignore-dependency) remove $@
return ;;
conary)
sudocmd conary erase $@
return ;;
npackd)
sudocmd npackdcl remove --package=$1
return ;;
nix)
sudocmd nix-env --uninstall $@
return ;;
apk)
sudocmd apk del $@
return ;;
guix)
sudocmd guix package -r $@
return ;;
android)
sudocmd pm uninstall $@
return ;;
termux-pkg)
sudocmd pkg uninstall $@
return ;;
choco)
sudocmd choco uninstall $@
return ;;
slackpkg)
sudocmd /usr/sbin/slackpkg remove $@
return ;;
homebrew)
docmd brew remove $@
return ;;
aptcyg)
sudocmd apt-cyg remove $@
return ;;
xbps)
sudocmd xbps remove -R $@
return ;;
appget|winget)
sudocmd $PMTYPE uninstall $@
return ;;
opkg)
# shellcheck disable=SC2046
sudocmd opkg $(subst_option force -force-depends) remove $@
return ;;
*)
fatal "Have no suitable command for $PMTYPE"
;;
esac
}
# TODO
epm_remove_nonint()
{
warmup_bases
case $PMTYPE in
apt-dpkg)
sudocmd apt-get -y --force-yes remove --purge $@
return ;;
aptitude-dpkg)
sudocmd aptitude -y purge $@
return ;;
apt-rpm)
sudocmd apt-get -y --force-yes remove $@
return ;;
packagekit)
docmd pkcon remove --noninteractive $@
return ;;
urpm-rpm)
sudocmd urpme --auto $@
return ;;
pacman)
sudocmd pacman -Rc --noconfirm $@
return ;;
yum-rpm)
sudocmd yum -y remove $@
return ;;
dnf-rpm)
sudocmd dnf remove --assumeyes $@
return ;;
zypper-rpm)
sudocmd zypper --non-interactive remove --clean-deps $@
return ;;
slackpkg)
sudocmd /usr/sbin/slackpkg -batch=on -default_answer=yes remove $@
return ;;
pkgng)
sudocmd pkg delete -y -R $@
return ;;
opkg)
sudocmd opkg -force-defaults remove $@
return ;;
eopkg)
sudocmd eopkg $(subst_option nodeps --ignore-dependency) --yes-all remove $@
return ;;
appget|winget)
sudocmd $PMTYPE uninstall -s $@
return ;;
xbps)
sudocmd xbps remove -y $@
return ;;
esac
return 5
}
epm_print_remove_command()
{
case $PMTYPE in
*-rpm)
echo "rpm -ev $nodeps $*"
;;
*-dpkg)
echo "dpkg -P $*"
;;
packagekit-*)
echo "pkcon remove --noninteractive $*"
;;
pkgsrc)
echo "pkg_delete -r $*"
;;
pkgng)
echo "pkg delete -R $*"
;;
pacman)
echo "pacman -R $*"
;;
emerge)
echo "emerge --unmerge $*"
;;
slackpkg)
echo "/sbin/removepkg $*"
;;
opkg)
echo "opkg remove $*"
;;
eopkg)
echo "eopkg remove $*"
;;
aptcyg)
echo "apt-cyg remove $*"
;;
xbps)
echo "xbps remove -y $*"
;;
appget|winget)
echo "$PMTYPE uninstall -s $*"
;;
*)
fatal "Have no suitable appropriate remove command for $PMTYPE"
;;
esac
}
epm_remove()
{
if [ -n "$show_command_only" ] ; then
epm_print_remove_command $pkg_filenames
return
fi
# TODO: add support for --no-scripts to all cases
if [ "$BASEDISTRNAME" = "alt" ] ; then
load_helper epm-sh-altlinux
if tasknumber "$pkg_names" >/dev/null ; then
assure_exists apt-repo
pkg_names="$(get_task_packages $pkg_names)"
fi
fi
# TODO: fix pkg_names override
# get full package name(s) from the package file(s)
[ -n "$pkg_files" ] && pkg_names="$pkg_names $(epm query $pkg_files)"
pkg_files=''
if [ -z "$pkg_names" ] ; then
warning "no package(s) to remove."
return
fi
# remove according current arch (if x86_64) by default
pkg_names="$(echo $pkg_names | exp_with_arch_suffix)"
if [ -n "$dryrun" ] ; then
info "Packages for removing:"
echo "$pkg_names"
case $PMTYPE in
apt-rpm)
nodeps="--test"
APTOPTIONS="--simulate"
;;
apt-deb)
nodeps="--simulate"
APTOPTIONS="--simulate"
;;
*)
fatal "don't yet support --simulate for $PMTYPE"
return
;;
esac
fi
if [ -n "$skip_missed" ] ; then
pkg_names="$(get_only_installed_packages $pkg_names)"
fi
epm_remove_low $pkg_names && return
local STATUS=$?
if [ -n "$direct" ] || [ -n "$nodeps" ] || [ "$STATUS" = "$RPMISNOTINSTALLED" ]; then
[ -n "$force" ] || return $STATUS
fi
# TODO: FIX
# нужно удалить все пакеты, которые зависят от удаляемого
if [ -n "$noscripts" ] ; then
#warning "It is not recommended to remove a few packages with disabled scripts simultaneously."
fatal "We can't allow packages removing on hi level when --noscripts is used."
fi
# get package name for hi level package management command (with version if supported and if possible)
pkg_names=$(__epm_get_hilevel_name $pkg_names)
if [ -n "$non_interactive" ] ; then
epm_remove_nonint $pkg_names
local RET=$?
# if not separate command, use usual command
[ "$RET" = "5" ] || return $RET
fi
epm_remove_names $pkg_names
}