Compare commits

..

No commits in common. "734ca2940c22ae5bf66d3e1531e4233c7e986d58" and "c4ec01204bd5525aee0779aa0fc09e5dbe2c00da" have entirely different histories.

33
init.sh
View File

@ -338,23 +338,14 @@ initUpdateConfigOption() {
for config_file in "$category_dir"/*; do
if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
if grep -q "^$config_option=" "$config_file"; then
# Use SOH (\x01) as the s-command delimiter — it can't appear
# in text-based config values or comments, so no field needs
# to escape the delimiter. The replacement field DOES need
# `&` (whole-match insertion) and `\` (escape char) neutralised
# in BOTH the value AND the comment — comments like
# `# Installation Mode - ...[release|git|local]` previously
# broke the `|`-delimited form with "unknown option to `s'".
local DELIM=$'\x01'
local escaped_value=$(printf '%s' "$config_value" | sed -e 's/[\\&]/\\&/g')
local escaped_value=$(printf '%s\n' "$config_value" | sed -e 's/[\/&]/\\&/g')
local original_line=$(grep "^$config_option=" "$config_file")
local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p")
local escaped_comment=$(printf '%s' "$comment_part" | sed -e 's/[\\&]/\\&/g')
if [[ -n "$comment_part" ]]; then
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value $escaped_comment${DELIM}" "$config_file"
sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file"
else
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value${DELIM}" "$config_file"
sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file"
fi
source "$config_file"
return 0
@ -1258,24 +1249,18 @@ commandUpdateConfigOption() {
for config_file in "$category_dir"/*; do
if [ -f "$config_file" ] && [[ ! "$config_file" =~ \.category$ ]]; then
if grep -q "^$config_option=" "$config_file"; then
# Use SOH (\x01) as the s-command delimiter — it can't appear
# in text-based config values or comments, so no field needs
# to escape the delimiter. The replacement field DOES need
# `&` (whole-match insertion) and `\` (escape char) neutralised
# in BOTH the value AND the comment — comments like
# `# Installation Mode - ...[release|git|local]` previously
# broke the `|`-delimited form with "unknown option to `s'".
local DELIM=$'\x01'
local escaped_value=$(printf '%s' "$config_value" | sed -e 's/[\\&]/\\&/g')
# Escape special characters in the config value to prevent sed issues
local escaped_value=$(printf '%s\n' "$config_value" | sed -e 's/[\/&]/\\&/g')
# Extract the comment part first (everything after the first #)
local original_line=$(grep "^$config_option=" "$config_file")
local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p")
local escaped_comment=$(printf '%s' "$comment_part" | sed -e 's/[\\&]/\\&/g')
# Replace the value, preserving comment if it existed
if [[ -n "$comment_part" ]]; then
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value $escaped_comment${DELIM}" "$config_file"
sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file"
else
sed -i "s${DELIM}^$config_option=.*${DELIM}$config_option=$escaped_value${DELIM}" "$config_file"
sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file"
fi
source "$config_file"
return 0