From 8c46cfebe573695673bf1f0035ea17affac7463f Mon Sep 17 00:00:00 2001 From: Thuan Bui Date: Thu, 30 Jan 2025 19:37:40 +0900 Subject: [PATCH] Check if user input empty username --- lib/menu.sh | 5 +++++ lib/validation.sh | 8 ++++++++ templates/wp-setup.sh.template | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/menu.sh b/lib/menu.sh index d3ed25d..3f273ad 100644 --- a/lib/menu.sh +++ b/lib/menu.sh @@ -176,7 +176,12 @@ install_site() { fi done + while true; do read -p "Enter admin username: " ADMIN_USER + if validate_username "$ADMIN_USER"; then + break + fi + done read -s -p "Enter password (press Enter for random password): " ADMIN_PASSWORD echo diff --git a/lib/validation.sh b/lib/validation.sh index 27a85ec..ae4b97b 100644 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -14,4 +14,12 @@ validate_email() { return 1 fi return 0 +} + +validate_username() { + if [[ -z "$1" ]] || [[ "$1" =~ ^[[:space:]]*$ ]]; then + echo -e "${RED}Username cannot be empty${NC}" + return 1 + fi + return 0 } \ No newline at end of file diff --git a/templates/wp-setup.sh.template b/templates/wp-setup.sh.template index 06e7d2b..e4ec15b 100644 --- a/templates/wp-setup.sh.template +++ b/templates/wp-setup.sh.template @@ -7,7 +7,8 @@ wpcli() { echo "Waiting for MariaDB to be ready..." while [ "$(docker inspect --format='{{.State.Health.Status}}' db_${DOMAIN})" != "healthy" ]; do - echo "MariaDB is not healthy yet. Retrying..." + #echo "MariaDB is not healthy yet. Retrying..." + echo "Loading..." sleep 5 done