|
|
# Use the color preference from portage | # Use the color preference from portage |
NOCOLOR=$(portageq envvar NOCOLOR) | NOCOLOR=$(portageq envvar NOCOLOR) |
| |
# Find a place to put temporary files |
set_trap() { |
# 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/}) |
cat <<- EOF | cat <<- EOF |
|
|
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" |
| |