Fixed the sed commands

main
Anthony 2025-08-09 01:13:54 +08:00
parent c7668bee46
commit f9d144e6f7
1 changed files with 9 additions and 2 deletions

View File

@ -230,7 +230,14 @@ if [[ -f "$CONFIG_FILE" && -w "$CONFIG_FILE" ]]; then
[[ -z "$HOST_ONLY" ]] && HOST_ONLY="$TARGET_URL"
# shellcheck disable=SC2016 # we want literal quotes inside sed replacement
# Replace existing definitions (handle both single and double quotes)
sed -i -E "s|define\([[:space:]]*['\"]WP_HOME['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\);|define( 'WP_HOME', '${TARGET_URL}' );|; s|define\([[:space:]]*['\"]WP_SITEURL['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\);|define( 'WP_SITEURL', '${TARGET_URL}' );|; s|\$_SERVER\[(\"|')HTTP_HOST\1\][[:space:]]*=[[:space:]]*(\"|')[^"']*\2;|\$_SERVER['HTTP_HOST'] = '${HOST_ONLY}';|" "$CONFIG_FILE" || warning "Failed to update wp-config.php"
# Update WP_HOME if it exists
sed -i -E "s|define[[:space:]]*\([[:space:]]*['\"]WP_HOME['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\)|define( 'WP_HOME', '${TARGET_URL}' )|g" "$CONFIG_FILE"
# Update WP_SITEURL if it exists
sed -i -E "s|define[[:space:]]*\([[:space:]]*['\"]WP_SITEURL['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\)|define( 'WP_SITEURL', '${TARGET_URL}' )|g" "$CONFIG_FILE"
# Update HTTP_HOST if it exists
sed -i -E "s|(\\\$_SERVER\[['\"]HTTP_HOST['\"]\][[:space:]]*=[[:space:]]*['\"])[^'\"]*(['\"];)|\1${HOST_ONLY}\2|g" "$CONFIG_FILE"
# Determine which entries are missing to avoid duplicates
needs_home=1
@ -243,7 +250,7 @@ sed -i -E "s|define\([[:space:]]*['\"]WP_HOME['\"][[:space:]]*,[[:space:]]*['\"]
if grep -Eq "define[[:space:]]*\([[:space:]]*['\"]WP_SITEURL['\"]" "$CONFIG_FILE"; then
needs_siteurl=0
fi
if grep -Eq "\$_SERVER\[(\"|')HTTP_HOST\1\][[:space:]]*=" "$CONFIG_FILE"; then
if grep -Eq '\$_SERVER\[["\x27]HTTP_HOST["\x27]\][[:space:]]*=' "$CONFIG_FILE"; then
needs_http_host=0
fi