Commit 0d186c4d authored by Vitaly Lipatov's avatar Vitaly Lipatov

improve epm remove for remove by package file and remove kernel packages via apt and yum

parent c0147c05
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2013 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2013 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
...@@ -37,6 +37,52 @@ _query_via_packages_list() ...@@ -37,6 +37,52 @@ _query_via_packages_list()
return $res return $res
} }
# internal use only
__epm_get_hilevel_nameform()
{
[ -n "$*" ] || return
case $PMTYPE in
apt-rpm)
# use # as delimeter for apt
local pkg
pkg=$(rpm -q --queryformat "%{NAME}#%{SERIAL}:%{VERSION}-%{RELEASE}\n" $1)
echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}#%{VERSION}-%{RELEASE}\n" $1)
# HACK: can use only for multiple install packages like kernel
echo $pkg | grep -q kernel || return 1
echo $pkg
return
;;
yum-rpm)
# just use strict version with Epoch and Serial
local pkg
pkg=$(rpm -q --queryformat "%{EPOCH}:%{NAME}%{VERSION}-%{RELEASE}.${ARCH}\n" $1)
echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.${ARCH}\n" $1)
echo $pkg
return
;;
*)
return 1
;;
esac
}
# for local installed packages only
# used from epm remove
__epm_get_hilevel_name()
{
local i
for i in $@ ; do
local pkg
# get short form in pkg
quiet=1 short=1 pkg=$(__epm_query_name $i)
# if already short form, skipped
[ "$pkg" = "$i" ] && echo "$i" && continue
# try get long form or use short form
__epm_get_hilevel_nameform $i || echo $pkg
done
}
__epm_query_file() __epm_query_file()
{ {
local CMD local CMD
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2013 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2013 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
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
load_helper epm-query
# Try remove with low level removing # Try remove with low level removing
epm_remove_low() epm_remove_low()
{ {
...@@ -171,18 +173,22 @@ epm_remove() ...@@ -171,18 +173,22 @@ epm_remove()
return return
fi fi
[ -n "$pkg_files" ] && fatal "FIXME: remove by package file is not supported yet" # get full package name(s) from the package file(s)
[ -n "$pkg_files" ] && pkg_names="$pkg_names $(epm query $pkg_files)"
[ -n "$pkg_names" ] || fatal "Run remove without args"
epm_remove_low $pkg_names && return
[ -n "$pkg_filenames" ] || fatal "Run remove without args" # get package name for hi level package management command (with version if supported and if possible)
epm_remove_low $pkg_filenames && return pkg_names=$(__epm_get_hilevel_name $pkg_names)
if [ -n "$non_interactive" ] ; then if [ -n "$non_interactive" ] ; then
epm_remove_nonint $pkg_filenames epm_remove_nonint $pkg_names
local RET=$? local RET=$?
# if not separate command, use usual command # if not separate command, use usual command
[ "$RET" = "5" ] || return $RET [ "$RET" = "5" ] || return $RET
fi fi
epm_remove_names $pkg_filenames epm_remove_names $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