Re: Proposition
Hi !
The script is attached to this mail. It is called dpkg-revome although
this is not very appropriate :)
It only gives the idea of the missing functionnality I (actually, we,
people from "debian-french" after a short discussion) intended to
provide to "dpkg -r".
As you can see, it uses "dpkg -p" and "dpkg -r --no-act" to determine
which packages should be removed. Since I didn't want to enter these
commands code, it uses the ouput messages. However, one should do
better.
The end of the script sends a mail to root but, like M.O said, it could
be anoying. Any other idea is welcome.
I'm not a "real" debian developer although I consider myself as a rather
good programmer. I can therefor offer some help if wanted (with regards
to this idea's implementation or in a more general purpose).
Please let we know,
Nicolas.
Rick Younie wrote:
> Hi,
>
> I'd like to have a look please.
>
> Rick
> --
Marcin Owsiany wrote:
> This would be very nice, though mailing root after each package
> removal would be annoying IMHO.
> Marcin
--
Nicolas SABOURET
LIMSI-CNRS, BP133, 91403 Orsay, France
http://www.limsi.fr/Individu/nico
#!/bin/sh
##############
# FILE NAMES #
##############
tmpfile=/tmp/dpkg-remove.dat
depfile=/tmp/dpkg-remove.dep
#################
# HELP fonction #
#################
usage()
{
echo "usage: dpkg-remove <package> ..."
echo "Looks for packages not required anymore if you remove the package(s)"
exit
}
################
# MAIN Program #
################
#
# Check wether there are arguments
#
if [ $# -eq 0 ]
then
usage $*
fi
#
# Check for "command --help"
#
if [ $1 == "--help" ]
then
usage $*
fi
########
# body #
########
for i in $* # for all arguments
do
res=`dpkg -p $i | grep Depends`
#
# In case "dpkg -p" didn't find the package (or no "Depends" line !)
#
if [ `echo $res | wc -w` == 0 ]
then
echo "Warning : package \"$i\" does not exist"
else
#
# Otherwise, adds all the dependencies in "$tmpfile"
#
for j in $res
do
echo $j >> $tmpfile
done
fi
done
if [ -e $tmpfile ]
then
echo Checking dependencies :
else
echo No package could be removed
exit
fi
#
# Cleaning "$tmpfile" : remove "Depend", commas and versions numbers
#
grep -v Depends $tmpfile | grep -v "[\(\)]" | awk -F ',' '{print $1}' > $depfile
#
# "$depfile" now contains all the "depended" packages
#
# At this point, the packages given in parameter should be really removed
# Otherwise, all package in "$depfile" will be required by one of these and
# will therefore not be selected for removal !
#
#
# Begining or the mail
#
echo "After removal of $*, no more package uses :" > $tmpfile
#
# For all these, check wether they could be removed
#
for i in `cat $depfile`
do
echo $i
res=`dpkg --no-act -r $i 2>/dev/null | grep "Would remove or purge"`
#
# if it can be removed, adds it in $"tmpfile"
#
if [ `echo $res | wc -w` != 0 ]
then
echo " $i could be removed"
echo $i >> $tmpfile
fi
done
#
# Mail the result (if any) to root
#
if [ `cat $tmpfile | wc -l` != 1 ]
then
echo "If you do not use some of them, they could be removed safely. Run \"dpkg -s <package>\" for a desciption of the package(s)." >> $tmpfile
echo "Librairies especially should be removable without regret." >> $tmpfile
echo "However, if you installed some non-debian package on your system, be sure you do not remove something that it uses." >> $tmpfile
cat $tmpfile | mail -s "Package that might not be required anymore" root
else
echo No package could be removed
fi
## The END ##
rm $tmpfile
rm $depfile
############
# COMMENTS #
############
# HOW TO USE THIS PROGRAMM
#
# This program can be used upon packages that have already been removed,
# since it doesn't check wether the command arguments are installed packages.
#
# It could be included in the "dpkg -r" process or be kept separated, for use
# with a "package remove" log build by dpkg.
#
#
# LANGUAGE PROBLEM
#
# I programmed this for a computer using "C" as language (LANG=C).
# However, it should take into account the other languages (e.g. LANG="french")
# for the error messages returned by "dpkg -r" are in the right language
# (e.g. "Devrait enlever ou pruger ...")
#
#
# INCLUDING IN DPKG
#
# If this program is included in "dpkg -r", we should :
# - add it AT THE END of "dpkg -r", after package removal,
# - not call "dpkg-r | grep ..." but use "dpkg -r" build-in functions.
# This will :
# - increase performance
# - solve the language problem
Reply to: