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