From c538750fdc7405f7def2243fb54560493dc911de Mon Sep 17 00:00:00 2001 From: Vitaly Lipatov <lav@etersoft.ru> Date: Wed, 18 Oct 2017 12:05:11 +0300 Subject: [PATCH] autoremove: add support for autoremove [libs|python|perl|libs-devel] --- TODO | 2 -- bin/epm | 2 +- bin/epm-autoremove | 55 ++++++++++++++++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/TODO b/TODO index eac96ed..5dc1718 100644 --- a/TODO +++ b/TODO @@ -4,8 +4,6 @@ packages list таск аналог epm purge: запоминаем список файлов, удаляем пакеты и по возможности всё, от чего зависит (рекурсивно). -epm autoremove [libs|python|perl|libs-devel] - --interactive встроить вычисление зависимость сюда rpmreqs diff --git a/bin/epm b/bin/epm index 9fa6d7a..816cc36 100755 --- a/bin/epm +++ b/bin/epm @@ -256,7 +256,7 @@ check_command() clean) # HELPCMD: clean local package cache epm_cmd=clean ;; - autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) + autoremove|package-cleanup) # HELPCMD: auto remove unneeded package(s) Supports args for ALT: [libs|python|perl|libs-devel] epm_cmd=autoremove ;; autoorphans|--orphans) # HELPCMD: remove all packages not from the repository diff --git a/bin/epm-autoremove b/bin/epm-autoremove index 6de7c9f..71f6290 100644 --- a/bin/epm-autoremove +++ b/bin/epm-autoremove @@ -25,11 +25,12 @@ __epm_autoremove_altrpm_pp() #[ -n "$force" ] || info "You can run with --force for more deep removing" local force=force + local libexclude="$1" + 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" ) @@ -44,7 +45,7 @@ __epm_autoremove_altrpm_pp() if [ -n "$flag" ] ; then info "" info "call again for next cycle until all modules will be removed" - __epm_autoremove_altrpm_pp + __epm_autoremove_altrpm_pp "$libexclude" fi return 0 @@ -54,8 +55,16 @@ __epm_autoremove_altrpm_lib() { local pkgs + local nodevel="$1" + info - info "Removing all non -devel/-debuginfo libs packages not need by anything..." + if [ "$nodevel" = "nodevel" ] ; then + info "Removing all non -devel/-debuginfo libs packages not need by anything..." + local develrule='-(devel|devel-static)$' + else + info "Removing all non -debuginfo libs packages (-devel too) not need by anything..." + local develrule='-(NONONO)$' + fi #[ -n "$force" ] || info "You can run with --force for more deep removing" local force=force @@ -67,7 +76,8 @@ __epm_autoremove_altrpm_lib() showcmd "apt-cache list-nodeps | grep -- \"$libexclude\"" pkgs=$(apt-cache list-nodeps | grep -E -- "$libexclude" \ | sed -e "s/[-\.]32bit$//g" \ - | grep -E -v -- "-(devel|devel-static|debuginfo)$" \ + | grep -E -v -- "$develrule" \ + | grep -E -v -- "-(debuginfo)$" \ | grep -E -v -- "-(util|utils|tool|tools|plugin|daemon|help)$" \ | grep -E -v -- "^(libsystemd|libreoffice|libnss|libvirt-client|libvirt-daemon|libsasl2-plugin|eepm)" ) @@ -82,7 +92,7 @@ __epm_autoremove_altrpm_lib() if [ -n "$flag" ] ; then info "" info "call again for next cycle until all libs will be removed" - __epm_autoremove_altrpm_lib + __epm_autoremove_altrpm_lib $nodevel fi return 0 @@ -91,12 +101,35 @@ __epm_autoremove_altrpm_lib() __epm_autoremove_altrpm() { - local pkg + local i load_helper epm-packages assure_exists /etc/buildreqs/files/ignore.d/apt-scripts apt-scripts - __epm_autoremove_altrpm_pp - __epm_autoremove_altrpm_lib + if [ -z "$pkg_names" ] ; then + __epm_autoremove_altrpm_pp '^(python-module-|python3-module-|python-modules-|python3-modules|perl-)' + __epm_autoremove_altrpm_lib nodevel + return 0 + fi + + for i in $pkg_names ; do + case $i in + libs) + __epm_autoremove_altrpm_lib nodevel + ;; + python) + __epm_autoremove_altrpm_pp '^(python-module-|python3-module-|python-modules-|python3-modules)' + ;; + perl) + __epm_autoremove_altrpm_pp '^(perl-)' + ;; + libs-devel) + __epm_autoremove_altrpm_lib + ;; + *) + fatal "autoremove: unsupported '$i'. Use libs, python, perl, libs-devel." + ;; + esac + done return 0 } @@ -105,8 +138,6 @@ __epm_autoremove_altrpm() epm_autoremove() { -[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here" - case $DISTRNAME in ALTLinux) __epm_autoremove_altrpm @@ -125,6 +156,8 @@ case $DISTRNAME in ;; esac +[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here" + case $PMTYPE in apt-dpkg|aptitude-dpkg) sudocmd apt-get autoremove $dryrun -- 2.24.1