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
This commit is contained in:
osm0sis committed 2021-01-28 17:31:33 -04:00
1 parent d1fd1eb013
commit 8df26b0389
2 files changed
+16 -8

No files matched your search

+1 -1
View File
@@ -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;
+15 -7
View File
@@ -15,7 +15,7 @@ split_img=$home/split_img;
# ui_print "<text>" [...]
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 <file> <line replace string> <replacement line>
# replace_line <file> <line replace string> <replacement line> <scope>
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 <file> <line match string>
# remove_line <file> <line match string> <scope>
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;
}