View previous topic :: View next topic |
Author |
Message |
singular n00b


Joined: 07 Jun 2003 Posts: 54
|
Posted: Mon Feb 09, 2004 2:34 am Post subject: Automatically inject unwanted packages |
|
|
Sometimes when installing a metapackage like Gnome or KDE you may not want to install certain packages that they contain - like Epiphany or all the games. The usual suggestion is to either manually inject the packages into portage or create your own ebuild in PORTDIR_OVERLAY.
While this works, you end up needing to do the same thing over and over again whenever there is an update to the metapackage or the unwanted package itself.
This script will automatically check if there is any update to an unwanted package listed in a config file, and automatically inject it into portage for you.
Step 1:
Copy this script and save it as /usr/local/bin/autoinject
Code: |
#! /usr/bin/python
# This script will scan packages listed in /etc/portage/package.inject
# and check for updates to them. If any updates are found, it will
# automatically inject them into portage.
import sys
import portage
# Check if user has the correct permission
if portage.secpass != 2 :
print "%s: root access required" % sys.argv[0]
sys.exit(1)
def emergelog(mystr):
try :
mylogfile=open("/var/log/emerge.log", "a")
mylogfile.write(str(time.time())[:10]+": "+mystr+"\n")
mylogfile.flush()
mylogfile.close()
except Exception, e :
pass
packages = portage.grabfile("/etc/portage/package.inject")
if packages :
print "Checking for package updates to inject..."
installed = portage.db["/"]["vartree"]
for pkg in packages :
# Check if package name is formatted correctly
catpkg = pkg.split("/")
if len(catpkg) != 2 :
print '!!! "%s" is not a specific cat/pkg, skipping...' % pkg
continue
current = installed.dep_bestmatch(pkg)
latest = portage.portdb.xmatch("bestmatch-visible", pkg)
# Check if package is a legitimate ebuild
if not latest :
print '!!! There are no masked or unmasked ebuilds to satisfy "%s".' % pkg
continue
if current != latest :
installed.dbapi.cpv_inject(latest)
print ">>>Injected %s." % latest
emergelog(" === inject: %s" % latest)
print "Done."
|
Make sure you give it executable permission.
Code: | hermes root# chmod +x /usr/local/bin/autoinject |
Step2:
Add the unwanted packages to /etc/portage/package.inject
Note that the name needs to be in the category/package format.
Code: | hermes root# echo net-www/epiphany >> /etc/portage/package.inject |
Right now you can call the program manually or do something like :
Code: | hermes root# emerge sync && autoinject |
and it will go through your list and inject any updates, but we can make it completely automatic with a little bash magic.
Step3: (optional)
To make it run automatically after an `emerge sync` simply add this to your ~/.bashrc
Code: |
#---- emerge: wrapper script to call autoinject after an emerge sync -------
emerge () {
EMERGE="/usr/bin/emerge"
AUTO_INJECT="/usr/local/bin/autoinject"
if [[ "$1" == "sync" || "$1" == "--sync" ]]; then
${EMERGE} "$@" && ${AUTO_INJECT}
else
${EMERGE} "$@"
fi
}
|
Note the usual disclaimer applies,
I am not responsible if this completely trashes your system, sets your computer on fire, etc. Use it at your own risk.
But on the other hand if it does work....  |
|
Back to top |
|
 |
Given M. Sur l33t


Joined: 03 Feb 2004 Posts: 648 Location: No such file or directory
|
Posted: Wed Jul 28, 2004 2:46 am Post subject: |
|
|
You may want to set up the script so it unmerges the older injected version. That way your world file doesn't build up with injected packages. _________________ What is the best [insert-type-of-program-here]? |
|
Back to top |
|
 |
singular n00b


Joined: 07 Jun 2003 Posts: 54
|
Posted: Thu Jul 29, 2004 3:52 am Post subject: |
|
|
I've found that isn't really necessary. Then next time you run emerge, portage will automatically remove the older version when it is finished. At least that is how it has been working on my computers.
From my understanding, I think the only time that wouldn't happen would be if you had set AUTOCLEAN="no" in /etc/make.conf, but if you had that set, I don't think the script should be removing it either.
If I'm wrong about this, let me know, and I'll see about adding an option to the script to clean out the older versions after it injects the package. |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|