Cannot access special environment in script ran before making changes to domain

Hi,

I'm having an issue regarding the "Command to run before making changes to a domain" option within the Virtualmin configuration. I've written a little script that changes around permissions on the virtualhomes for various reasons, which is done with the "Command to run after making changes to a domain" option.

To prepare the domains for those permissions (after every change) I wrote another script that resets them before the changes, using the "Command to run before making changes to a domain". The script executes, but I don't have access to the special environment variables (VIRTUALSERVER_HOME for example).

Status: 
Closed (fixed)

Comments

Howdy -- could you share the full contents of your script looks like, and provide examples of line numbers that aren't working properly for you?

stat=`stat --format "%U" $VIRTUALSERVER_HOME`

if [[ $stat == "root" ]]
then
        chown $VIRTUALSERVER_USER $VIRTUALSERVER_HOME > /dev/null
fi

None of the lines produce an error since its running stat a non-existent variable

Which specific action in Virtualmin are you performing when this script gets run with no environment variables set?

Where I first ran into this is requesting/renewing a Let's encrypt SSL certificate, which gives a bunch of errors if the virtualserver home dir isn't owned by $VIRTUALSERVER_USER. I want the pre-domain script to fix the ownership, and the post-script will change ownership again.

I've updated the script for clarity:

echo "123"

whoami

echo $VIRTUALSERVER_HOME
echo $VIRTUALSERVER_USER

stat=`stat --format "%U" $VIRTUALSERVER_HOME`

if [[ $stat == "root" ]]
then
        chown $VIRTUALSERVER_USER $VIRTUALSERVER_HOME > /dev/null
fi

And the output, when I request a certificate is this:

123 root stat: missing operand Try 'stat --help' for more information. /opt/predomain.sh: 10: /opt/predomain.sh: [[: not found
Requesting a certificate for Foo.tld, Foo.tld from Let's Encrypt ..
.. request was successful!

Configuring webserver to use new certificate and key ..
Failed to request certificate : Failed to open /home/Foo.tld/ssl.cert.webmintmp.4586 : Permission denied

Ok, I see the bug here - this will be fixed in the next Virtualmin release.

Status: Active » Fixed