Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Automatically inject unwanted packages
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 07 Jun 2003
Posts: 54

PostPosted: Mon Feb 09, 2004 2:34 am    Post subject: Automatically inject unwanted packages Reply with quote

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

#! /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]

def emergelog(mystr):
    try :
        mylogfile=open("/var/log/emerge.log", "a")
        mylogfile.write(str(time.time())[:10]+": "+mystr+"\n")
    except Exception, e :

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
        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
        if current != latest :
            print ">>>Injected %s." % latest
            emergelog(" === inject: %s" % latest)
    print "Done."

Make sure you give it executable permission.
hermes root# chmod +x /usr/local/bin/autoinject

Add the unwanted packages to /etc/portage/package.inject
Note that the name needs to be in the category/package format.
hermes root# echo net-www/epiphany >> /etc/portage/package.inject

Right now you can call the program manually or do something like :
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

#---- emerge: wrapper script to call autoinject after an emerge sync -------
emerge () {
    if [[ "$1" == "sync" || "$1" == "--sync" ]]; then
        ${EMERGE} "$@" && ${AUTO_INJECT}
        ${EMERGE} "$@"

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.... :D
Back to top
View user's profile Send private message
Given M. Sur

Joined: 03 Feb 2004
Posts: 648
Location: No such file or directory

PostPosted: Wed Jul 28, 2004 2:46 am    Post subject: Reply with quote

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
View user's profile Send private message

Joined: 07 Jun 2003
Posts: 54

PostPosted: Thu Jul 29, 2004 3:52 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
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