home · contact · privacy
Fix. master
authorChristian Heller <c.heller@plomlompom.de>
Wed, 30 Apr 2025 21:49:04 +0000 (23:49 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 30 Apr 2025 21:49:04 +0000 (23:49 +0200)
bookworm/scripts/lib/apt_get_edited

index de1d7b26190b72c1f9d3d732dd7c5d74cd32f8a4..839e82d8ef01a5c23022f06ba8d9d8de82c15fa6 100644 (file)
@@ -3,80 +3,58 @@
 apt_get_edited() {
 abort_if_command_unknown calc
 
-_TO_IGNORE=\
-'(Reading database ...
-Preparing to unpack
-Unpacking '
-
-_PREFIXES=\
-'9 5 0 Get:
-5 2-3 0 Get:
-6 2-4 0 Get:
-7 2-3 0 Get:
-4 2-3 0 Hit:
-8 7 0 Installing new version of config file
-6 4 0 Processing triggers for
-7 5 0 Purging configuration files for
-5 4 0 Removing obsolete conffile
-4 2 0 Removing
-5 5 1 Selecting previously unselected package
-5 3 0 Setting up
-11 8 1 dpkg: warning: unable to delete old directory
-5 3-5 1 Created symlink'
+_SEDS=\
+'|\(Reading database \.\.\. .*|IGNORE
+|Generation complete.|IGNORE
+|Preconfiguring packages \.\.\.|IGNORE
+|Preparing to unpack [[:print:]]+ \.\.\.|IGNORE
+|Unpacking [[:print:]]+ \([[:print:]]+\)( over \([[:print:]]+\))? \.\.\.|IGNORE
+Adding diversion(s):|Adding '"'"'diversion of ([[:print:]]+) to ([[:print:]]+) by ([[:print:]]+)'"'"'| \3:[\1 → \2]
+Created symlink(s):|Created symlink '"'"'([[:print:]]+)'"'"' → '"'"'([[:print:]]+)'"'"'\.| [\1 → \2]
+Dependencies:|([[:print:]]+) depends on ([[:print:]]+)( \([>=]+ [[:print:]]+\))?\.|[\2 → \1]
+Installing new version of config file(s):|Installing new version of config file ([[:print:]]+) \.\.\.|\1
+Processing triggers for:|Processing triggers for ([[:print:]]+) \([[:print:]]+\) \.\.\.|\1
+Purging configuration files:|Purging configuration files for ([[:print:]]+) \([[:print:]]+\) \.\.\.|\1
+Removing:|Removing ([[:print:]]+) \([[:print:]]+\) \.\.\.|\1
+Removing diversion(s):|Removing '"'"'diversion of ([[:print:]]+) to ([[:print:]]+) by ([[:print:]]+)| \3:[\1 → \2]
+Removing obsolete conffile(s):|Removing obsolete conffile ([[:print:]]+) \.\.\.|\1
+Selecting previously unselected: |Selecting previously unselected package ([[:print:]]+)\.|\1
+Setting up:|Setting up ([[:print:]]+) \([[:print:]]+\) \.\.\.|\1
+Updating to current default:|Updating ([[:print:]]+) to current default.|\1
+disabled or static unit, so not starting:|([[:print:]]+) is a disabled or a static unit, not starting it\.|\1
+disabled or static unit not running, so not starting:|([[:print:]]+) is a disabled or a static unit not running, not starting it\.|\1
+dpkg warning: 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)]'
 
 _LAST_PREFIX=''
 DEBIAN_FRONTEND=noninteractive apt-get -y $1 2>&1 | while read _LINE; do
-    _DO_CONTINUE=
-    for _PLACEHOLDED in $(echo "${_TO_IGNORE}" | sed 's/  */#WHITESPACE_PLACEHOLDER#/g'); do
-        _WHITESPACED=$(echo "${_PLACEHOLDED}" | sed 's/#WHITESPACE_PLACEHOLDER#/ /g')
-        _LEN=$(echo -n "${_WHITESPACED}" | wc -c)
-        _TO_CMP=$(echo "${_LINE}" | cut -c "-${_LEN}")
-        if [ "${_TO_CMP}" = "${_WHITESPACED}" ]; then
-            _DO_CONTINUE=1
-       break
-        fi
-    done
-    if [ 1 = "${_DO_CONTINUE}" ]; then 
+    _LINE=$(printf '%s' "${_LINE}" | tr -d '\r')
+    if [ -z "${_LINE}" ]; then
         continue
     fi
-    _ITEM=''
-    for _PLACEHOLDED in $(echo "${_PREFIXES}" | sed 's/  */#WHITESPACE_PLACEHOLDER#/g'); do
-        _WHITESPACED=$(echo "${_PLACEHOLDED}" | sed 's/#WHITESPACE_PLACEHOLDER#/ /g')
-        _N_WORDS=$(echo "${_WHITESPACED}" | cut -d' ' -f1)
-        _TO_CMP=$(echo "${_LINE}" | wc -w)
-        if [ ! "${_N_WORDS}" -eq "${_TO_CMP}" ]; then
-            continue
-        fi
-        _PREFIX=$(echo "${_WHITESPACED}" | cut -d' ' -f4-)
-        _LEN_PREFIX=$(echo -n "${_PREFIX}" | wc -c)
-        _TO_CMP=$(echo "${_LINE}" | cut -c "-${_LEN_PREFIX}")
-        if [ "${_TO_CMP}" != "${_PREFIX}" ]; then
-            continue
-        elif [ "${_LAST_PREFIX}" != "${_PREFIX}" ]; then
-            if [ ! -z "${_LAST_PREFIX}" ]; then
-                echo ''
-            fi
-            echo -n "\r# ${_PREFIX}"
+    _COMPRESSED_ITEM=''
+    for _SED in $(printf '%s' "${_SEDS}" | sed 's/ /#WHITESPACE#/g'); do
+        _WHITESPACED=$(printf '%s' "${_SED}" | sed 's/#WHITESPACE#/ /g')
+        _PREFIX=$(printf '%s' "${_WHITESPACED}" | cut -d'|' -f1)
+        _PATTERN=$(printf '^%s$' "${_WHITESPACED}" | cut -d'|' -f2)
+        _REPLACEMENT=$(printf '%s' "${_WHITESPACED}" | cut -d'|' -f3)
+        if printf '%s' "${_LINE}" | grep -E "${_PATTERN}" > /dev/null; then
+            _COMPRESSED_ITEM=$(printf '%s' "${_LINE}" | sed -E "s|${_PATTERN}|${_REPLACEMENT}|")
+            break
         fi
-        _IDX_ITEM=$(echo "${_WHITESPACED}" | cut -d' ' -f2)
-        _CUTOFF=$(echo "${_WHITESPACED}" | cut -d' ' -f3)
-        _ITEM=$(echo "${_LINE}" | cut -d' ' "-f${_IDX_ITEM}")
-        if [ "${_CUTOFF}" -gt 0 ]; then
-            _LEN_ITEM=$(echo -n "${_ITEM}" | wc -c)
-            _LEN_ITEM_CUT=$(calc "${_LEN_ITEM} - ${_CUTOFF} - 1" | tr -d '\t')
-            _ITEM=$(echo "${_ITEM}" | cut -c "-${_LEN_ITEM_CUT}")
-        fi
-        echo -n " ${_ITEM}"
-        _LAST_PREFIX="${_PREFIX}"
-        break
     done
-    if [ -z "${_ITEM}" ]; then
-        if [ ! -z "${_LAST_PREFIX}" ]; then
-            echo ''
-        fi
-        echo "\r${_LINE}"
+    if [ "${_COMPRESSED_ITEM}" = "IGNORE" ]; then
+        continue
+    elif [ -z "${_COMPRESSED_ITEM}" ]; then
         _LAST_PREFIX=''
+        printf '\n\r%s' "${_LINE}"
+    else
+        if [ "${_PREFIX}" != "${_LAST_PREFIX}" ]; then
+            printf '\n\r# %s' "${_PREFIX}"
+            _LAST_PREFIX="${_PREFIX}"
+        fi
+        printf ' %s' "${_COMPRESSED_ITEM}"
     fi
 done
-echo ''
+printf '\r\n\n'
 }