彻底卸载rpm软件包的脚本
有时卸载一个软件包时,发现有很多其它软件包依赖它,强制卸载会造成这些软件包都无法使用。下面这个脚本可以卸载一个软件包及依赖于它的所有软件包。
rpm_erase_deps.sh
#!/bin/bash
#######################################################
PACKAGE=$1
RPM_OPS="-e"
#######################################################
if [ "$1" = "" ]
then
echo "usage : $0 package --rpmops=[/'opts/']"
echo "example: $0 ant --rpmops='--test -e'"
exit 1
fi
#######################################################
while [ ! "$1" = "" ]
do
shift
arg=$1
if [ "${arg:0:8}" = "--rpmops" ]
then
RPM_OPS="${arg:9:100}"
fi
done
function show_depends()
{
local _PACKAGE="$1"
local _INDENT="$2"
DEPS=`rpm --test -e $_PACKAGE 2>&1|grep needed|awk '{print $NF}'`
for depends in $DEPS
do
echo "$_INDENT $depends"
show_depends "$depends" "$_INDENT""--"
done
}
function rpm_do_erase()
{
local _PACKAGE="$1"
local _INDENT="$2"
DEPS=`rpm $RPM_OPS $_PACKAGE 2>&1|grep needed|awk '{print $NF}'`
for depends in $DEPS
do
echo "erase $_INDENT $depends"
rpm_do_erase "$depends" "$_INDENT""--"
if [ ! "$?" = 0 ]
then
echo "erase $_INDENT $depends failed."
fi
done
}
echo "show depends graph:"
echo "$PACKAGE"
show_depends $PACKAGE "--"
echo "do you want to uninstall $_PACKAGE (y/n)?"
read yn
if [ "$yn" = "y" ]
then
rpm_do_erase $PACKAGE "--"
else
echo "cancel uninstall $PACKAGE"
fi