|
|
sleep 2 | sleep 2 |
# End pre-release disclaimer to stderr | # End pre-release disclaimer to stderr |
| |
source /etc/init.d/functions.sh |
|
# TODO: | # TODO: |
# - Use more /etc/init.d/functions.sh | # - Use more /etc/init.d/functions.sh |
| |
|
|
# Replace whitespace with linebreaks, normalize repeated '/' chars, and sort -u | # Replace whitespace with linebreaks, normalize repeated '/' chars, and sort -u |
# (If any libs have whitespace in their filenames, someone needs punishment.) | # (If any libs have whitespace in their filenames, someone needs punishment.) |
clean_var() { | 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, | # A benchmark shows this loop is faster than piping to sed, |
# as long as there aren't more than a handful of '/' chars. | # as long as there aren't more than a handful of '/' chars. |
while [[ $a = *//* ]]; do a="${a//\/\///}"; done | while [[ $a = *//* ]]; do a="${a//\/\///}"; done |
|
|
avoid_utils="$1" | avoid_utils="$1" |
;; | ;; |
-nc|-C|--no-color|--nocolor) | -nc|-C|--no-color|--nocolor) |
# TODO: Does this variable do anything now that the main color functions are removed? |
export NOCOLOR=yes |
export NOCOLOR=1 |
|
;; | ;; |
-l|-np|--no-ld-path) | -l|-np|--no-ld-path) |
unset FULL_LD_PATH | unset FULL_LD_PATH |
|
|
sed 's:/var/db/pkg/\(.*\)/CONTENTS:\1:' | sed 's:/var/db/pkg/\(.*\)/CONTENTS:\1:' |
} | } |
fi | fi |
|
# Normalize some EMERGE_OPTIONS |
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-p/--pretend}) | EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-p/--pretend}) |
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-f/--fetchonly}) | EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-f/--fetchonly}) |
|
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]/%-f/--verbose}) |
if [[ ${EMERGE_OPTIONS[@]} != *--pretend* && $UID -ne 0 ]]; then | if [[ ${EMERGE_OPTIONS[@]} != *--pretend* && $UID -ne 0 ]]; then |
ewarn "You are not superuser. Adding --pretend to emerge options." | ewarn "You are not superuser. Adding --pretend to emerge options." |
EMERGE_OPTIONS+=(--pretend) | EMERGE_OPTIONS+=(--pretend) |
|
|
]] | ]] |
| |
get_args "$@" | 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" | einfo "Configuring search environment for $appname" |
| |
|
|
SEARCH_DIRS_MASK=$(clean_var "$SEARCH_DIRS_MASK") | SEARCH_DIRS_MASK=$(clean_var "$SEARCH_DIRS_MASK") |
LD_LIBRARY_MASK=$(clean_var "$LD_LIBRARY_MASK") | LD_LIBRARY_MASK=$(clean_var "$LD_LIBRARY_MASK") |
| |
# Use the color preference from portage |
set_trap() { |
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 () { |
|
trap "rm_temp $1" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM | trap "rm_temp $1" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM |
} | } |
function rm_temp () { |
rm_temp() { |
rm $1 | rm $1 |
die 1 $' ...terminated. Removing incomplete '"$1." | die 1 $' ...terminated. Removing incomplete '"$1." |
} | } |
get_search_env() { | 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 | if [[ $SEARCH_BROKEN ]]; then |
SONAME_SEARCH="$SONAME" | SONAME_SEARCH="$SONAME" |
HEAD_TEXT="broken by a package update" | HEAD_TEXT="broken by a package update" |
|
|
unset WORKING_TEXT | unset WORKING_TEXT |
fi | fi |
| |
[[ $LIST ]] || die 1 $LIST IS NOT DEFINED |
|
|
|
# If any of our temporary files are older than 1 day, remove them all | # If any of our temporary files are older than 1 day, remove them all |
[[ ! $keep_tempfiles && -r $LIST && |
if [[ ! $keep_tempfiles ]]; then |
$( |
while read; do |
find -L "$LIST" -type f -mmin +1440 -print | |
remove_old_tempfiles=1 |
while read; do echo 1; break; done |
break |
) ]] && rm -f $LIST.* |
done < <(find -L "$LIST."* -maxdepth 0 -type f -mmin +1440 -print) |
|
fi |
| |
# Compare old and new environments | # Compare old and new environments |
# Don't use our previous files if environment doesn't match | # Don't use our previous files if environment doesn't match |
new_env=$( | 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[@]//--pretend/}) |
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]//--fetchonly/}) | EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]//--fetchonly/}) |
|
EMERGE_OPTIONS=(${EMERGE_OPTIONS[@]//--verbose/}) |
cat <<- EOF | cat <<- EOF |
SEARCH_DIRS="$SEARCH_DIRS" | SEARCH_DIRS="$SEARCH_DIRS" |
SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK" | SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK" |
|
|
old_env=$(<"$LIST.0_env") | old_env=$(<"$LIST.0_env") |
if [[ $old_env != $new_env ]]; then | if [[ $old_env != $new_env ]]; then |
ewarn 'Environment mismatch from previous run, deleting temporary files...' | ewarn 'Environment mismatch from previous run, deleting temporary files...' |
rm -f "$LIST"* |
remove_old_tempfiles=1 |
fi | fi |
else | else |
# No 0_env file found, silently delete any other tempfiles that may exist | # No 0_env file found, silently delete any other tempfiles that may exist |
rm -f "$LIST"* |
remove_old_tempfiles=1 |
fi | fi |
| |
|
# If we should remove old tempfiles, do so |
|
[[ $remove_old_tempfiles ]] && rm -f "$LIST."* |
|
|
# Save the environment in a file for next time | # Save the environment in a file for next time |
echo "$new_env" > "$LIST.0_env" | echo "$new_env" > "$LIST.0_env" |
| |