How can I check for root privileges with an Ant build script? I tried doing it with the shellscript task like
<shellscript shell="bash">
if [[ `whoami` != 'root' ]]; then
echo "You need to be root to install ooplss";
exit 1
fi
</shellscript>
But this won't stop the execution of the script.
Any other ideas?
The shellscript task is an extension of the exec task. You should be able to specify failonerror
to make the build process fail if the script fails:
failonerror: Stop the buildprocess if the command exits with a return code signaling failure. Defaults to false.
<shellscript shell="bash" failonerror="true">
if [[ `whoami` != 'root' ]]; then
echo "You need to be root to install ooplss";
exit 1
fi
</shellscript>
It should however be possible to do without a shell script; the following is untested:
<fail message="You need to be root to install ooplss">
<condition>
<not>
<equals arg1="root" arg2="${user.name}"/>
</not>
</condition>
</fail>