Skip to content

Commit

Permalink
Make config_update() use universal_update()
Browse files Browse the repository at this point in the history
Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Mar 8, 2022
1 parent 13abe14 commit b1eaf45
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions easytls
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down

1 comment on commit b1eaf45

@TinCanTech
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.