From bbd9213afd58696736043d8c2dcc89d3dc3cf37e Mon Sep 17 00:00:00 2001 From: allan Date: Thu, 30 Oct 2025 10:09:44 +0100 Subject: [PATCH] logic changes --- giteainstall | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/giteainstall b/giteainstall index 7b5172a..a44ac05 100755 --- a/giteainstall +++ b/giteainstall @@ -16,22 +16,40 @@ if [[ $(id -u) -ne 0 ]]; then printf "\nMust be root or use sudo.\n\n" ; exit 1 giteaport=3000 if ss -tuln | grep -q ":${giteaport}\b"; then printf "\nPort %s appears to be in use.\n" "$giteaport" - listener=$(ss -tulpn 2>/dev/null | awk '/:3000\b/ && /LISTEN/ {print $7}' | sed 's/users:(("//; s/",.*//') + listener=$(ss -tulpn 2>/dev/null | awk -v port=":${giteaport}\\b" '$0 ~ port && /LISTEN/ {print $7}' | sed 's/users:(("//; s/",.*//') if [[ "$listener" == gitea* ]]; then printf "Detected a running Gitea-related process: %s\n" "$listener" printf "It looks like another Gitea multi-instance installation has not yet completed.\n" printf "Please finish its web installer and run its postinstall script before continuing.\n\n" elif [[ -n "$listener" ]]; then - printf "Process using port 3000 : %s\n" "$listener" + printf "Process using port %s : %s\n" "$giteaport" "$listener" printf "This port is required temporarily by the Gitea web installer.\n" printf "Please stop or reconfigure that application before running this installer.\n\n" else - printf "Port 3000 is in use by an unknown process.\n" + printf "Port %s is in use by an unknown process.\n" "$giteaport" printf "Please ensure it is free before running this installer.\n\n" fi exit 1 fi +# +# Check if required services are running or not +# +for svc in nginx mariadb; do systemctl is-active --quiet "$svc" || { printf "\n%s is not running, cannot continue...\n\n" "${svc^}" ; exit 1 ; }; done + +# +# Check MariaDB authentication method (socket or not) +# +if mysql -u root -e ";" 2>/dev/null; then + socket="SOCKET DETECTED — no need for -a or -m" + socketusage="SOCKET DETECTED — this flag is not needed" + socketauth="yes" +else + socket="NO SOCKET DETECTED — you must use -a and -m" + socketusage="NO SOCKET DETECTED — these flags are required" + socketauth="no" +fi + # # Define variables and functions # @@ -54,21 +72,18 @@ usage () { printf -- " sudo ./giteainstall -n git3.example.com -p gitea3dbpwd -a admin -m adminpwd\n\n" } -serviceno () { printf "\n%s is not running cannot continue...\n\n" "$service"; } -servicedead () { status=$(systemctl is-active "$service"); if [[ "$status" != "active" ]]; then serviceno ; exit ; fi ; } -inputcheck () { [[ -z "$hostname" ]] && { usage ; printf "\nError! Hostname empty.\n\n" ; exit 1 ; } ; [[ -z "$dbpass" ]] && { usage ; printf "\nError! Database password empty.\n\n" ; exit 1 ; } ; } +# +# Function inputcheck +# +inputcheck () { + [[ -z "$hostname" ]] && { usage; echo "ERROR: DOMAIN CANNOT BE EMPTY!"; exit 1; } + [[ "$hostname" =~ [[:space:]/] ]] && { echo "ERROR: DOMAIN INVALID (no spaces or slashes allowed)"; exit 1; } + [[ -z "$dbpass" ]] && { usage; echo "ERROR: DATABASE PASSWORD CANNOT BE EMPTY!"; exit 1; } +} # -# If Nginx and MariaDB are not running then die +# Let's go # -service="mariadb" ; servicedead ; service="nginx" ; servicedead - -# -# Check MariaDB authentication method (socket or not) -# -if mysql -u root -e ";" 2>/dev/null; then socket="SOCKET DETECTED — no need for -a or -m" ; socketusage="SOCKET DETECTED — these flags are not needed" ; socketauth="yes" -else socket="NO SOCKET DETECTED — you must use -a and -m" ; socketusage="NO SOCKET DETECTED — these flags are required" ; socketauth="no" ; fi - clear # @@ -164,7 +179,7 @@ esac # Create Gitea temporary Nginx configuration file using port 3000 for web installer # cp "$nginxsnippets/hostfiles/gitea-multi.80.conf" /etc/nginx/conf.d/"$hostname".conf -sed -i "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf +sed -i -- "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf sed -i "s/GITEAPORT/3000/g" /etc/nginx/conf.d/"$hostname".conf systemctl restart nginx