config_edit() {
config_edit_file="$1"
config_edit_tmp_file=$(mktemp "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXXXX")
cp "$config_edit_file" "$config_edit_tmp_file"
errors=""
for var in $config_parameters; do
eval tmp_val="\$config_$var"
eval tmp_label="\$display_$var"
if [ -n "$(type -t validate_${var})" ] && [ "$(type -t validate_${var})" = function ]; then
if validate_$var "$tmp_val" ; then
error=""
else
errors="$errors\nERROR: $var $validate_msg_error"
fi
else
if validate_empty "$tmp_val" ; then
error=""
else
errors="$errors\nERROR: $var $validate_msg_error"
fi
fi
# sanitized_val=$(echo "$tmp_val" | sed -e 's/[\/&]/\\&/g')
# sanitized_var=$(echo "$var" | sed -e 's/[\/&]/\\&/g')
# sanitized_error=""
# [ "$error" != "" ] && sanitized_error=$(echo "$error" | sed -e 's/[\/&]/\\&/g')
# sanitized_error="# ${sanitized_error}"
# error_sed=""
# [ "$error" != "" ] && error_sed="/^[[:space:]]*${sanitized_var}[[:space:]]*=/i${sanitized_error}"
# sed -i -e "s/^\([[:space:]]*${sanitized_var}[[:space:]]*=\)/\1/" -e "$error_sed" "$config_edit_tmp_file"
sed -i -e "s/^\([[:space:]]*${sanitized_var}[[:space:]]*=\)/\1/" "$config_edit_tmp_file"
done
sed -i '1i # This is Onedatify configuration. Apply your changes to this file, save it and exit the editor.' "$config_edit_tmp_file"
echo $errors
#vim "$config_edit_tmp_file"
#rm "$config_edit_tmp_file"
}