rpmパッケージを完全にアンインストール用スクリプト

rpmuninstall.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

}

####rpmをアンインストールする###
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 “作業 $_INDENT $depends 失敗した"

fi

done

}

echo “show depends graph:"

echo “$PACKAGE"

show_depends $PACKAGE “–"

echo “本当に $_PACKAGE (y/n)をアンインストールするか?"

read yn

if [ “$yn" = “y" ]

then

rpm_do_erase $PACKAGE “–"

else

echo " $PACKAGEのアンインストールをキャンセルする"

fi

Source

Posted by arkgame