Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Find & copy installed ebuilds after removal from tree
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
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Wed Mar 01, 2006 5:15 am    Post subject: Find & copy installed ebuilds after removal from tree Reply with quote

This script is in its early stages, but works for me. YMMV. Testing and input on improvements and features welcome -- especially the code ;) but not required.

Overview:
Over time, ebuild versions are removed from the tree, as support for those particular versions ceases. Consider three versions of a package: 1, 2 and 3. You have version 2 installed, and version 3 masked (maybe you're just not ready to install it). If version 2 is removed from the tree, portage will try to downgrade to version 1, since versions 2 & 3 are 'unavailable.' If version 1 is also unavailable (e.g., due to masking), Portage will error about no versions being available.

Having to manually create the directory structure in the overlay and copy the ebuild is inconvenient. This script automates those tasks.

Usage:
This command currently takes no options. Running it will copy relevant ebuilds from /var/db/pkg to your local portage overlay. root required, or permission errors will cause failure ("should" be graceful).

Manually running the program is recommended, as there currently are no options for reporting only or quiet modes.

Note: ebuilds are removed from the tree for reasons. You should be aware of those reasons specifically, or generically, and work toward using ebuild versions available in the tree. This is a 'stop gap' measure only. You have been informed.
Code:
#!/bin/sh
#
# Based on a script by Earthwings with input from Maedhros
# to find ebuilds of installed packages that have been
# removed from Portage.
#
# 2006.FEB.28 - Replaced informational only output.
#                               Added copy_to_overlay, create_overlay_path,
#                               and overlay_path_exists functions.
#
############################################################

source /sbin/functions.sh

#
# If overlay, category, and/or package dirs do not exist,
# try creating them, and recheck.
#
create_overlay_path() {
        ewarn "Overlay, category, or package dir do not exist.  Creating."
        mkdir -p "${overlay}/${category}/${pkg}/"
        overlay_path_exists
        if [ $? -ne 0 ]
        then
                return 1
        else
                eerror "\tCould not create ${overlay}/${category}/${pkg}/"
        fi

        return 0
}

#
# Check if the overlay, category, and package dirs exist
#
overlay_path_exists() {
        if [ -d "${overlay}/${category}/${pkg}/" ]
        then
                return 1
        fi
        return 0
}

#
# Copy ebuild from /var/db/pkg to overlay, & verify success
#
copy_to_overlay() {
        einfo "Copying ${filename} to overlay."
        cp $dir/${eb} ${overlay}/${filename}
        if [ ! -f ${overlay}/${filename} ] ; then return 0 ; fi

        return 1
}

einfo "Searching for ebuilds installed but not in the Portage tree anymore"

# Append the following to check the overlay too... $(portageq portdir_overlay)"
overlay="$(portageq portdir_overlay)"
portdirs="$(portageq portdir) ${overlay}"

for ebuild in $(find /var/db/pkg -type f -name "*.ebuild")
do
  dir="$(dirname $ebuild)"
  if [[ ! -f "${dir}/CATEGORY" || ! -f "${dir}/PF" ]]
  then
    ewarn "$ebuild has a broken /var/db/pkg entry"
    continue;
  fi

  category="$(cat "${dir}/CATEGORY")"
  pkg="$(cat "${dir}/PF" | sed 's/-[0-9]\{1,\}.*$//')"
  eb="$(basename "${ebuild}")"
  filename="${category}/${pkg}/${eb}"
  found=1
  for portdir in $portdirs
  do
    if [ -f "${portdir}/${filename}" ]
    then
      found=0
    fi
  done

  if [ $found == 1 ]
  then
        # Does the overlay directory structure exist to receive the ebuild?
        #  - Yes, then copy over the file from /var/db/pkg/...
        if [ -d "${overlay}/${category}/${pkg}/" ]
        then
                copy_to_overlay
                if [ $? -eq 0 ] ; then exit 1 ; fi
        #  - No, so try and create it and if successful, copy the ebuild.
        else
                create_overlay_path
                if [ $? -eq 0 ] ; then exit 1 ; fi
                copy_to_overlay
        fi
  fi
done


EDIT:
Corrected the credits.
_________________
Quis separabit? Quo animo?


Last edited by pjp on Wed Mar 01, 2006 9:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
Zarhan
l33t
l33t


Joined: 27 Feb 2004
Posts: 994

PostPosted: Wed Mar 01, 2006 3:38 pm    Post subject: Reply with quote

See https://bugs.gentoo.org/show_bug.cgi?id=48195 - altough it seems not much is happening on this issue.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Wed Mar 01, 2006 9:10 pm    Post subject: Reply with quote

I don't see anything in that bug as being related. Either I'm not understanding the connection to the bug, or I didn't do a good enough job at describing where this script is useful.
_________________
Quis separabit? Quo animo?
Back to top
View user's profile Send private message
Zarhan
l33t
l33t


Joined: 27 Feb 2004
Posts: 994

PostPosted: Wed Mar 01, 2006 9:53 pm    Post subject: Reply with quote

See the bugs that are marked as duplicates, some of them give a better explanation, but the crux is that, in your original problem, if package version "2" is removed, portage attempts to downgrade to "1".

If portage would take into account already installed packages (in /var/db/pkg) into dependency calculation, package version "2" would still be taken into account and the downgrade would not happen. So there would be no need to copy stuff to overlay portage tree.

This problem is most common with some kernel sources - since it's typically something that you don't want to upgrade for every point release, yet they keep vanishing from the main tree.
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 20053

PostPosted: Thu Mar 02, 2006 12:16 am    Post subject: Reply with quote

Ah, OK. I didn't follow the duplicates. Seems resolution is a ways off yet though. It does seem like something Portage should handle (and seems like it'd be a 'quick' fix). In the meantime...
_________________
Quis separabit? Quo animo?
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