0

The web-application document-root for Debian-Apache is typically /var/www/html/ but for Arch-Apache it's typically /srv/http/.

I wrote a distro-agnostic LAMP-establishment script and I need it to test what is the distro-oriented document-root dir (based on the dir's existence) and the one that is true is the one I would continue to work with till the end of the script.

I usually do drt="/var/www/html" but I need to have the variable control flowed like in this pseudocode:

drt="/var/www/html XOR /srv/http"

Of course, only one of the two or more options is true, and that should base the XOR conditioning.

Is there a way to do so in Bash?

  • The dir's existence. – JohnDoea Jan 19 at 21:35
2

I need it to test what is the distro-oriented document-root dir (based on the dir's existence)

From those two options, you could use [ -d dir ] to see if they exist:

if [ -d /var/www/html ]; then
    drt=/var/www/html;
elif [ -d /srv/http ]; then
    drt=/srv/http
else
    echo "No HTTP server root directory found"
    exit 1
fi

or, with a loop:

drt=
for d in /var/www/html /srv/http; do
    if [ -d "$d" ]; then
        drt=$d;
        break 
    fi
done
if [ -z "$drt" ]; then
    echo "No HTTP server root directory found"
    exit 1
fi 

Of course, all of this assumes that they're actually using the distro's default document root, which might not be the case. It might not be a bad idea to give the user a chance to verify that the directory found by the script is the correct one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.