--- revdep-rebuild.orig 2007-07-19 10:37:38.000000000 -0400 +++ revdep-rebuild 2007-07-19 13:45:13.000000000 -0400 @@ -30,7 +30,6 @@ sleep 2 # End pre-release disclaimer to stderr -source /etc/init.d/functions.sh # TODO: # - Use more /etc/init.d/functions.sh @@ -141,7 +140,7 @@ # Replace whitespace with linebreaks, normalize repeated '/' chars, and sort -u # (If any libs have whitespace in their filenames, someone needs punishment.) clean_var() { - local a=$(echo ${@%%-\**}) # Deliberately unquoted + local a=$(echo ${@%%[[:space:]]-\*[[:space:]]*}) # Deliberately unquoted # A benchmark shows this loop is faster than piping to sed, # as long as there aren't more than a handful of '/' chars. while [[ $a = *//* ]]; do a="${a//\/\///}"; done @@ -208,8 +207,7 @@ avoid_utils="$1" ;; -nc|-C|--no-color|--nocolor) - # TODO: Does this variable do anything now that the main color functions are removed? - export NOCOLOR=1 + export NOCOLOR=yes ;; -l|-np|--no-ld-path) unset FULL_LD_PATH @@ -248,8 +246,10 @@ sed 's:/var/db/pkg/\(.*\)/CONTENTS:\1:' } fi + # Normalize some EMERGE_OPTIONS EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-p/--pretend}) EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-f/--fetchonly}) + EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-f/--verbose}) if [[ ${EMERGE_OPTIONS[@]} != *--pretend* && $UID -ne 0 ]]; then ewarn "You are not superuser. Adding --pretend to emerge options." EMERGE_OPTIONS+=(--pretend) @@ -260,6 +260,10 @@ ]] get_args "$@" +# 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 einfo "Configuring search environment for $appname" @@ -314,32 +318,25 @@ SEARCH_DIRS_MASK=$(clean_var "$SEARCH_DIRS_MASK") LD_LIBRARY_MASK=$(clean_var "$LD_LIBRARY_MASK") -# Use the color preference from portage -NOCOLOR=$(portageq envvar NOCOLOR) - -# Find a place to put temporary files -# TODO; let the user choose where to put tempfiles -# gfind $HOME/ /var/tmp/ /tmp/ -writable -print -quit -# TODO: This is a rather noisy, but portable way to implement -quit -LIST=$( - find $HOME/ /var/tmp/ /tmp/ -writable | while read LIST; do - echo "$LIST.$appname" - break - done -) -if [[ $LIST = .$appname ]]; then - die 1 "!!! Unable to find a satisfactory location for temporary files !!!" -fi -[[ $remove_old_tempfiles ]] && rm -f $LIST.* - -function set_trap () { +set_trap() { trap "rm_temp $1" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM } -function rm_temp () { +rm_temp() { rm $1 die 1 $' ...terminated. Removing incomplete '"$1." } get_search_env() { + # Find a place to put temporary files + # TODO; let the user choose where to put tempfiles + # gfind $HOME/ /var/tmp/ /tmp/ -writable -print -quit + # HACK: This is a rather noisy, but portable way to implement -quit + while read LIST; do + break # Set LIST + done < <(find $HOME/ /var/tmp/ /tmp/ -writable) + [[ $LIST ]] || + die 1 "Unable to find a satisfactory location for temporary files" + + LIST+=".$appname" if [[ $SEARCH_BROKEN ]]; then SONAME_SEARCH="$SONAME" HEAD_TEXT="broken by a package update" @@ -364,21 +361,21 @@ unset WORKING_TEXT fi - [[ $LIST ]] || die 1 $LIST IS NOT DEFINED - # If any of our temporary files are older than 1 day, remove them all - [[ ! $keep_tempfiles && -r $LIST && - $( - find -L "$LIST" -type f -mmin +1440 -print | - while read; do echo 1; break; done - ) ]] && rm -f $LIST.* + if [[ ! $keep_tempfiles ]]; then + while read; do + remove_old_tempfiles=1 + break + done < <(find -L "$LIST."* -maxdepth 0 -type f -mmin +1440 -print) + fi # Compare old and new environments # Don't use our previous files if environment doesn't match new_env=$( - # We don't care if these options change + # We don't care if these emerge options change EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]//--pretend/}) EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]//--fetchonly/}) + EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]//--verbose/}) cat <<- EOF SEARCH_DIRS="$SEARCH_DIRS" SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK" @@ -393,13 +390,16 @@ old_env=$(<"$LIST.0_env") if [[ $old_env != $new_env ]]; then ewarn 'Environment mismatch from previous run, deleting temporary files...' - rm -f "$LIST"* + remove_old_tempfiles=1 fi else # No 0_env file found, silently delete any other tempfiles that may exist - rm -f "$LIST"* + remove_old_tempfiles=1 fi + # If we should remove old tempfiles, do so + [[ $remove_old_tempfiles ]] && rm -f "$LIST."* + # Save the environment in a file for next time echo "$new_env" > "$LIST.0_env"