Commit 54756d39 authored by Vitaly Lipatov's avatar Vitaly Lipatov

add --dry-run support to remove, autoorphans, autoremove

parent eb459192
......@@ -4,8 +4,6 @@ packages list таск
аналог epm purge: запоминаем список файлов, удаляем пакеты и по возможности всё, от чего зависит (рекурсивно).
--dry-run при удалении (--print)
epm autoremove [libs|python|perl|libs-devel]
--interactive
......
......@@ -79,6 +79,7 @@ verbose=
quiet=
nodeps=
noremove=
dryrun=
force=
short=
direct=
......@@ -334,6 +335,9 @@ check_option()
--noremove|--no-remove) # HELPOPT: exit if any packages are to be removed during upgrade
noremove="--no-remove"
;;
--dry-run|--simulate|--just-print|-recon--no-act) # HELPOPT: print only (autoremove/autoorphans only)
dryrun="--dry-run"
;;
--short) # HELPOPT: short output (just 'package' instead 'package-version-release')
short="--short"
;;
......
#!/bin/sh
#
# Copyright (C) 2015, 2016 Etersoft
# Copyright (C) 2015, 2016 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2015, 2017 Etersoft
# Copyright (C) 2015, 2017 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
......@@ -32,18 +32,25 @@ case $PMTYPE in
apt-rpm)
# ALT Linux only
assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts
echo "We will try remove all installed packages which are missed in repositories"
warning "Use with caution!"
if [ -z "$dryrun" ] ; then
echo "We will try remove all installed packages which are missed in repositories"
warning "Use with caution!"
fi
local PKGLIST=$(__epm_orphan_altrpm \
| sed -e "s/\.32bit//g" \
| grep -v -- "^eepm$" \
| grep -v -- "^kernel")
docmd epm remove $PKGLIST
if [ -n "$quiet" ] ; then
echo "$PKGLIST"
else
docmd epm remove $dryrun $PKGLIST
fi
;;
apt-dpkg|aptitude-dpkg)
assure_exists deborphan
showcmd deborphan
a='' deborphan | docmd epm remove
a='' deborphan | docmd epm remove $dryrun
;;
#aura)
# sudocmd aura -Oj
......@@ -51,18 +58,22 @@ case $PMTYPE in
yum-rpm)
showcmd package-cleanup --orphans
local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
docmd epm remove $PKGLIST
docmd epm remove $dryrun $PKGLIST
;;
dnf-rpm)
# TODO: dnf list extras
# TODO: Yum-utils package has been deprecated, use dnf instead.
showcmd package-cleanup --orphans
local PKGLIST=$(package-cleanup -q --orphans | grep -v "^eepm-")
docmd epm remove $PKGLIST
docmd epm remove $dryrun $PKGLIST
;;
urpm-rpm)
showcmd urpme --report-orphans
sudocmd urpme --auto-orphans
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
else
showcmd urpme --report-orphans
sudocmd urpme --auto-orphans
fi
;;
#emerge)
# sudocmd emerge --depclean
......@@ -70,7 +81,12 @@ case $PMTYPE in
# sudocmd revdep-rebuild
# ;;
pacman)
sudocmd pacman -Qdtq | sudocmd pacman -Rs -
if [ -n "$dryrun" ] ; then
info "Autoorphans packages list:"
sudocmd pacman -Qdtq
else
sudocmd pacman -Qdtq | sudocmd pacman -Rs -
fi
;;
#slackpkg)
# clean-system removes non official packages
......@@ -89,10 +105,14 @@ case $PMTYPE in
sudocmd zypper packages --orphaned
# FIXME: x86_64/i586 are duplicated
local PKGLIST=$(zypper packages --orphaned | tail -n +5 | cut -d \| -f 3 | sort -u)
sudocmd zypper remove --clean-deps $PKGLIST
docmd epm remove $dryrun --clean-deps $PKGLIST
;;
xbps)
CMD="xbps-remove -o"
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
else
sudocmd xbps-remove -o
fi
;;
*)
fatal "Have no suitable command for $PMTYPE"
......
#!/bin/sh
#
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2017 Etersoft
# Copyright (C) 2012, 2017 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
......@@ -32,6 +32,13 @@ __epm_autoremove_altrpm_pp()
[ -n "$force" ] || libexclude=$libexclude'[^-]*$'
showcmd "apt-cache list-nodeps | grep -E -- \"$libexclude\""
pkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" )
if [ -n "$dryrun" ] ; then
info "Packages for autoremoving:"
echo "$pkgs"
return 0
fi
[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1
if [ -n "$flag" ] ; then
......@@ -63,6 +70,13 @@ __epm_autoremove_altrpm_lib()
| grep -E -v -- "-(devel|devel-static|debuginfo)$" \
| grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \
| grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|libsasl2-plugin|eepm)" )
if [ -n "$dryrun" ] ; then
info "Packages for autoremoving:"
echo "$pkgs"
return 0
fi
[ -n "$pkgs" ] && sudocmd rpm -v -e $pkgs && flag=1
if [ -n "$flag" ] ; then
......@@ -96,6 +110,9 @@ epm_autoremove()
case $DISTRNAME in
ALTLinux)
__epm_autoremove_altrpm
[ -n "$dryrun" ] && return
docmd epm remove-old-kernels
if which nvidia-clean-driver 2>/dev/null ; then
......@@ -110,9 +127,12 @@ esac
case $PMTYPE in
apt-dpkg|aptitude-dpkg)
sudocmd apt-get autoremove
sudocmd apt-get autoremove $dryrun
;;
aura)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd aura -Oj
;;
yum-rpm)
......@@ -123,10 +143,13 @@ case $PMTYPE in
# FIXME: package-cleanup have to use stderr for errors
local PKGLIST=$(package-cleanup -q --leaves | grep -v "^eepm-")
[ -n "$PKGLIST" ] || break
sudocmd yum remove $PKGLIST
showcmd epm remove $PKGLIST
done
;;
dnf-rpm)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd dnf autoremove
;;
# see autoorhans
......@@ -134,6 +157,9 @@ case $PMTYPE in
# sudocmd urpme --auto-orphans
# ;;
emerge)
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd emerge --depclean
assure_exists revdep-rebuild
sudocmd revdep-rebuild
......@@ -158,10 +184,13 @@ case $PMTYPE in
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
showcmd epm remove --clean-deps $PKGLIST
;;
xbps)
CMD="xbps-remove -O"
if [ -n "$dryrun" ] ; then
fatal "--dry-run is not supported yet"
fi
sudocmd xbps-remove -O
;;
*)
fatal "Have no suitable command for $PMTYPE"
......
......@@ -234,7 +234,19 @@ epm_remove()
[ -n "$pkg_files" ] && pkg_names="$pkg_names $(epm query $pkg_files)"
[ -n "$pkg_names" ] || fatal "Remove: missing package(s) name."
if [ -n "$dryrun" ] ; then
info "Packages for removing:"
echo "$pkg_names"
return
fi
epm_remove_low $pkg_names && return
local STATUS=$?
if [ -n "$direct" ] ; then
return $STATUS
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment