diff --git a/wordpressinstall b/wordpressinstall index 683810b..5cc8030 100755 --- a/wordpressinstall +++ b/wordpressinstall @@ -130,6 +130,27 @@ if [[ ! "$hostname" =~ ^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$ ]]; then exit 1 fi +# Prevent accidental overwrite of existing Nginx config +if [[ -f "/etc/nginx/conf.d/${hostname}.conf" ]]; then + printf "\nERROR: A configuration file already exists for %s.\n" "$hostname" + printf "Refusing to overwrite existing site.\n\n" + exit 1 +fi + +# Check for existing references in other Nginx configs +hostcheck=$(grep -r --exclude="README.md" "$hostname" /etc/nginx/ 2>/dev/null || true) +if [[ -n "$hostcheck" ]]; then + printf "\nFound existing configuration mentioning %s — aborting to avoid collision.\n\n" "$hostname" + exit 1 +fi + +# Prevent overwriting existing document root +if [[ -d "/var/www/html/${hostname}" ]]; then + printf "\nERROR: Directory /var/www/html/%s already exists.\n" "$hostname" + printf "Refusing to continue to avoid overwriting existing WordPress files.\n\n" + exit 1 +fi + # Check for spaces in DB credentials if [[ "$dbname" =~ [[:space:]] || "$dbuser" =~ [[:space:]] || "$dbpass" =~ [[:space:]] ]]; then printf "\nERROR: Database name, user, and password cannot contain spaces.\n\n"