From 92c6bade156ecc47730382221162de44f36bc3e7 Mon Sep 17 00:00:00 2001 From: allan Date: Sun, 2 Nov 2025 11:35:55 +0000 Subject: [PATCH] updated input check --- dokuwikiinstall | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dokuwikiinstall b/dokuwikiinstall index 28fce0f..ee47a9e 100755 --- a/dokuwikiinstall +++ b/dokuwikiinstall @@ -39,12 +39,18 @@ usage () { } # -# Function input check +# Parse and validate input # -inputcheck () { - if [[ -z "$1" ]]; then usage ; printf "ERROR: DOMAIN CANNOT BE EMPTY!\n\n" ; exit 1; fi - if [[ "$1" =~ [[:space:]/] ]]; then printf "ERROR: DOMAIN INVALID (no spaces or slashes allowed)\n\n"; exit 1; fi -} +if [[ $# -ne 1 ]]; then usage ; printf "ERROR: Exactly one argument (the domain) is required.\n\n" ; exit 1 ; fi + +hostname="$1" ; hostname=$(echo "$hostname" | tr '[:upper:]' '[:lower:]') + +if [[ "$hostname" =~ [[:space:]/_] ]]; then printf "ERROR: Domain cannot contain spaces, slashes, or underscores.\n\n" ; exit 1 ; fi + +if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then + printf "ERROR: Invalid domain format.\n" + printf "Example of valid input: wiki.example.com\n\n" ; exit 1 +fi # # Let's go