1 |
commit: d48d1c9525f6632e9ba58202e028bb517b0a118c |
2 |
Author: Paul Varner <fuzzyray <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Mar 29 02:12:44 2011 +0000 |
4 |
Commit: Paul Varner <fuzzyray <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Mar 29 02:12:44 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=d48d1c95 |
7 |
|
8 |
Latest euse changes from Jared Hancock |
9 |
Prefers /etc/portage/make.conf when modifing global flags only if it |
10 |
defines the USE variable |
11 |
|
12 |
Also fixes a bug where euse would refuse to add hyphenated use flags. |
13 |
So you can: |
14 |
|
15 |
euse -E bash-completion |
16 |
|
17 |
--- |
18 |
bin/euse | 79 ++++++++++++++++++++++++++++++++++++-------------------------- |
19 |
1 files changed, 46 insertions(+), 33 deletions(-) |
20 |
|
21 |
diff --git a/bin/euse b/bin/euse |
22 |
index dbbb129..8262271 100755 |
23 |
--- a/bin/euse |
24 |
+++ b/bin/euse |
25 |
@@ -29,10 +29,13 @@ warn() { |
26 |
echo -e "WARNING: ${*}" |
27 |
} |
28 |
|
29 |
-# /etc/make.conf can now exist in /etc/portage/make.conf, prefer it over /etc/make.conf for changes |
30 |
-if [ -e "${ETC}/portage/make.conf" ]; then |
31 |
+# /etc/make.conf can now exist in /etc/portage/make.conf, prefer it over |
32 |
+# /etc/make.conf for changes. Since this will only be used for modifying |
33 |
+# the USE variable, we need to make sure the one we pick is the one with |
34 |
+# the USE variable defined. |
35 |
+if [[ -n $(grep '^USE="' "${ETC}/portage/make.conf" 2>/dev/null) ]]; then |
36 |
MAKE_CONF_PATH="${ETC}/portage/make.conf" |
37 |
-elif [ -e "${ETC}/make.conf" ]; then |
38 |
+elif [[ -e "${ETC}/make.conf" ]]; then |
39 |
MAKE_CONF_PATH="${ETC}/make.conf" |
40 |
else |
41 |
fatal "make.conf does not exist" |
42 |
@@ -56,7 +59,7 @@ else |
43 |
fi |
44 |
PACKAGE_USE_PATH=${ETC}/portage/package.use |
45 |
|
46 |
-[ -z "${MODE}" ] && MODE="showhelp" # available operation modes: showhelp, showversion, showdesc, showflags, modify |
47 |
+[ -z "${MODE:-}" ] && MODE="showhelp" # available operation modes: showhelp, showversion, showdesc, showflags, modify |
48 |
|
49 |
parse_arguments() { |
50 |
if [ -z "${1}" ]; then |
51 |
@@ -74,8 +77,8 @@ parse_arguments() { |
52 |
-E | --enable) MODE="modify"; ACTION="add";; |
53 |
-D | --disable) MODE="modify"; ACTION="remove";; |
54 |
-P | --prune | -R | --remove) |
55 |
- MODE="modify"; ACTION="prune";; |
56 |
- -p | --package) MODE="modify"; shift; PACKAGE=${1}; SCOPE="local";; |
57 |
+ MODE="modify"; ACTION="prune";; |
58 |
+ -p | --package) MODE="modify"; shift; PACKAGE=${1}; SCOPE="local";; |
59 |
-*) |
60 |
echo "ERROR: unknown option ${1} specified." |
61 |
echo |
62 |
@@ -83,10 +86,10 @@ parse_arguments() { |
63 |
;; |
64 |
"%active") |
65 |
get_portageuseflags |
66 |
- ARGUMENTS="${ARGUMENTS} ${ACTIVE_FLAGS[9]}" |
67 |
+ ARGUMENTS="${ARGUMENTS:-} ${ACTIVE_FLAGS[9]}" |
68 |
;; |
69 |
*) |
70 |
- ARGUMENTS="${ARGUMENTS} ${1}" |
71 |
+ ARGUMENTS="${ARGUMENTS:-} ${1}" |
72 |
;; |
73 |
esac |
74 |
shift |
75 |
@@ -128,6 +131,7 @@ check_sanity() { |
76 |
done |
77 |
[ "${MODE}" == "modify" -a ! -w "${MAKE_CONF_PATH}" ] && fatal ""${MAKE_CONF_PATH}" is not writable" |
78 |
[ "${MODE}" == "modify" -a -s "${PACKAGE_USE_PATH}" -a ! -w "${PACKAGE_USE_PATH}" ] && fatal ""${PACKAGE_USE_PATH}" is not writable" |
79 |
+ return 0 |
80 |
} # }}} |
81 |
|
82 |
showhelp() { |
83 |
@@ -435,7 +439,7 @@ get_all_make_conf() { |
84 |
traverse_profile() { |
85 |
local curdir |
86 |
local parent |
87 |
- local rvalue |
88 |
+ local rvalue="" |
89 |
|
90 |
curdir="${2:-$(get_real_path ${MAKE_PROFILE_PATH})}" |
91 |
|
92 |
@@ -458,7 +462,7 @@ traverse_profile() { |
93 |
# Function: get_all_make_defaults {{{ |
94 |
# Det all make.defaults by traversing the cascaded profile directories |
95 |
get_all_make_defaults() { |
96 |
- if [[ -z $MAKE_DEFAULTS ]]; then |
97 |
+ if [[ -z ${MAKE_DEFAULTS:-} ]]; then |
98 |
MAKE_DEFAULTS=$(traverse_profile "make.defaults") |
99 |
fi |
100 |
echo $MAKE_DEFAULTS |
101 |
@@ -606,7 +610,7 @@ get_flagstatus() { |
102 |
# Flag status for package.use and ebuild, slot and version, and overlay |
103 |
# the version lives is if not PORTDIR |
104 |
# |
105 |
-# Full positive would be "[+PB]", full negative would be "[-pb], and full |
106 |
+# Full positive would be "[+PB]", full negative would be "[-pb]", and full |
107 |
# missing would be "[? ]", question because the sign will default to the |
108 |
# sign of the global status of the flag |
109 |
get_flagstatus_pkg() { |
110 |
@@ -671,8 +675,10 @@ get_flagstatus_pkg() { |
111 |
# Outputs: |
112 |
# Location of portage tree root |
113 |
get_portdir() { |
114 |
- if [ -z "${PORTDIR}" ]; then |
115 |
- use_backup="${USE}" |
116 |
+ # Use a subshell so we don't have to protect the variables in |
117 |
+ # the current scope |
118 |
+ ( |
119 |
+ if [ -z "${PORTDIR:-}" ]; then |
120 |
source "${MAKE_GLOBALS_PATH}" |
121 |
for x in $(get_all_make_defaults); do |
122 |
source "${x}" |
123 |
@@ -680,9 +686,9 @@ get_portdir() { |
124 |
for x in $(get_all_make_conf); do |
125 |
source "${x}" |
126 |
done |
127 |
- USE="${use_backup}" |
128 |
fi |
129 |
echo "${PORTDIR}" |
130 |
+ ) |
131 |
} # }}} |
132 |
# This won't change while the script is running, so cache it |
133 |
PORTDIR="$(get_portdir)" |
134 |
@@ -691,10 +697,14 @@ PORTDIR="$(get_portdir)" |
135 |
# Outputs list of portage overlays as defined in the PORTDIR_OVERLAY |
136 |
# variable defined in make.conf |
137 |
get_all_overlays() { |
138 |
- use_backup="${USE}" |
139 |
- source "${MAKE_CONF_PATH}" |
140 |
- USE="${use_backup}" |
141 |
- echo ${PORTDIR_OVERLAY} |
142 |
+ # Use a subshell so we don't have to protect the variables in |
143 |
+ # the current scope |
144 |
+ ( |
145 |
+ for x in $(get_all_make_conf); do |
146 |
+ [[ -r "${x}" ]] && source "${x}" |
147 |
+ done |
148 |
+ echo ${PORTDIR_OVERLAY} |
149 |
+ ) |
150 |
} # }}} |
151 |
ALL_PORTDIRS=( "$PORTDIR" $(get_all_overlays) ) |
152 |
|
153 |
@@ -761,8 +771,7 @@ showdesc() { |
154 |
if array_contains "${useflags[*]}" "$1"; then |
155 |
get_flagstatus "${1}" |
156 |
# XXX: Handle overlay |
157 |
- grep "^${1} *-" ${ALL_PORTDIRS[@]/%//profiles/use.desc} 2> /dev/null \ |
158 |
- | sed -re "s/^([^:]+)://" |
159 |
+ grep -h "^${1} *-" ${ALL_PORTDIRS[@]/%//profiles/use.desc} 2> /dev/null |
160 |
foundone=1 |
161 |
fi |
162 |
fi |
163 |
@@ -773,14 +782,14 @@ showdesc() { |
164 |
foundone=1 |
165 |
fi |
166 |
# Fetch all the packages data using this flag |
167 |
- infos=$( grep ":${1} *-" ${ALL_PORTDIRS[@]/%//profiles/use.local.desc} 2> /dev/null \ |
168 |
- | sed -re "s/^([^:]+):([^:]+):(${1}) *- *(.+)/\1|\2|\3|\4/g") |
169 |
+ infos=$( grep -h ":${1} *-" ${ALL_PORTDIRS[@]/%//profiles/use.local.desc} 2> /dev/null \ |
170 |
+ | sed -re "s/^([^:]+):(${1}) *- *(.+)/\1|\2|\3/g") |
171 |
OIFS=$IFS; IFS=$'\n'; infos=($infos); IFS=$OIFS; |
172 |
for line in "${infos[@]}"; do |
173 |
OIFS=$IFS; IFS="|"; line=($line); IFS=$OIFS |
174 |
- pkg=${line[1]} |
175 |
- flag=${line[2]} |
176 |
- desc=${line[3]} |
177 |
+ pkg=${line[0]} |
178 |
+ flag=${line[1]} |
179 |
+ desc=${line[2]} |
180 |
if get_flagstatus "${flag}"; then |
181 |
ACTIVE="+" |
182 |
else |
183 |
@@ -925,18 +934,22 @@ showflags() { |
184 |
|
185 |
# two small helpers to add or remove a flag from a USE string |
186 |
add_flag() { |
187 |
- if [[ -n $(grep " -${1//-/} " <<< " ${ACTIVE_FLAGS[6]} ") ]]; then |
188 |
- error "Use flag \"${1//-/}\" is masked and should not be added" \ |
189 |
+ # Remove leading '-' from flag if found |
190 |
+ local flag=$1 |
191 |
+ [[ ${flag:0:1} == "-" ]] && flag=${1:1} |
192 |
+ |
193 |
+ if [[ -n $(grep " -${flag} " <<< " ${ACTIVE_FLAGS[6]} ") ]]; then |
194 |
+ error "Use flag \"${flag}\" is masked and should not be added" \ |
195 |
"to make.conf." |
196 |
return 1 |
197 |
# Bug #104396 -- Only add use flags defined in use.desc and use.local.desc |
198 |
- elif [[ -z $(grep "^${1//-/}$" <<< "$(get_useflaglist)") ]]; then |
199 |
- error "Use flag \"${1//-/}\" is not defined in use.desc and should" \ |
200 |
+ elif [[ -z $(grep "^${flag}$" <<< "$(get_useflaglist)") ]]; then |
201 |
+ error "Use flag \"${flag}\" is not defined in use.desc and should" \ |
202 |
"not be added\nto make.conf." |
203 |
return 1 |
204 |
else |
205 |
NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE} ${1}" |
206 |
- echo "Adding flag \"${1}\" to make.conf" >&2 |
207 |
+ echo "Adding flag \"${1}\" to make.conf" >&2 |
208 |
fi |
209 |
} |
210 |
|
211 |
@@ -981,9 +994,8 @@ scrub_use_flag() { |
212 |
elif [[ -n "${PACKAGE}" ]]; then |
213 |
if [[ -n $(echo "${line}" | grep -Ee "${pkg_re}") ]]; then |
214 |
# If this is the only (remaining) use flag defined |
215 |
- # for this package, then remove the whole line |
216 |
- if [[ -z $(echo "${line}" | \ |
217 |
- grep -Ee "${pkg_re} *-?${flag} *$") ]]; then |
218 |
+ # for this package, then remove the whole line |
219 |
+ if [[ -z $(echo "${line}" | grep -Ee "${pkg_re} *-?${flag} *$") ]]; then |
220 |
# Remove flag from this line |
221 |
echo "${line}" | sed -re "s/ *-?\b${flag}\b//" |
222 |
fi |
223 |
@@ -1231,6 +1243,7 @@ modify() { |
224 |
fi |
225 |
done |
226 |
|
227 |
+ # Bail if there is no need to modify make.conf |
228 |
[[ ${make_conf_modified} == 1 ]] || return |
229 |
# make a backup just in case the user doesn't like the new make.conf |
230 |
cp -p "${MAKE_CONF_PATH}" "${MAKE_CONF_BACKUP_PATH}" |