Skip to content

Commit

Permalink
Fix apt line wrapping if output is not a tty
Browse files Browse the repository at this point in the history
With Bash, we can leave stdout to the tty.
  • Loading branch information
grass committed Jul 24, 2023
1 parent 1c5ff08 commit 0e6718c
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions usr/bin/installer-dist
Expand Up @@ -2838,13 +2838,38 @@ parse_opt(){
}


## Bash supports process substitution and saving xtrace to a file, which is a
## simpler way to log to file and console.
log_term_and_file_bash(){
exec > >(tee -a "${log_file_user}") 2> >(tee -a "${log_file_debug}" >&2) &
## Bash has built-in feature to redirect xtrace to the specified file.
# shellcheck disable=SC2039
true "exec 9>>${log_file_debug}"
exec 9>>"${log_file_debug}"
export BASH_XTRACEFD=9
set -o xtrace
xtrace=1
touch "${log_file_debug}"
}


## Logging mechanism.
log_term_and_file(){
## Discover if terminal is attached to stdout
if ! test -t 1; then
log warn "Output is not being sent to the terminal because terminal is not connected to stdout."
return 0
fi

if test "${curr_shell}" = "bash"; then
log_term_and_file_bash
return 0
fi

## Portable log and console redirection that has the downside of some
## applications doing horrible line wrappings (apt >=2.6.1) if the output is
## not a tty.

## Send fd3 to the terminal
true "exec 3>$(tty)"
exec 3>>"$(tty)"
Expand All @@ -2862,16 +2887,6 @@ log_term_and_file(){
true "exec 2>/dev/null"
exec 2>/dev/null
fi
## Bash has built-in feature to redirect xtrace to the specified file.
if test "${curr_shell}" = "bash"; then
# shellcheck disable=SC2039
true "exec 9>>${log_file_debug}"
exec 9>>"${log_file_debug}"
export BASH_XTRACEFD=9
set -o xtrace
xtrace=1
touch "${log_file_debug}"
fi
## Copy output of log file to fd3 and send process to the background.
if test -f "${log_file_debug}" && test "${log_level}" = "debug"; then
true "tail -qf ${log_file_debug} ${log_file_user} >&3 &"
Expand Down

0 comments on commit 0e6718c

Please sign in to comment.