3
# Copyright (C) 2012, 2017, 2018, 2021 Etersoft
4
# Copyright (C) 2012, 2017, 2018, 2021 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/>.
20
load_helper epm-check_updated_repo
27
excluded="$(estrlist exclude "$pkgs" "$fullpkgs")"
28
if [ -n "$excluded" ] ; then
29
echo "Skipped manually installed:"
30
estrlist union $excluded
34
__epm_autoremove_altrpm_pp()
38
info "Removing unused python/perl modules..."
44
showcmd "apt-cache list-nodeps | grep -E -- \"$libexclude\""
45
fullpkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" )
46
pkgs=$(skip_manually_installed $fullpkgs)
48
if [ -n "$dryrun" ] ; then
49
info "Packages for autoremoving:"
51
__epm_print_excluded "$pkgs" "$fullpkgs"
55
if [ -n "$pkgs" ] ; then
56
info "The command we will run:"
57
showcmd rpm -v -e $pkgs
58
__epm_print_excluded "$pkgs" "$fullpkgs"
60
confirm_info "We will remove unused (without dependencies) packages above."
62
sudocmd rpm -v -e $pkgs && flag=1
66
if [ -n "$flag" ] ; then
68
info "call again for next cycle until all modules will be removed"
69
__epm_autoremove_altrpm_pp "$libexclude"
75
__epm_autoremove_altrpm_package_group()
78
confirm_info "We will remove unused (without dependencies) packages above."
79
docmd epm remove $(epmqp --short "$*")
83
__epm_autoremove_altrpm_lib()
93
info "Removing all non -devel/-debuginfo libs packages not need by anything..."
94
local develrule='-(devel|devel-static)$'
95
libgrep='^(lib|bzlib|zlib)'
98
info "Removing all non -devel/-debuginfo i586-libs packages not need by anything..."
99
local develrule='-(devel|devel-static)$'
100
libgrep='^(i586-lib|i586-bzlib|i586-zlib)'
103
info "Removing all non -debuginfo libs packages (-devel too) not need by anything..."
104
local develrule='-(NONONO)$'
105
libgrep='^(lib|bzlib|zlib)'
108
fatal "Internal error: unsupported opt $opt"
111
# https://www.altlinux.org/APT_в_ALT_Linux/Советы_по_использованию#apt-cache_list-nodeps
112
showcmd "apt-cache list-nodeps | grep -E -- \"$libgrep\""
113
fullpkgs=$(apt-cache list-nodeps | grep -E -- "$libgrep" \
114
| sed -e "s/[-\.]32bit$//g" \
115
| grep -E -v -- "$develrule" \
116
| grep -E -v -- "-(debuginfo)$" \
117
| grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \
118
| grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|libsasl2-plugin|eepm|distro_info)" )
119
pkgs=$(skip_manually_installed $fullpkgs)
121
if [ -n "$dryrun" ] ; then
122
info "Packages for autoremoving:"
124
__epm_print_excluded "$pkgs" "$fullpkgs"
128
if [ -n "$pkgs" ] ; then
129
info "The command we will run:"
130
showcmd rpm -v -e $pkgs
131
__epm_print_excluded "$pkgs" "$fullpkgs"
132
confirm_info "We will remove unused (without dependencies) packages above."
134
sudocmd rpm -v -e $pkgs && flag=1
137
if [ -n "$flag" ] ; then
139
info "call again for next cycle until all libs will be removed"
140
__epm_autoremove_altrpm_lib $opt
147
epm_autoremove_default_groups="python2 python3 perl gem ruby libs"
149
__epm_autoremove_altrpm()
152
load_helper epm-packages
153
assure_exists /usr/share/apt/scripts/list-nodeps.lua apt-scripts
155
if [ -z "$pkg_names" ] ; then
156
pkg_names="$epm_autoremove_default_groups"
157
elif [ "$pkg_names" = "python" ] ; then
158
pkg_names="python2 python3"
161
for i in $pkg_names ; do
164
__epm_autoremove_altrpm_lib libs
167
__epm_autoremove_altrpm_lib i586-libs
170
__epm_autoremove_altrpm_package_group '-debuginfo-'
173
__epm_autoremove_altrpm_package_group '^(rpm-build-|gcc-|glibc-devel-)'
176
__epm_autoremove_altrpm_pp '^(python-module-|python-modules-)'
179
__epm_autoremove_altrpm_pp '^(python3-module-|python3-modules-)'
182
__epm_autoremove_altrpm_pp '^(php7-|php5-|php8-)'
185
__epm_autoremove_altrpm_pp '^(gem-)'
188
__epm_autoremove_altrpm_pp '^(ruby-)'
191
__epm_autoremove_altrpm_pp '^(perl-)'
194
__epm_autoremove_altrpm_lib devel
197
fatal "autoremove: unsupported '$i'. Use epm autoremove --help to list supported ones"
205
epm_autoremove_print_help()
207
echo "epm autoremove removes unneeded packages from the system"
208
echo "run 'epm autoremove' to use apt-get autoremove"
209
echo "or run 'epm autoremove --direct [group1] [group2] ...' to use epm implementation"
210
echo "Default groups: $epm_autoremove_default_groups"
212
Supported package groups:
213
libs - unused libraries
214
libs-devel - unused -devel packages
215
i586-libs - unused i586-libs libraries
216
debuginfo - all debuginfo packages
217
devel - all packages used for build/developing
218
python - all python modules
219
python2 - python2 modules
220
python3 - python3 modules
226
--auto|--assumeyes|--non-interactive for non interactive mode
231
# TODO: keep our eepm package
235
case $BASEDISTRNAME in
237
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "help" ] ; then
238
epm_autoremove_print_help
242
if [ -z "$direct" ] ; then
243
[ -n "$1" ] && fatal "Run autoremove without args or with --direct. Check epm autoremove --help to available commands."
244
if epm installed sudo ; then
245
epm mark manual sudo || fatal
247
sudocmd apt-get $(subst_option non_interactive -y) autoremove $dryrun
249
if [ "$RET" != 0 ] ; then
251
info "Also you can run 'epm autoremove --direct' to use epm implementation of autoremove (see --help)"
255
__epm_autoremove_altrpm "$@"
258
#[ -n "$dryrun" ] && return
260
# remove old kernels only by a default way
261
[ -n "$1" ] && return
263
docmd epm remove-old-kernels $dryrun
265
if [ -z "$direct" ] ; then
267
info "Also you can run 'epm autoremove --direct' to use epm implementation of autoremove (see --help)"
276
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"
279
apt-dpkg|aptitude-dpkg)
280
sudocmd apt-get autoremove $(subst_option non_interactive -y) $dryrun
283
if [ -n "$dryrun" ] ; then
284
fatal "--dry-run is not supported yet"
289
docmd pkcon repair --autoremove
294
# shellcheck disable=SC2046
295
docmd package-cleanup --leaves $(subst_option non_interactive --assumeyes)
296
# FIXME: package-cleanup have to use stderr for errors
297
local PKGLIST=$(package-cleanup -q --leaves | grep -v "^eepm-")
298
[ -n "$PKGLIST" ] || break
299
docmd epm remove $PKGLIST
303
if [ -n "$dryrun" ] ; then
304
fatal "--dry-run is not supported yet"
306
sudocmd dnf autoremove
310
# sudocmd urpme --auto-orphans
313
if [ -n "$dryrun" ] ; then
314
fatal "--dry-run is not supported yet"
316
sudocmd emerge --depclean
317
assure_exists revdep-rebuild
318
sudocmd revdep-rebuild
322
# sudocmd pacman -Qdtq | sudocmd pacman -Rs -
325
# clean-system removes non official packages
326
#sudocmd slackpkg clean-system
332
sudocmd pkg autoremove
335
# https://www.linux.org.ru/forum/desktop/11931830
336
assure_exists zypper zypper 1.9.3
337
sudocmd zypper packages --unneeded
338
# FIXME: x86_64/i586 are duplicated
339
local PKGLIST=$(zypper packages --unneeded | tail -n +5 | cut -d \| -f 3 | sort -u)
340
showcmd epm remove --clean-deps $PKGLIST
343
if [ -n "$dryrun" ] ; then
344
fatal "--dry-run is not supported yet"
346
sudocmd xbps-remove -O
349
if [ -n "$dryrun" ] ; then
350
sudocmd opkg --noaction --autoremove
352
sudocmd opkg --autoremove
356
fatal "Have no suitable command for $PMTYPE"