epm-autoremove 3.76 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2016  Etersoft
# Copyright (C) 2012, 2016  Vitaly Lipatov <lav@etersoft.ru>
5
#
6 7 8
# 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
9 10 11 12 13
# (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
14
# GNU Affero General Public License for more details.
15
#
16 17
# 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/>.
18 19
#

20 21 22 23
__epm_autoremove_altrpm()
{
	local pkg
	load_helper epm-packages
24
	assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts
25
	info
26
	info "Removing all non -devel/-debuginfo libs packages not need by anything..."
27 28
	#[ -n "$force" ] || info "You can run with --force for more deep removing"
	local force=force
29 30 31 32

	local flag=
	local libexclude='^lib'
	[ -n "$force" ] || libexclude=$libexclude'[^-]*$'
33

34 35
	# https://www.altlinux.org/APT_в_ALT_Linux/Советы_по_использованию#apt-cache_list-nodeps
	showcmd "apt-cache list-nodeps | grep -- \"$libexclude\""
Vitaly Lipatov's avatar
Vitaly Lipatov committed
36 37
	pkgs=$(apt-cache list-nodeps | grep -- "$libexclude" \
		| grep -E -v -- "-(devel|debuginfo)$" \
38
		| grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \
Vitaly Lipatov's avatar
Vitaly Lipatov committed
39
		| sed -e "s/\.32bit$//g" \
40
		| grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|eepm)" )
41 42
	[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1

43
	info "Removing unused python/perl modules..."
44 45 46 47 48 49 50
	libexclude='^(python-module-|python3-module-|python-modules-|python3-modules|perl-)'
	[ -n "$force" ] || libexclude=$libexclude'[^-]*$'
	showcmd "apt-cache list-nodeps | grep -E -- \"$libexclude\""
	pkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" )
	[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1

	if [ -n "$flag" ] ; then
51 52
		info ""
		info "call again for next cycle until all libs will be removed"
53 54
		__epm_autoremove_altrpm
	fi
55 56 57 58

	return 0
}

59
# TODO: keep our eepm package
60
epm_autoremove()
61
{
62 63 64

[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"

65 66
case $DISTRNAME in
	ALTLinux)
67
		__epm_autoremove_altrpm
68
		docmd epm remove-old-kernels
69 70 71 72
		
		if which nvidia-clean-driver 2>/dev/null ; then
			sudocmd nvidia-clean-driver
		fi
73

74 75 76
		return
		;;
	*)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
77
		;;
78 79 80
esac

case $PMTYPE in
Vitaly Lipatov's avatar
Vitaly Lipatov committed
81
	apt-dpkg|aptitude-dpkg)
82
		sudocmd apt-get autoremove
83
		;;
84 85 86
	aura)
		sudocmd aura -Oj
		;;
87 88 89
	yum-rpm)
		# cleanup orphanes?
		while true ; do
90
			docmd package-cleanup --leaves $(subst_option non_interactive --assumeyes)
91
			# FIXME: package-cleanup have to use stderr for errors
92
			local PKGLIST=$(package-cleanup --leaves | grep -v "Loaded plugins" | grep -v "Unable to" | grep -v "^eepm$")
93 94 95 96
			[ -n "$PKGLIST" ] || break
			sudocmd yum remove $PKGLIST
		done
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
97 98 99
	dnf-rpm)
		sudocmd dnf autoremove
		;;
100 101 102 103
	# see autoorhans
	#urpm-rpm)
	#	sudocmd urpme --auto-orphans
	#	;;
104 105
	emerge)
		sudocmd emerge --depclean
106
		assure_exists revdep-rebuild
Vitaly Lipatov's avatar
Vitaly Lipatov committed
107
		sudocmd revdep-rebuild
108
		;;
109 110 111 112
	# see autoorhans
	#pacman)
	#	sudocmd pacman -Qdtq | sudocmd pacman -Rs -
	#	;;
113 114 115 116
	slackpkg)
		# clean-system removes non official packages
		#sudocmd slackpkg clean-system
		;;
117 118 119
	guix)
		sudocmd guix gc
		;;
120 121 122
	pkgng)
		sudocmd pkg autoremove
		;;
123 124 125 126 127 128 129 130
	zypper-rpm)
		# https://www.linux.org.ru/forum/desktop/11931830
		assure_exists zypper zypper 1.9.3
		sudocmd zypper packages --unneeded
		# FIXME: x86_64/i586 are duplicated
		local PKGLIST=$(zypper packages --unneeded | tail -n +5 | cut -d \| -f 3 | sort -u)
		sudocmd zypper remove --clean-deps $PKGLIST
		;;
131 132 133
	xbps)
		CMD="xbps-remove -O"
		;;
134
	*)
135
		fatal "Have no suitable command for $PMTYPE"
136 137 138 139
		;;
esac

}