Skip to content

Commit 1332a77

Browse files
authored
Update vhost-install.sh
1 parent d5b15b0 commit 1332a77

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

scripts/functions/vhost/vhost-install.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,18 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
193193
fi
194194
# RAND_CHAR4, RAND_CHAR16, and RAND_CHAR32 are random strings (length 4/16/32)
195195
# sourced from /usr/local/bin/enginescript/enginescript-variables.txt.
196-
database_name="${domain_without_tld}_${RAND_CHAR4}"
196+
# Enforce MySQL/MariaDB identifier max length (64 chars) before concatenation.
197+
db_name_suffix="_${RAND_CHAR4}"
198+
max_db_name_len=64
199+
max_domain_without_tld_len=$((max_db_name_len - ${#db_name_suffix}))
200+
if (( max_domain_without_tld_len < 1 )); then
201+
echo "Error: Invalid random suffix length for database name generation." >&2
202+
exit 1
203+
fi
204+
if (( ${#domain_without_tld} > max_domain_without_tld_len )); then
205+
domain_without_tld="${domain_without_tld:0:max_domain_without_tld_len}"
206+
fi
207+
database_name="${domain_without_tld}${db_name_suffix}"
197208
# Normalize to lowercase for MySQL/MariaDB portability across platforms
198209
database_name="${database_name,,}"
199210
# Validate DB identifier before writing credentials file or interpolating into SQL
@@ -236,7 +247,7 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
236247

237248
echo "Randomly generated MySQL database credentials for ${DOMAIN}."
238249

239-
if ! sudo mariadb -e "CREATE DATABASE ${DB} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; then
250+
if ! sudo mariadb -e "CREATE DATABASE \`${DB}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_uca1400_ai_ci;"; then
240251
echo "Error: Failed to create database '${DB}' for domain '${DOMAIN}'." >&2
241252
exit 1
242253
fi
@@ -246,7 +257,7 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
246257
exit 1
247258
fi
248259

249-
if ! sudo mariadb -e "GRANT ALL ON ${DB}.* TO '${USR}'@'localhost'; FLUSH PRIVILEGES;"; then
260+
if ! sudo mariadb -e "GRANT ALL ON \`${DB}\`.* TO '${USR}'@'localhost'; FLUSH PRIVILEGES;"; then
250261
echo "Error: Failed to grant privileges on database '${DB}' to user '${USR}'." >&2
251262
exit 1
252263
fi
@@ -317,7 +328,7 @@ if [[ "${INSTALL_WORDPRESS}" == "1" ]]; then
317328

318329
# Email: basic format validation
319330
# Single character addresses such as [email protected] are valid and accepted by the regex.
320-
EMAIL_REGEX='^[A-Za-z0-9](?:[A-Za-z0-9_%+-]*[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9_%+-]*[A-Za-z0-9])?)*@[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*\.[A-Za-z]{2,}$'
331+
EMAIL_REGEX='^[A-Za-z0-9]([A-Za-z0-9_%+-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9_%+-]*[A-Za-z0-9])?)*@[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*\.[A-Za-z]{2,}$'
321332
if [[ ! "${WP_ADMIN_EMAIL}" =~ ${EMAIL_REGEX} ]]; then
322333
echo "Error: WP_ADMIN_EMAIL is not a valid email address format." >&2
323334
exit 1

0 commit comments

Comments
 (0)