commit:     146de30d358d92a10bab9888898e43735baf4af2
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Tue Mar 26 03:34:40 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Tue Mar 26 05:25:45 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=146de30d

kconfig_set_opt(): add possibility to add new kernel options

Bug: https://bugs.gentoo.org/669412
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 gen_funcs.sh | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/gen_funcs.sh b/gen_funcs.sh
index b105d64..95c8f30 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -570,7 +570,24 @@ function kconfig_set_opt() {
        kconfig="$1"
        optname="$2"
        optval="$3"
-       sed -i "${kconfig}" \
-               -e "s/^#\? \?${optname}[ =].*/${optname}=${optval}/g" \
-       || gen_die "Failed to set ${optname}=${optval} in $kconfig"
+
+       curropt=$(grep -E "^#? ?${optname}[ =].*$" "${kconfig}")
+       if [[ -z "${curropt}" ]]
+       then
+               print_info 2 "$(getIndent 2) - Adding option '${optname}' with 
value '${optval}' to '${kconfig}'..."
+               echo "${optname}=${optval}" >> "${kconfig}" ||
+                       gen_die "Failed to add '${optname}=${optval}' to 
'$kconfig'"
+
+               [ ! -f "${TEMP}/.kconfig_modified" ] && touch 
"${TEMP}/.kconfig_modified"
+       elif [[ "${curropt}" != "*#*" && "${curropt#*=}" == "${optval}" ]]
+       then
+               print_info 2 "$(getIndent 2) - Option '${optname}=${optval}' 
already exists in '${kconfig}'; Skipping..."
+       else
+               print_info 2 "$(getIndent 2) - Setting option '${optname}' to 
'${optval}' in '${kconfig}'..."
+               sed -i "${kconfig}" \
+                       -e "s/^#\? \?${optname}[ =].*/${optname}=${optval}/g" ||
+                               gen_die "Failed to set '${optname}=${optval}' 
in '$kconfig'"
+
+               [ ! -f "${TEMP}/.kconfig_modified" ] && touch 
"${TEMP}/.kconfig_modified"
+       fi
 }

Reply via email to