Broken reverse dependency rebuilder.
+ -C, --nocolor Turn off colored output
+ -d, --debug Print way too much information (uses bash's set -xv)
+ -e, --exact Emerge based on exact package version
-h, --help Print this usage
+ -i, --ignore Ignore temporary files from previous runs
-k, --keep-temp Do not delete temporary files on exit
- -e, --exact Emerge based on exact package version
+ -L, --library NAME Emerge existing packages that use the library with NAME
+ --library=NAME NAME can be a full path to the library or a basic
+ regular expression (man grep)
-l, --no-ld-path Do not set LD_LIBRARY_PATH
- -C, --nocolor Turn off colored output
- -i, --ignore Ignore temporary files from previous runs
-o, --no-order Do not check the build order
(Saves time, but may cause breakage.)
+ -p, --pretend Do a trial run without actually emerging anything
+ (also passed to emerge command)
-P, --no-progress Turn off the progress meter
-q, --quiet Be less verbose (also passed to emerge command)
- -v, --verbose Be more verbose
+ -v, --verbose Be more verbose (also passed to emerge command)
-u, --no-util UTIL Do not use features provided by UTIL
--no-util=UTIL UTIL can be one of portage-utils or pkgcore
or it can be a *quoted* space-delimited list.
- -L, --library NAME Emerge existing packages that use the library with NAME
- --library=NAME NAME can be a full path to the library or a basic
- regular expression (man grep)
-Calls emerge, all other options are used for it (e. g. -p, --pretend).
+Calls emerge, options after -- are ignored by $APP_NAME
+and passed directly to emerge.
Report bugs to <http://bugs.gentoo.org>
EOF
echo -e '\a.'
}
# Get the name of a package owning a file on the filesystem using one of several
-# utilities: This is a placeholder. The function is defined in get_args()
+# utilities: This is a placeholder. The function is defined in get_opts()
get_file_owner() { :; }
# Replace whitespace with linebreaks, normalize repeated '/' chars, and sort -u
# (If any libs have whitespace in their filenames, someone needs punishment.)
einfo "$OK_TEXT... All done. "
exit 0
}
-get_args() {
- echo_v() { ewarn "$@"; }
- unset VERBOSE KEEP_TEMP EMERGE_OPTIONS RM_OLD_TEMPFILES
- ORDER_PKGS=1
- PACKAGE_NAMES=1
- SONAME="not found"
- SEARCH_BROKEN=1
- FULL_LD_PATH=1
- local avoid_utils
- while [[ $1 ]]; do
- case $1 in
- -h|--help)
- print_usage
- exit 0
- ;;
- -e|--exact)
- unset PACKAGE_NAMES
- ;;
- -o|--no-order)
- unset ORDER_PKGS
- ;;
- -P|--no-progress)
- progress() { :; }
- ;;
- -q|--quiet)
- echo_v() { :; }
- progress() { :; }
- quiet=1
- EMERGE_OPTIONS+=($1)
- ;;
- -L=*|--library=*|--soname=*|--soname-regexp=*)
- SONAME="${1#*=}"
- unset SEARCH_BROKEN
- ;;
- -L|--library|--soname|--soname-regexp)
- [[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1"
- shift
- SONAME="$1"
- unset SEARCH_BROKEN
- ;;
- -u=*|--no-util=*)
- # TODO: check for invalid values
- avoid_utils="${1#*=}"
- ;;
- -u|--no-util)
- [[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1"
- shift
- avoid_utils="$1"
- ;;
- -nc|-C|--no-color|--nocolor)
- export NOCOLOR=yes
- ;;
- -l|-np|--no-ld-path)
- unset FULL_LD_PATH
- ;;
- -i|--ignore)
- RM_OLD_TEMPFILES=1
- ;;
- -k|--keep-temp)
- KEEP_TEMP=1
- ;;
- -vv|--extra-verbose|-v|--verbose)
- VERBOSE=1
- EMERGE_OPTIONS+=($1)
- ;;
- -X|--package-names)
- # No longer used, since it is the default.
- # We accept it for backwards compatibility
- PACKAGE_NAMES=1
- ;;
- --)
- ;;
- *)
- EMERGE_OPTIONS+=($1)
- ;;
- esac
- shift
- done
- # Check if various utils are allowed and installed
+
+##
+# Check if various portage utils are allowed and installed
+setup_get_file_owner() {
if [[ $avoid_utils != *portage-utils* ]] && hash qfile 2> /dev/null; then
get_file_owner() { qfile -qvC "$@"; }
elif [[ $avoid_utils != *pkgcore* ]] && hash pquery 2> /dev/null; then
sed 's:/var/db/pkg/\(.*\)/CONTENTS:\1:'
}
fi
+}
- # Use the color preference from portage
- export NOCOLOR=$(portageq envvar NOCOLOR)
- [[ $NOCOLOR = yes || $NOCOLOR = true ]] && export RC_NOCOLOR=yes # HACK! (grr)
- source /etc/init.d/functions.sh
-
+##
+# Normalize some EMERGE_OPTIONS
+normalize_emerge_opts() {
# Normalize some EMERGE_OPTIONS
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-p/--pretend})
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-f/--fetchonly})
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-f/--verbose})
+}
+
+##
+# Use the color preference from portage
+setup_color() {
+ # This should still work if NOCOLOR is set by the -C flag or in the user's
+ # environment.
+ export NOCOLOR=$(portageq envvar NOCOLOR)
+ [[ $NOCOLOR = yes || $NOCOLOR = true ]] && export RC_NOCOLOR=yes # HACK! (grr)
+ . /sbin/functions.sh
+}
+
+##
+# Die if an argument is missing.
+die_if_missing_arg() {
+ [[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1"
+}
+
+##
+# Die because an option is not recognized.
+die_invalid_option() {
+ # We cannot use eerror and einfo because this gets called before function.sh
+ # is sourced
+ print_usage
+ echo
+ echo "Encountered unrecognized option $1." >&2
+ echo
+ echo "$APP_NAME no longer automatically passes unrecognized options to portage."
+ echo "Separate emerge-only options from revdep-rebuild options with the -- flag."
+ echo
+ exit 1
+}
+
+##
+# Warn about deprecated options.
+warn_deprecated_opt() {
+ # We cannot use eerror and einfo because this gets called before function.sh
+ # is sourced
+ echo
+ echo "Encountered deprecated option $1." >&2
+ [[ $2 ]] && echo "Please use $2 instead." >&2
+}
+
+##
+# Get whole-word commandline options preceded by two dashes.
+get_longopts() {
+ case $1 in
+ --nocolor) export NOCOLOR="yes";;
+ --no-color) warn_deprecated_opt "$1" "--nocolor"
+ export NOCOLOR="yes";;
+ --debug) set -xv;;
+ --exact) unset PACKAGE_NAMES;;
+ --help) print_usage
+ exit 0;;
+ --ignore) RM_OLD_TEMPFILES=1;;
+ --keep-temp) KEEP_TEMP=1;;
+ --library=*) # TODO: check for invalid values
+ SONAME="${1#*=}"
+ unset SEARCH_BROKEN;;
+ --soname=*|--soname-regexp=*) # TODO: check for invalid values
+ warn_deprecated_opt "${1%=*}" "--library"
+ SONAME="${1#*=}"
+ unset SEARCH_BROKEN;;
+ --library) # TODO: check for invalid values
+ die_if_missing_arg $1 $2
+ shift
+ SONAME="$1"
+ unset SEARCH_BROKEN;;
+ --soname|--soname-regexp) # TODO: check for invalid values
+ warn_deprecated_opt "$1" "--library"
+ die_if_missing_arg $1 $2
+ shift
+ SONAME="$1"
+ unset SEARCH_BROKEN;;
+ --no-ld-path) unset FULL_LD_PATH;;
+ --no-order) unset ORDER_PKGS;;
+ --no-progress) progress() { :; };;
+ --pretend) EMERGE_OPTIONS+=("--pretend");;
+ --quiet) echo_v() { :; }
+ progress() { :; }
+ quiet=1
+ EMERGE_OPTIONS+=($1);;
+ --no-util=*) # TODO: check for invalid values
+ avoid_utils="${1#*=}";;
+ --no-util) # TODO: check for invalid values
+ die_if_missing_arg $1 $2
+ shift
+ avoid_utils="$1";;
+ --verbose) VERBOSE=1
+ EMERGE_OPTIONS+=("--verbose");;
+ --extra-verbose) warn_deprecated_opt "$1" "--verbose"
+ VERBOSE=1
+ EMERGE_OPTIONS+=("--verbose");;
+ --package-names) # No longer used, since it is the
+ # default. We accept it for
+ # backwards compatibility.
+ warn_deprecated_opt "$1"
+ PACKAGE_NAMES=1;;
+ *) die_invalid_option $1;;
+ esac
+}
+
+##
+# Get single-letter commandline options preceded by a single dash.
+get_shortopts() {
+ local OPT OPTSTRING OPTARG OPTIND
+ while getopts ":CdehikL:loPpqu:vX" OPT; do
+ case "$OPT" in
+ C) # TODO: Match syntax with the rest of gentoolkit
+ export NOCOLOR="yes";;
+ d) set -xv;;
+ e) unset PACKAGE_NAMES;;
+ h) print_usage
+ exit 0;;
+ i) RM_OLD_TEMPFILES=1;;
+ k) KEEP_TEMP=1;;
+ L) # TODO: Check for invalid values
+ SONAME="${OPTARG#*=}"
+ unset SEARCH_BROKEN;;
+ l) unset FULL_LD_PATH;;
+ o) unset ORDER_PKGS;;
+ P) progress() { :; };;
+ p) EMERGE_OPTIONS+=("--pretend");;
+ q) echo_v() { :; }
+ progress() { :; }
+ quiet=1
+ EMERGE_OPTIONS+=("--quiet");;
+ u) avoid_utils="$1";; # TODO: Check for invalid values
+ v) VERBOSE=1
+ EMERGE_OPTIONS+=("--verbose");;
+ X) # No longer used, since it is the default.
+ # We accept it for backwards compatibility.
+ warn_deprecated_opt "-X"
+ PACKAGE_NAMES=1;;
+ *) die_invalid_option "-$OPTARG";;
+ esac
+ done
+}
+
+##
+# Get command-line options.
+get_opts() {
+ local avoid_utils
+ local -a args
+ echo_v() { ewarn "$@"; }
+ unset VERBOSE KEEP_TEMP EMERGE_OPTIONS RM_OLD_TEMPFILES
+ ORDER_PKGS=1
+ PACKAGE_NAMES=1
+ SONAME="not found"
+ SEARCH_BROKEN=1
+ FULL_LD_PATH=1
+ while [[ $1 ]]; do
+ case $1 in
+ --) shift
+ EMERGE_OPTIONS+=("$@")
+ break;;
+ -*) while true; do
+ args+=("$1")
+ shift
+ [[ ${1:--} = -* ]] && break
+ done
+ if [[ ${args[0]} = --* ]]; then
+ get_longopts "${args[@]}"
+ else
+ get_shortopts "${args[@]}"
+ fi;;
+ *) die_invalid_option "$1";;
+ esac
+ unset args
+ done
+
+ setup_get_file_owner
+ setup_color
+ normalize_emerge_opts
+
+ # If the user is not super, add --pretend to EMERGE_OPTIONS
if [[ ${EMERGE_OPTIONS[@]} != *--pretend* && $UID -ne 0 ]]; then
ewarn "You are not superuser. Adding --pretend to emerge options."
EMERGE_OPTIONS+=(--pretend)
fi
}
-is_real_merge() [[
- ${EMERGE_OPTIONS[@]} != *--pretend* && ${EMERGE_OPTIONS[@]} != *--fetchonly*
-]]
-get_args "$@"
+is_real_merge() {
+ [[ ${EMERGE_OPTIONS[@]} != *--pretend* &&
+ ${EMERGE_OPTIONS[@]} != *--fetchonly* ]]
+}
+
+get_opts "$@"
einfo "Configuring search environment for $APP_NAME"