Skip to content

Commit b1eaf45

Browse files
committed
Make config_update() use universal_update()
Signed-off-by: Richard T Bonhomme <[email protected]>
1 parent 13abe14 commit b1eaf45

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

easytls

+15-24
Original file line numberDiff line numberDiff line change
@@ -919,30 +919,21 @@ easytls_config ()
919919
# Update config
920920
config_update ()
921921
{
922-
# Find the pattern
923-
"${EASYTLS_GREP}" -q "^${cfg_opt}[[:blank:]]=[[:blank:]].*$" \
924-
"${EASYTLS_CONFIG_FILE}" || {
925-
error_msg "config_update - input error: ${cfg_opt}"
926-
return 1
927-
}
928-
929-
# backup
930-
"${EASYTLS_CP}" "${EASYTLS_CONFIG_FILE}" "${EASYTLS_CONFIG_FILE}.tmp" || {
931-
error_msg "config_update - backup"
922+
# remove old_record
923+
old_record="^${cfg_opt} = .*\$"
924+
if universal_update del "${EASYTLS_CONFIG_FILE}" "${old_record}"; then
925+
: # ok
926+
else
932927
return 1
933-
}
934-
935-
# Replace the pattern
936-
[ "${cfg_val}" != "0" ] || unset -v cfg_val
937-
"${EASYTLS_SED}" -i -e \
938-
"s\`^${cfg_opt}[[:blank:]]=[[:blank:]].*$\`${cfg_opt} = ${cfg_val}\`g" \
939-
"${EASYTLS_CONFIG_FILE}" || {
940-
error_msg "config_update - replace error: ${cfg_opt}"
941-
return 1
942-
}
928+
fi
943929

944-
# cleanup
945-
"${EASYTLS_RM}" -f "${EASYTLS_CONFIG_FILE}.tmp"
930+
# add new_record
931+
new_record="${cfg_opt} = ${cfg_val}"
932+
if universal_update add "${EASYTLS_CONFIG_FILE}" "${new_record}"; then
933+
: # ok
934+
else
935+
return 1
936+
fi
946937

947938
easytls_verbose
948939
easytls_verbose "config-file updated: ${cfg_opt} = ${cfg_val}"
@@ -6399,9 +6390,9 @@ universal_update ()
63996390
fi
64006391
;;
64016392
del)
6402-
if "${EASYTLS_GREP}" -q "^${record}" "${EASYTLS_TEMP_LIST}"; then
6393+
if "${EASYTLS_GREP}" -q "${record}" "${EASYTLS_TEMP_LIST}"; then
64036394
# Delete record
6404-
if "${EASYTLS_SED}" -e "/^${record}/d" \
6395+
if "${EASYTLS_SED}" -e "/${record}/d" \
64056396
"${EASYTLS_TEMP_LIST}" > "${EASYTLS_TEMP_UPDATE}"
64066397
then
64076398
# Success

0 commit comments

Comments
 (0)