From 8decdd4624c7bcb82ce72a516d1c9e97aabe7c32 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Sun, 15 Oct 2017 17:32:43 -0700 Subject: [PATCH] AK2: Allow users to use either "" or " " for empty strings Either one is now valid: patch_fstab fstab.qcom /system ext4 options "discard" " " patch_fstab fstab.qcom /system ext4 options "discard" "" Signed-off-by: Nathan Chancellor --- tools/ak2-core.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/ak2-core.sh b/tools/ak2-core.sh index b18353a..418c8fe 100755 --- a/tools/ak2-core.sh +++ b/tools/ak2-core.sh @@ -261,7 +261,7 @@ replace_section() { begin=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; for end in `grep -n "$3" $1 | cut -d: -f1`; do if [ "$begin" -lt "$end" ]; then - if [ "$3" == " " ]; then + if [ "$3" == " " -o -z "$3" ]; then sed -i "/${2//\//\\/}/,/^\s*$/d" $1; else sed -i "/${2//\//\\/}/,/${3//\//\\/}/d" $1; @@ -277,7 +277,7 @@ remove_section() { begin=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; for end in `grep -n "$3" $1 | cut -d: -f1`; do if [ "$begin" -lt "$end" ]; then - if [ "$3" == " " ]; then + if [ "$3" == " " -o -z "$3" ]; then sed -i "/${2//\//\\/}/,/^\s*$/d" $1; else sed -i "/${2//\//\\/}/,/${3//\//\\/}/d" $1; @@ -357,7 +357,7 @@ replace_file() { # patch_fstab patch_fstab() { entry=$(grep "$2" $1 | grep "$3"); - if [ -z "$(echo "$entry" | grep "$6")" ] || [ -z $6 ]; then + if [ -z "$(echo "$entry" | grep "$6")" -o "$6" == " " -o -z "$6" ]; then case $4 in block) part=$(echo "$entry" | awk '{ print $1 }');; mount) part=$(echo "$entry" | awk '{ print $2 }');; @@ -365,7 +365,7 @@ patch_fstab() { options) part=$(echo "$entry" | awk '{ print $4 }');; flags) part=$(echo "$entry" | awk '{ print $5 }');; esac; - newpart=$(echo "$part" | sed -e "s;${5};${6};" -e 's;,\{2,\};,;g' -e 's;,*$;;g' -e 's;^,;;g'); + newpart=$(echo "$part" | sed -e "s;${5};${6};" -e "s; ;;g" -e 's;,\{2,\};,;g' -e 's;,*$;;g' -e 's;^,;;g'); newentry=$(echo "$entry" | sed "s;${part};${newpart};"); sed -i "s;${entry};${newentry};" $1; fi;