V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 50s
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 50s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
@@ -141,11 +141,11 @@ grub_extract_current_string() {
|
||||
#######################################
|
||||
grub_finalize_string() {
|
||||
### Declare Arrays, HashMaps, and Variables.
|
||||
declare -a ary_lines=()
|
||||
declare -a ary_out=()
|
||||
declare var_file="${TARGET}/etc/default/grub"
|
||||
declare var_new_lin="${VK_GRUB_CMDLINE_LINUX}'${VV_GRUB_CMDLINE_LINUX}'"
|
||||
declare var_new_lin_def="${VK_GRUB_CMDLINE_LINUX_DEFAULT}'${VV_GRUB_CMDLINE_LINUX_DEFAULT}'"
|
||||
declare -i var_found_lin=0 var_found_lin_def=0 var_line=0 i=0
|
||||
declare -i var_found_lin=0 var_found_lin_def=0 var_line=0
|
||||
|
||||
# TODO REMOVE DEBUG LOGGER
|
||||
do_log "debug" "file_only" "1081() var_new_lin [${var_new_lin}]."
|
||||
@@ -153,42 +153,38 @@ grub_finalize_string() {
|
||||
do_log "debug" "file_only" "1081() Before [mapfile -t ary_lines < ${var_file}]."
|
||||
# TODO REMOVE DEBUG LOGGER
|
||||
|
||||
mapfile -t ary_lines < "${var_file}"
|
||||
|
||||
### Replace lines strictly based on the key (including '=').
|
||||
for (( i=0; i<${#ary_lines[@]}; i++ )); do
|
||||
|
||||
var_line=${ary_lines[i]}
|
||||
|
||||
# TODO REMOVE DEBUG LOGGER
|
||||
do_log "debug" "file_only" "1081() [Line '${i}': ${var_line}]."
|
||||
# TODO REMOVE DEBUG LOGGER
|
||||
### Read file line by line; robust against missing a final newline.
|
||||
while IFS= read -r var_line || [[ -n "${var_line}" ]]; do
|
||||
|
||||
case "${var_line}" in
|
||||
|
||||
"${VK_GRUB_CMDLINE_LINUX}"*)
|
||||
|
||||
ary_lines[i]="${var_new_lin}"
|
||||
ary_out+=("${var_new_lin}")
|
||||
var_found_lin=1
|
||||
;;
|
||||
|
||||
"${VK_GRUB_CMDLINE_LINUX_DEFAULT}"*)
|
||||
|
||||
ary_lines[i]="${var_new_lin_def}"
|
||||
ary_out+=("${var_new_lin_def}")
|
||||
var_found_lin_def=1
|
||||
;;
|
||||
|
||||
*)
|
||||
ary_out+=("${var_line}")
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
done
|
||||
done < "${var_file}"
|
||||
|
||||
### If Key is missing in the file, add it at the end (robust against minimal templates).
|
||||
(( var_found_lin == 0 )) && ary_lines+=("${var_new_lin}")
|
||||
(( var_found_lin_def == 0 )) && ary_lines+=("${var_new_lin_def}")
|
||||
(( var_found_lin == 0 )) && ary_out+=( "${var_new_lin}" )
|
||||
(( var_found_lin_def == 0 )) && ary_out+=( "${var_new_lin_def}" )
|
||||
|
||||
### Write back (without sed/awk, only built-ins).
|
||||
{
|
||||
for var_line in "${ary_lines[@]}"; do
|
||||
for var_line in "${ary_out[@]}"; do
|
||||
printf '%s\n' "${var_line}"
|
||||
done
|
||||
} >| "${var_file}"
|
||||
|
||||
Reference in New Issue
Block a user