On 12/21/05, Daniel da Veiga <[EMAIL PROTECTED]> wrote:
> Hello list,
>
> Sorry if this is a silly question and/or if there is no easy way to
> fix the mess on my system, here is the problem: I installed
> everything, configured some stuff and started building apps, the only
> unstalbe package would be Xorg (because I need some drivers related to
> unichrome), and almost all apps passed an "emerge -pv" in order to
> check USE flags, the case is that I customized most of the packages,
> modifying the default USE for them, but I did that at command line
> (yeah, yeah, I know, don't tell me), now, is there some easy way to
> put the CURRENT USE flags that the packages in world are using at
> packages.use? I am afraid that an "emerge -u world" would download A
> LOT of unnecessary stuff using the default USE for each package, and
> causing a mess on my filesystem.


You are lucky this problem looked interesting to me! ;->

Here is a script that will:

1. Scan the package database
2. Examine the USE flags from when packages were merged, the USE flags
that the package knows about, and the current global USE flags.
3. Output package names and the use flag settings that need to be in
/etc/portage/package.use to account for the difference between the
global flags and what was in effect when the package was merged.

Save it as mkpkguse.sh and run it with "sh mkpkguse.sh".

Disclaimer: I think this works correctly, but I don't guarantee
anything.  If it breaks, you get to keep the pieces.

-Richard

#!/bin/bash

idx_in_array() {
        local item array i
        item=$1
        array=($2)

        i=0
        while test -n "${array[$i]}"; do
                if test "${array[$i]}" = "$item"; then
                        echo $i
                        return 0
                fi
                i=$(($i + 1))
        done
        echo -1
        return -1
}

cd /var/db/pkg
eval `emerge --info | grep ^USE=`
USE=($USE)

for pkg in */*; do
        pkg_flags=(`cat $pkg/IUSE`)
        used_flags=(`cat $pkg/USE`)
        eval `bzcat $pkg/environment.bz2 | grep ^PN=`
        category=`dirname $pkg`
        i=0;
        while test -n "${pkg_flags[$i]}"; do
                flag=${pkg_flags[$i]}
                use_idx=`idx_in_array "$flag" "${USE[*]}"`
                pkg_idx=`idx_in_array "$flag" "${used_flags[*]}"`
                if test $pkg_idx -lt 0 -a $use_idx -ge 0; then
                        # flag in current USE, but not when pkg
merged, use -flag
                        flag="-${flag}"
                elif test $pkg_idx -ge 0 -a $use_idx -lt 0; then
                        # flag not in current USE, but was when pkg
merged, use +flag
                        flag="+${flag}"
                else
                        # no change in flag
                        flag=""
                fi

                pkg_flags[$i]="$flag"
                i=$(($i + 1))
        done

        flags=${pkg_flags[*]}
        if test -n "$flags"; then
                echo "$category/$PN $flags"
        fi
done

-- 
gentoo-user@gentoo.org mailing list

Reply via email to