apt_get_digested() {
prefixed_msg_init 'apt_get_digested'
-
abort_if_command_unknown calc
-_FINISH_LINE='apt_get_digested_FINISH_LINE'
_SEDS=\
'|\(Reading database \.\.\. .*|IGNORE
|Generation complete.|IGNORE
dpkg warns: unable to delete old directories (not empty):|dpkg: warning: unable to delete old directory '"'"'([[:print:]]+)'"'"': Directory not empty|\1
update-alternatives: providing in auto mode:|update-alternatives: using ([[:print:]]+) to provide ([[:print:]]+) \(([[:print:]]+)\) in auto mode| [\1 → \2 (\3)]'
+_FINISH_LINE='apt_get_digested_FINISH_LINE'
_LAST_PREFIX=''
_STARTED_PRINTING=
+print_cr_and_if_started_printing_nl() {
+ printf '\r'
+ if [ ! -z "${_STARTED_PRINTING}" ]; then
+ printf '\n'
+ fi
+}
eval "DEBIAN_FRONTEND=noninteractive apt-get -y $1; echo ${_FINISH_LINE}" 2>&1 | while read _LINE; do
_LINE=$(printf '%s' "${_LINE}" | tr -d '\r')
if [ -z "${_LINE}" ]; then
continue
elif [ "${_LINE}" = "${_FINISH_LINE}" ]; then
- test ! -z "${_STARTED_PRINTING}" && printf '\n'
- printf '\r'
+ print_cr_and_if_started_printing_nl()
break
fi
_COMPRESSED_ITEM=''
if [ "${_COMPRESSED_ITEM}" = "IGNORE" ]; then
continue
elif [ -z "${_COMPRESSED_ITEM}" ]; then
- test ! -z "${_STARTED_PRINTING}" && printf '\n'
- printf '\r%s' "${_LINE}"
+ print_cr_and_if_started_printing_nl()
+ printf '%s' "${_LINE}"
_LAST_PREFIX=''
else
if [ "${_PREFIX}" != "${_LAST_PREFIX}" ]; then
- test ! -z "${_STARTED_PRINTING}" && printf '\n'
- printf '\r'
+ print_cr_and_if_started_printing_nl()
prefixed_msg_no_nl "${_PREFIX}"
_LAST_PREFIX="${_PREFIX}"
fi