Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 44219
Collapse All | Expand All

(-)/usr/bin/euse (-2 / +100 lines)
Lines 14-19 Link Here
14
MAKE_GLOBALS_PATH=/etc/make.globals
14
MAKE_GLOBALS_PATH=/etc/make.globals
15
MAKE_PROFILE_PATH=/etc/make.profile
15
MAKE_PROFILE_PATH=/etc/make.profile
16
MAKE_CONF_BACKUP_PATH=/etc/make.conf.euse_backup
16
MAKE_CONF_BACKUP_PATH=/etc/make.conf.euse_backup
17
PACKAGE_USE_PATH=/etc/portage/package.use
18
PACKAGE_USE_BACKUP_PATH=/etc/portage/package.use.euse_backup
17
19
18
[ -z "${MODE}" ] && MODE="showhelp"		# available operation modes: showhelp, showversion, showdesc, showflags, modify
20
[ -z "${MODE}" ] && MODE="showhelp"		# available operation modes: showhelp, showversion, showdesc, showflags, modify
19
21
Lines 38-43 Link Here
38
				echo
40
				echo
39
				MODE="showhelp"
41
				MODE="showhelp"
40
				;;
42
				;;
43
			*/*|[\>\<=\~]*)
44
				# try to normalize package specifiers, and resolve short names
45
				local comp="${1%%[^<>=~]*}"
46
				local pkg="${1:${#comp}}"
47
				pkg="${pkg#/}"
48
				if [ "${pkg#*/}" = "${pkg}" ]; then
49
					local cat="`equery which "${pkg%%-[0-9]*}"`"
50
					cat="${cat%/*/*}"
51
					cat="${cat##*/}"
52
					pkg="$cat/$pkg"
53
				fi
54
				PACKAGES="$PACKAGES $comp$pkg"
55
				;;
56
41
			"%active")
57
			"%active")
42
				get_useflags
58
				get_useflags
43
				ARGUMENTS="${ARGUMENTS} ${ACTIVE_FLAGS[9]}"
59
				ARGUMENTS="${ARGUMENTS} ${ACTIVE_FLAGS[9]}"
Lines 71-76 Link Here
71
	
87
	
72
	descdir="$(get_portdir)/profiles"
88
	descdir="$(get_portdir)/profiles"
73
	
89
	
90
	if [ -n "$PACKAGES" ]; then
91
		[ ! -f "${PACKAGE_USE_PATH}" ] && { touch "${PACKAGE_USE_PATH}" || error "Could not create \"${PACKAGE_USE_PATH}\""; }
92
		[ ! -w "${PACKAGE_USE_PATH}" ] && error "${PACKAGE_USE_PATH} is not writable"
93
	fi
74
	[ ! -r "${MAKE_CONF_PATH}" ] && error "${MAKE_CONF_PATH} is not readable"
94
	[ ! -r "${MAKE_CONF_PATH}" ] && error "${MAKE_CONF_PATH} is not readable"
75
	[ ! -r "${MAKE_GLOBALS_PATH}" ] && error "${MAKE_GLOBALS_PATH} is not readable"
95
	[ ! -r "${MAKE_GLOBALS_PATH}" ] && error "${MAKE_GLOBALS_PATH} is not readable"
76
	[ ! -h "${MAKE_PROFILE_PATH}" ] && error "${MAKE_PROFILE_PATH} is not a symlink"
96
	[ ! -h "${MAKE_PROFILE_PATH}" ] && error "${MAKE_PROFILE_PATH} is not a symlink"
Lines 89-95 Link Here
89
cat << HELP
109
cat << HELP
90
${PROGRAM_NAME} v${PROGRAM_VERSION}
110
${PROGRAM_NAME} v${PROGRAM_VERSION}
91
111
92
Syntax: ${PROGRAM_NAME} <option> [suboptions] [useflaglist]
112
Syntax: ${PROGRAM_NAME} <option> [suboptions] [/short package name | full package specifier ...] [use flag ...]
93
113
94
Options: -h, --help           - show this message
114
Options: -h, --help           - show this message
95
         -v, --version        - show version information
115
         -v, --version        - show version information
Lines 106-113 Link Here
106
126
107
Notes: ${PROGRAM_NAME} currently only works for global flags defined
127
Notes: ${PROGRAM_NAME} currently only works for global flags defined
108
       in make.globals, make.defaults or make.conf, it doesn't handle
128
       in make.globals, make.defaults or make.conf, it doesn't handle
109
       use.defaults, use.mask or package.use yet (see portage(5) for details on
129
       use.defaults or use.mask yet (see portage(5) for details on
110
       these files). It also might have issues with cascaded profiles.
130
       these files). It also might have issues with cascaded profiles.
131
       If package name(s) are given, use flags for these packages are
132
       set. The usual package version specifiers are understood as well.
111
       If multiple options are specified only the last one will be used.
133
       If multiple options are specified only the last one will be used.
112
HELP
134
HELP
113
}
135
}
Lines 181-186 Link Here
181
	USE_FLAGS_CALCULATED=1
203
	USE_FLAGS_CALCULATED=1
182
}
204
}
183
205
206
# read package.use and join all matching entries
207
get_package_useflags() {
208
	local spec flags result
209
	while read spec flags; do
210
		[ "$spec" = "$1" ] && result="$result $flags"
211
	done < "${PACKAGE_USE_PATH}"
212
	echo "$(reduce_incrementals ${result})"
213
}
214
184
# get the list of all known USE flags by reading use.desc and/or use.local.desc
215
# get the list of all known USE flags by reading use.desc and/or use.local.desc
185
# (depending on the value of $SCOPE)
216
# (depending on the value of $SCOPE)
186
get_useflaglist() {
217
get_useflaglist() {
Lines 447-452 Link Here
447
# USE flag modification function. Mainly a loop with calls to add_flag and 
478
# USE flag modification function. Mainly a loop with calls to add_flag and 
448
# remove_flag to create a new USE string which is then inserted into make.conf.
479
# remove_flag to create a new USE string which is then inserted into make.conf.
449
modify() {
480
modify() {
481
	if [ -n "$PACKAGES" ]; then
482
		modify_packages "$@"
483
		return
484
	fi
485
450
	if [ -z "${*}" ]; then
486
	if [ -z "${*}" ]; then
451
		if [ "${ACTION}" != "prune" ]; then
487
		if [ "${ACTION}" != "prune" ]; then
452
			echo "WARNING: no USE flags listed for modification, do you really"
488
			echo "WARNING: no USE flags listed for modification, do you really"
Lines 537-542 Link Here
537
	echo "${MAKE_CONF_PATH} was modified, a backup copy has been placed at ${MAKE_CONF_BACKUP_PATH}"
573
	echo "${MAKE_CONF_PATH} was modified, a backup copy has been placed at ${MAKE_CONF_BACKUP_PATH}"
538
}
574
}
539
575
576
# USE flag modification function for package.use. Mainly a loop with calls to add_flag and 
577
# remove_flag to create a new USE string which is then inserted into make.conf.
578
modify_packages() {
579
	local pkg args result
580
	cp -p "${PACKAGE_USE_PATH}" "${PACKAGE_USE_BACKUP_PATH}"
581
	args=("$@")
582
	for pkg in ${PACKAGES}; do
583
		if [ -z "${*}" ]; then
584
			# Use emerge to find use flags and their current setting. Use a phony root to speed up operation (drastically, in some situations).
585
			result="`ROOT=/tmp/euse emerge --quiet --pretend --nodeps --verbose "$1"`"
586
			result="${result#*  USE=}"
587
			set -- ${result//[\(\)\"+-]/}
588
		else
589
			set -- "${args[@]}"
590
		fi
591
		
592
		NEW_MAKE_CONF_USE=" $(get_package_useflags "$pkg") "
593
594
		while [ -n "${1}" ]; do
595
			if [ "${ACTION}" == "add" ]; then
596
				case " $NEW_MAKE_CONF_USE " in
597
				*" ${1} "*) shift;;
598
				*" -${1} "*) remove_flag "-${1}";;
599
				*) add_flag "${1}";;
600
				esac
601
			elif [ "${ACTION}" == "remove" ]; then
602
				case " $NEW_MAKE_CONF_USE " in
603
				*" -${1} "*) shift;;
604
				*" ${1} "*) remove_flag "${1}";;
605
				*) add_flag "-${1}";;
606
				esac
607
			elif [ "${ACTION}" == "prune" ]; then
608
				remove_flag "${1}"
609
				remove_flag "-${1}"
610
				shift
611
			fi
612
		done
613
614
		NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE#  }"
615
		NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE# }"
616
		NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE%  }"
617
		NEW_MAKE_CONF_USE="${NEW_MAKE_CONF_USE% }"
618
		{ # update in-place magic, backup has been made already
619
			rm -f "${PACKAGE_USE_PATH}"
620
			local line done
621
			{
622
				while read line; do
623
					if [ "${line%%[ 	]*}" == "$pkg" ]; then
624
						[ -z "$done" -a -n "$NEW_MAKE_CONF_USE" ] && echo "$pkg	$NEW_MAKE_CONF_USE"
625
						done=1
626
					else
627
						echo "$line"
628
					fi
629
				done
630
				[ -z "$done" -a -n "$NEW_MAKE_CONF_USE" ] && echo "$pkg	$NEW_MAKE_CONF_USE"
631
			} > "${PACKAGE_USE_PATH}"
632
		} < "${PACKAGE_USE_PATH}"
633
	done
634
635
	echo "${PACKAGE_USE_PATH} was modified, a backup copy has been placed at ${PACKAGE_USE_BACKUP_PATH}"
636
}
637
540
##### main program comes now #####
638
##### main program comes now #####
541
639
542
# disable globbing as it fucks up with args=*
640
# disable globbing as it fucks up with args=*

Return to bug 44219