epm-autoremove 4.23 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
__epm_autoremove_altrpm_pp()
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
	local pkgs

	info "Removing unused python/perl modules..."
	#[ -n "$force" ] || info "You can run with --force for more deep removing"
	local force=force

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

	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
		info ""
		info "call again for next cycle until all modules will be removed"
		__epm_autoremove_altrpm_pp
	fi

	return 0
}

__epm_autoremove_altrpm_lib()
{
	local pkgs

50
	info
51
	info "Removing all non -devel/-debuginfo libs packages not need by anything..."
52 53
	#[ -n "$force" ] || info "You can run with --force for more deep removing"
	local force=force
54 55

	local flag=
56
	local libexclude='^(lib|i586-lib)'
57
	[ -n "$force" ] || libexclude=$libexclude'[^-]*$'
58

59 60
	# https://www.altlinux.org/APT_в_ALT_Linux/Советы_по_использованию#apt-cache_list-nodeps
	showcmd "apt-cache list-nodeps | grep -- \"$libexclude\""
61 62
	pkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" \
		| sed -e "s/\.32bit$//g" \
63
		| grep -E -v -- "-(devel|devel-static|debuginfo)$" \
64
		| grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \
65
		| grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|libsasl2-plugin|eepm)" )
66 67 68
	[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1

	if [ -n "$flag" ] ; then
69 70
		info ""
		info "call again for next cycle until all libs will be removed"
71
		__epm_autoremove_altrpm_lib
72
	fi
73 74 75 76

	return 0
}

77 78 79 80 81 82 83 84 85 86 87 88 89

__epm_autoremove_altrpm()
{
	local pkg
	load_helper epm-packages
	assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts

	__epm_autoremove_altrpm_pp
	__epm_autoremove_altrpm_lib

	return 0
}

90
# TODO: keep our eepm package
91
epm_autoremove()
92
{
93 94 95

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

96 97
case $DISTRNAME in
	ALTLinux)
98
		__epm_autoremove_altrpm
99
		docmd epm remove-old-kernels
100 101 102 103
		
		if which nvidia-clean-driver 2>/dev/null ; then
			sudocmd nvidia-clean-driver
		fi
104

105 106 107
		return
		;;
	*)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
108
		;;
109 110 111
esac

case $PMTYPE in
Vitaly Lipatov's avatar
Vitaly Lipatov committed
112
	apt-dpkg|aptitude-dpkg)
113
		sudocmd apt-get autoremove
114
		;;
115 116 117
	aura)
		sudocmd aura -Oj
		;;
118 119 120
	yum-rpm)
		# cleanup orphanes?
		while true ; do
121
			docmd package-cleanup --leaves $(subst_option non_interactive --assumeyes)
122
			# FIXME: package-cleanup have to use stderr for errors
123
			local PKGLIST=$(package-cleanup -q --leaves | grep -v "^eepm-")
124 125 126 127
			[ -n "$PKGLIST" ] || break
			sudocmd yum remove $PKGLIST
		done
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
128 129 130
	dnf-rpm)
		sudocmd dnf autoremove
		;;
131 132 133 134
	# see autoorhans
	#urpm-rpm)
	#	sudocmd urpme --auto-orphans
	#	;;
135 136
	emerge)
		sudocmd emerge --depclean
137
		assure_exists revdep-rebuild
Vitaly Lipatov's avatar
Vitaly Lipatov committed
138
		sudocmd revdep-rebuild
139
		;;
140 141 142 143
	# see autoorhans
	#pacman)
	#	sudocmd pacman -Qdtq | sudocmd pacman -Rs -
	#	;;
144 145 146 147
	slackpkg)
		# clean-system removes non official packages
		#sudocmd slackpkg clean-system
		;;
148 149 150
	guix)
		sudocmd guix gc
		;;
151 152 153
	pkgng)
		sudocmd pkg autoremove
		;;
154 155 156 157 158 159 160 161
	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
		;;
162 163 164
	xbps)
		CMD="xbps-remove -O"
		;;
165
	*)
166
		fatal "Have no suitable command for $PMTYPE"
167 168 169 170
		;;
esac

}