From b1eaf453f2e5619c48e9b1727d30dbc3bb6883e1 Mon Sep 17 00:00:00 2001 From: Richard T Bonhomme Date: Tue, 8 Mar 2022 00:12:30 +0000 Subject: [PATCH] Make config_update() use universal_update() Signed-off-by: Richard T Bonhomme --- easytls | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/easytls b/easytls index 9e36b1a..8c08270 100755 --- a/easytls +++ b/easytls @@ -919,30 +919,21 @@ easytls_config () # Update config config_update () { - # Find the pattern - "${EASYTLS_GREP}" -q "^${cfg_opt}[[:blank:]]=[[:blank:]].*$" \ - "${EASYTLS_CONFIG_FILE}" || { - error_msg "config_update - input error: ${cfg_opt}" - return 1 - } - - # backup - "${EASYTLS_CP}" "${EASYTLS_CONFIG_FILE}" "${EASYTLS_CONFIG_FILE}.tmp" || { - error_msg "config_update - backup" + # remove old_record + old_record="^${cfg_opt} = .*\$" + if universal_update del "${EASYTLS_CONFIG_FILE}" "${old_record}"; then + : # ok + else return 1 - } - - # Replace the pattern - [ "${cfg_val}" != "0" ] || unset -v cfg_val - "${EASYTLS_SED}" -i -e \ - "s\`^${cfg_opt}[[:blank:]]=[[:blank:]].*$\`${cfg_opt} = ${cfg_val}\`g" \ - "${EASYTLS_CONFIG_FILE}" || { - error_msg "config_update - replace error: ${cfg_opt}" - return 1 - } + fi - # cleanup - "${EASYTLS_RM}" -f "${EASYTLS_CONFIG_FILE}.tmp" + # add new_record + new_record="${cfg_opt} = ${cfg_val}" + if universal_update add "${EASYTLS_CONFIG_FILE}" "${new_record}"; then + : # ok + else + return 1 + fi easytls_verbose easytls_verbose "config-file updated: ${cfg_opt} = ${cfg_val}" @@ -6399,9 +6390,9 @@ universal_update () fi ;; del) - if "${EASYTLS_GREP}" -q "^${record}" "${EASYTLS_TEMP_LIST}"; then + if "${EASYTLS_GREP}" -q "${record}" "${EASYTLS_TEMP_LIST}"; then # Delete record - if "${EASYTLS_SED}" -e "/^${record}/d" \ + if "${EASYTLS_SED}" -e "/${record}/d" \ "${EASYTLS_TEMP_LIST}" > "${EASYTLS_TEMP_UPDATE}" then # Success