Gentoo Archives: gentoo-user

From: Richard Fish <bigfish@××××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] USE flags, command line and packages.use
Date: Wed, 21 Dec 2005 20:59:02
Message-Id: 7573e9640512211247y3efcefd1x9272248bdd84a7eb@mail.gmail.com
In Reply to: [gentoo-user] USE flags, command line and packages.use by Daniel da Veiga
1 On 12/21/05, Daniel da Veiga <danieldaveiga@×××××.com> wrote:
2 > Hello list,
3 >
4 > Sorry if this is a silly question and/or if there is no easy way to
5 > fix the mess on my system, here is the problem: I installed
6 > everything, configured some stuff and started building apps, the only
7 > unstalbe package would be Xorg (because I need some drivers related to
8 > unichrome), and almost all apps passed an "emerge -pv" in order to
9 > check USE flags, the case is that I customized most of the packages,
10 > modifying the default USE for them, but I did that at command line
11 > (yeah, yeah, I know, don't tell me), now, is there some easy way to
12 > put the CURRENT USE flags that the packages in world are using at
13 > packages.use? I am afraid that an "emerge -u world" would download A
14 > LOT of unnecessary stuff using the default USE for each package, and
15 > causing a mess on my filesystem.
16
17
18 You are lucky this problem looked interesting to me! ;->
19
20 Here is a script that will:
21
22 1. Scan the package database
23 2. Examine the USE flags from when packages were merged, the USE flags
24 that the package knows about, and the current global USE flags.
25 3. Output package names and the use flag settings that need to be in
26 /etc/portage/package.use to account for the difference between the
27 global flags and what was in effect when the package was merged.
28
29 Save it as mkpkguse.sh and run it with "sh mkpkguse.sh".
30
31 Disclaimer: I think this works correctly, but I don't guarantee
32 anything. If it breaks, you get to keep the pieces.
33
34 -Richard
35
36 #!/bin/bash
37
38 idx_in_array() {
39 local item array i
40 item=$1
41 array=($2)
42
43 i=0
44 while test -n "${array[$i]}"; do
45 if test "${array[$i]}" = "$item"; then
46 echo $i
47 return 0
48 fi
49 i=$(($i + 1))
50 done
51 echo -1
52 return -1
53 }
54
55 cd /var/db/pkg
56 eval `emerge --info | grep ^USE=`
57 USE=($USE)
58
59 for pkg in */*; do
60 pkg_flags=(`cat $pkg/IUSE`)
61 used_flags=(`cat $pkg/USE`)
62 eval `bzcat $pkg/environment.bz2 | grep ^PN=`
63 category=`dirname $pkg`
64 i=0;
65 while test -n "${pkg_flags[$i]}"; do
66 flag=${pkg_flags[$i]}
67 use_idx=`idx_in_array "$flag" "${USE[*]}"`
68 pkg_idx=`idx_in_array "$flag" "${used_flags[*]}"`
69 if test $pkg_idx -lt 0 -a $use_idx -ge 0; then
70 # flag in current USE, but not when pkg
71 merged, use -flag
72 flag="-${flag}"
73 elif test $pkg_idx -ge 0 -a $use_idx -lt 0; then
74 # flag not in current USE, but was when pkg
75 merged, use +flag
76 flag="+${flag}"
77 else
78 # no change in flag
79 flag=""
80 fi
81
82 pkg_flags[$i]="$flag"
83 i=$(($i + 1))
84 done
85
86 flags=${pkg_flags[*]}
87 if test -n "$flags"; then
88 echo "$category/$PN $flags"
89 fi
90 done
91
92 --
93 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] USE flags, command line and packages.use Christoph Eckert <ce@×××××××××.de>