home · contact · privacy
Fix.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 6 May 2025 03:01:45 +0000 (05:01 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 6 May 2025 03:01:45 +0000 (05:01 +0200)
bookworm/scripts/lib/apt_get_digested

index 67cbccb34ca7bdbdef6199d3469d331d99fe02d7..34ac00f5dbb8fc056250d76b025cff76a6e0080d 100644 (file)
@@ -3,10 +3,8 @@
 
 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
@@ -31,15 +29,21 @@ BECOME_NEXT_PREFIX|dpkg: ([[:print:]]+): dependency problems, but removing anywa
 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=''
@@ -62,13 +66,12 @@ eval "DEBIAN_FRONTEND=noninteractive apt-get -y $1; echo ${_FINISH_LINE}" 2>&1 |
     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