Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 3588 - dep-clean gentoolkit script (new!)
Summary: dep-clean gentoolkit script (new!)
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Brandon Low (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-10 14:18 UTC by Jerry Haltom
Modified: 2003-02-04 19:42 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
man page for dep-clean (dep-clean.1.gz,2.42 KB, application/gzip)
2002-07-18 15:04 UTC, Paul Belt
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jerry Haltom 2002-06-10 14:18:03 UTC
Pretty useful script.  Let me know what you think, and modify how you'd like.

#!/bin/bash
#Shows unrequired packages and missing dependencies.
#Author: Jerry Haltom <ssrit@larvalstage.net>

if [ `whoami` != "root" ]
then
	echo 'Only root can run this tool.'
	exit
fi

tmp="/tmp/$$"

rm -rf ${tmp} > /dev/null 2>&1
mkdir ${tmp} > /dev/null 2>&1
rm ${tmp}/current ${tmp}/i > /dev/null 2>&1
touch ${tmp}/current ${tmp}/image ${tmp}/safe ${tmp}/needed

#Retrieve currently merged packages.
echo Retrieving currently merged packages.
find /var/db/pkg -name '*.ebuild' \
	| sed s:/var/db/pkg/:: \
	| sed s/-[0-9].*// \
	| sort \
	| sort -u \
	>> ${tmp}/current

echo '   ' `cat ${tmp}/current | wc -l` 'currently merged packages.'
echo

#Open currently merged packages in text viewer for review.
#${EDITOR} ${tmp}/current

echo 'Retrieving desired packages.'

#Retrieve system packages and add to image.
emerge system -e -p \
	| grep ^\\[ebuild \
	| sed s/^...........................// \
	| sed s/.....$// \
	| sed s/-[0-9].*// \
	| sort \
	| sort -u \
	>> ${tmp}/image

echo '   ' `cat ${tmp}/image | wc -l` 'packages contained in system.'

#Create local copy of world and ask user to verify it.
#echo 'Please add or remove packages from world.'
cp /var/cache/edb/world ${tmp}/world
#${EDITOR} ${tmp}/world
echo '   ' `cat ${tmp}/world | wc -l` 'packages contained in world.'

echo

#Retrieve world packages and dependencies and add to image.
echo 'Listing world and total number of dependencies.'
for pkg in `cat ${tmp}/world | sort | sort -u`
do
	emerge ${pkg} -e -p \
		| grep ^\\[ebuild \
		| sed s/^...........................// \
		| sed s/.....$// \
		| sed s/-[0-9].*// \
		> ${tmp}/pkg-deps
	echo '   ' ${pkg} `cat ${tmp}/pkg-deps | wc -l`
	
	cat ${tmp}/pkg-deps >> ${tmp}/image
done
echo

#Cleanup image
sort ${tmp}/image | sort -u > ${tmp}/image.new
mv ${tmp}/image.new ${tmp}/image

#Show user the final image.
#echo 'Review the final destination system image.'
#${EDITOR} ${tmp}/image
#echo

#Determine packages that exist in current but not in image.  These packages are
safe to clean up.
echo 'These packages have no other packages depending on them.'
for pkg in `cat ${tmp}/current`
do
	if [ "`cat ${tmp}/image | grep -x ${pkg} | wc -l`" -eq "0" ]
	then
		echo '   ' ${pkg} 'has no currently depending packages.'
		echo ${pkg} >> ${tmp}/safe
	fi
done
echo '    Total of' `cat ${tmp}/safe | wc -l` 'packages.'
echo

#Determine packages that exist in image but not in current.  These packages
should be added.
echo 'These packages are depended upon but are not present on the system.'
for pkg in `cat ${tmp}/image`
do
	if [ "`cat ${tmp}/current | grep -x ${pkg} | wc -l`" -eq "0" ]
	then
		echo '   ' ${pkg} 'is not present.'
		echo ${pkg} >> ${tmp}/needed
	fi
done
echo '    Total of' `cat ${tmp}/needed | wc -l` 'packages.'
echo

rm -rf ${tmp}
Comment 1 Brandon Low (RETIRED) gentoo-dev 2002-06-12 13:08:18 UTC
check out what I've hacked up based on your script at 
http://www.lostlogicx.com/ebuilds/depend.scr
Let me know what you think and then I'll talk to karltk about including it in
gentoolkit, I do find it quite convenient :)
Comment 2 Jerry Haltom 2002-06-12 14:30:29 UTC
Cool and all... except it's broken now.  hehe.

These packages have no other packages depending on them.
app-admin/fam-oss-2.6.7
app-admin/gentoolkit-0.1.10
app-admin/gentoolkit-0.1.11
app-misc/screen-3.9.11-r2
app-office/gnumeric-1.0.6
app-text/ghostscript-6.53-r2
dev-java/blackdown-jre-1.3.1-r7
dev-lang/tcl-8.3.3-r1
dev-libs/glib-2.0.1-r5

... continued.

Ill be looking over it a bit later.
Comment 3 Jerry Haltom 2002-06-12 14:50:37 UTC
Ok looked over it a bit more.  The reason I looped over emerge -ep $worldline is
because emerge -ep apparently has a bug that does not list all the correct
dependencies when done on world.  I could never place the bug, but it did effect
results.
Comment 4 Brandon Low (RETIRED) gentoo-dev 2002-06-12 17:44:26 UTC
well I didn't do it on "world" I did it on the list of packages IN world... the
way you had it was just taking forever at runtime... not that hard to switch it
really... hmm...
Comment 5 Brandon Low (RETIRED) gentoo-dev 2002-06-12 22:10:15 UTC
fixed.  at a compromise in runtime... new version same place as the old.

I'm going to talk to karltk as soon as I get a chance about including it... if
he agrees with me that it is a convenient tool, would you be interested in
making a man page for it?
Comment 6 Brandon Low (RETIRED) gentoo-dev 2002-06-13 09:48:22 UTC
Another update to the version posted on my website... MUCH faster by using a
single qpkg call and an fgrep... I can probably still make it faster... but I
haven't gotten to that yet.
Comment 7 Brandon Low (RETIRED) gentoo-dev 2002-06-13 19:12:19 UTC
I've been doing more work on this... added another feature that started as a
bug... check it out at the URL posted previously... I think it is getting close
to production ready.
Comment 8 Brandon Low (RETIRED) gentoo-dev 2002-06-13 21:23:09 UTC
OK so I have time on my hands... but I updated the script a wee bit more, now it
parses multiple short opts together (ie. -CNvRUI) to do this I had to change the
no color short option to -C, hope that doesn't bother anyone... how to import
this functionality into qpkg... :)
Comment 9 Jerry Haltom 2002-06-16 14:30:20 UTC
Haha awesome.  Looks like it really took off.  Yes, I think this should be
included in qpkg...
Comment 10 Brandon Low (RETIRED) gentoo-dev 2002-06-16 15:13:09 UTC
I poked at qpkg with a stick, due to the types of options that the original 
qpkg author used I can't make it parse combined shorts... I am beginning to 
more seriously consider karltk's previous suggestion of deprecating qpkg and 
rewriting it from scratch with a new name...  Hmm... still haven't done the man 
page for dep-clean (or whatever we end up calling it in gentoolkit) any chance 
of you doing it, Jerry?
Comment 11 Jerry Haltom 2002-06-16 19:40:39 UTC
Sure.  What are we going to call it?
Comment 12 Paul Belt 2002-07-18 15:04:10 UTC
Created attachment 2363 [details]
man page for dep-clean

Per our discussions...
Comment 13 Brandon Low (RETIRED) gentoo-dev 2002-07-18 20:21:03 UTC
Its in, thanks Jerry and Paul for your work on this!