From 8df26b03894984a9273f82fc1247fd42cc4686c8 Mon Sep 17 00:00:00 2001 From: osm0sis Date: Thu, 28 Jan 2021 17:28:31 -0400 Subject: [PATCH] AK3+Backend: cleanups, update *_line functions - touch up a couple pesky minor things - add global scope to replace_line and remove_line so they match replace_string, and can now work on all matches found in a file --- META-INF/com/google/android/update-binary | 2 +- tools/ak3-core.sh | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index eb31870..0854f40 100755 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -90,7 +90,7 @@ umount_apex() { local dest loop; for dest in $($BB find /apex -type d -mindepth 1 -maxdepth 1); do if [ -f $dest.img ]; then - loop=$($BB mount | $BB grep $dest | $BB cut -d" " -f1); + loop=$($BB mount | $BB grep $dest | $BB cut -d\ -f1); fi; ($BB umount -l $dest; $BB losetup -d $loop) 2>/dev/null; diff --git a/tools/ak3-core.sh b/tools/ak3-core.sh index bae514a..42f0928 100755 --- a/tools/ak3-core.sh +++ b/tools/ak3-core.sh @@ -15,7 +15,7 @@ split_img=$home/split_img; # ui_print "" [...] ui_print() { until [ ! "$1" ]; do - echo -e "ui_print $1 + echo "ui_print $1 ui_print" >> /proc/self/fd/$OUTFD; shift; done; @@ -520,19 +520,27 @@ insert_line() { fi; } -# replace_line +# replace_line replace_line() { + local lines line; if grep -q "$2" $1; then - local line=$(grep -n "$2" $1 | head -n1 | cut -d: -f1); - sed -i "${line}s;.*;${3};" $1; + lines=$(grep -n "$2" $1 | cut -d: -f1 | sort -nr); + [ "$4" == "global" ] || lines=$(echo "$lines" | tail -n1); + for line in $lines; do + sed -i "${line}s;.*;${3};" $1; + done; fi; } -# remove_line +# remove_line remove_line() { + local lines line; if grep -q "$2" $1; then - local line=$(grep -n "$2" $1 | head -n1 | cut -d: -f1); - sed -i "${line}d" $1; + lines=$(grep -n "$2" $1 | cut -d: -f1 | sort -nr); + [ "$3" == "global" ] || lines=$(echo "$lines" | tail -n1); + for line in $lines; do + sed -i "${line}d" $1; + done; fi; }