如何使用Ant构建脚本检查root权限?我尝试使用shellscript任务来完成此任务,如下所示
<shellscript shell="bash">
if [[ `whoami` != 'root' ]]; then
echo "You need to be root to install ooplss";
exit 1
fi
</shellscript>但这不会停止脚本的执行。
还有其他想法吗?
发布于 2011-06-15 02:32:29
shellscript任务是exec任务的扩展。您应该能够指定failonerror,以便在脚本失败时使构建过程失败:
failonerror:如果命令退出时返回代码表示失败,则停止构建进程。默认为false。
<shellscript shell="bash" failonerror="true">
if [[ `whoami` != 'root' ]]; then
echo "You need to be root to install ooplss";
exit 1
fi
</shellscript>但是,不使用shell脚本也是可行的;以下内容未经测试:
<fail message="You need to be root to install ooplss">
<condition>
<not>
<equals arg1="root" arg2="${user.name}"/>
</not>
</condition>
</fail>发布于 2011-06-15 02:40:34
您可以检查java属性user.name
<target name="checkroot">
<condition property="isroot">
<equals arg1="${os.user}" arg2="root"/>
</condition>
</target>
<target name="dostuff" depends="checkroot" unless="isroot">
...
</target>从ANT1.7开始,您还可以使用<scriptcondition>代替上面的<equals>在脚本中做一些聪明的事情
发布于 2011-06-15 03:58:26
使用Ant Plugin Flaka =的直接方法
<project xmlns:fl="antlib:it.haefelinger.flaka">
<fl:when test=" '${user.name}'.toupper eq 'ROOT' ">
<!-- your tasks go here.. -->
</fl:when>
</project>https://stackoverflow.com/questions/6348151
复制相似问题