Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 99fdd04744
Fetching contributors…

Cannot retrieve contributors at this time

166 lines (137 sloc) 7.088 kB
<?xml version="1.0" encoding="UTF-8"?>
<project name="blip.fm" basedir="." default="hello">
<!-- properties -->
<dirname property="currentPath" file="./build.xml" />
<basename property="baseHostname" file="." />
<property name="server.host.prefix" value="server" />
<property name="clientSubdomain" value="client" />
<property name="vhostRepo" location="/etc/apache2/other" />
<property name="instancePath" location="${currentPath}" />
<property name="vhostConfPath" value="${vhostRepo}/${baseHostname}.conf" />
<property name="vhostTemplatePath" location="resqee-server/conf/vhost.tpl" />
<property name="etcHostsPath" location="/etc/hosts" />
<property name="serverAlias" value="${baseHostname}2.local" />
<property name="newHostsEntry" value="127.0.0.1 ${serverAlias} ${baseHostname}.local ${clientSubdomain}.${baseHostname}.local" />
<property environment="env" />
<condition property="username" value="${env.SUDO_USER}" else="${env.USER}">
<equals arg1="root" arg2="${env.USER}"/>
</condition>
<condition property="isRoot" value="true">
<equals arg1="root" arg2="${env.USER}"/>
</condition>
<!-- Check out the config -->
<target name ="showConfig" description="Dumps relevant ant properties.">
<echo>baseHostname : ${baseHostname}</echo>
<echo>vhostRepo : ${vhostRepo}</echo>
<echo>instancePath : ${instancePath}</echo>
<echo>vhostConfPath : ${vhostConfPath}</echo>
<echo>vhostTemplatePath : ${vhostTemplatePath}</echo>
<echo>username : ${username}</echo>
<echo>isRoot : ${isRoot}</echo>
</target>
<!-- hi -->
<target name="hello" depends="showConfig,showVhosts">
<exec executable="ant">
<arg value="-p" />
</exec>
</target>
<!-- configure this instance -->
<target name="configure"
description="Configure this virtual host"
depends="setupVhostRepo,createVhostConfFile,configEtcHosts,restart">
<echo>Point your browser at http://${baseHostname}.local or http://${clientSubdomain}.${baseHostname}.local</echo>
</target>
<!-- Make the folder that all vhost conf files go in -->
<target name ="setupVhostRepo"
depends="checksudo"
description="Make the folder that all vhost conf files go in.">
<chown file="${vhostRepo}" owner="${username}"/>
<echo>changed owner of ${vhostRepo} to ${username}</echo>
</target>
<!-- check out the vhost's conf file's content -->
<target name="dumpVhostConfig" description="Check out the virtual host's conf file">
<echo>dumping content of: ${vhostConfPath}</echo>
<loadfile property="vhostContent" srcFile="${vhostConfPath}" />
<echo>${vhostContent}</echo>
</target>
<!-- create the conf file -->
<target
name="createVhostConfFile"
depends="setupVhostRepo"
description="Create a .conf file for this vhost. If a conf file already exists it will be overwritten.">
<copy overwrite="true" file="${vhostTemplatePath}" tofile="${vhostConfPath}"/>
<echo>Created conf file:</echo>
<echo> ${vhostConfPath}</echo>
<echo>replacing tokens in ${vhostConfPath}:</echo>
<echo> $serverHostname => ${baseHostname}.local</echo>
<echo> $clientHostname => ${clientSubdomain}.${baseHostname}.local</echo>
<echo> $instancePath => ${instancePath}</echo>
<echo> $serverAlias => ${serverAlias}</echo>
<replace file="${vhostConfPath}" token="$serverHostname" value="${baseHostname}.local"/>
<replace file="${vhostConfPath}" token="$clientHostname" value="${clientSubdomain}.${baseHostname}.local"/>
<replace file="${vhostConfPath}" token="$instancePath" value="${instancePath}" />
<replace file="${vhostConfPath}" token="$serverAlias" value="${serverAlias}" />
<echo>chown ${username} ${vhostConfPath}:</echo>
<chown file="${vhostConfPath}" owner="${username}"/>
<echo> done</echo>
<echo>Make sure your main httpd.conf file has a line like</echo>
<echo> Include ${vhostRepo}/*.conf</echo>
</target>
<!-- cleanup -->
<target name="clean" depends="checksudo,removeHostsEnry,removeVhost,restart"
description="Clean up this host by removing vhost and ${etcHostsPath} entries" />
<!-- check for sudo -->
<target name="checksudo">
<echo>Checking for root:</echo>
<fail message="You must use sudo to run this target" unless="isRoot" />
<echo> OK</echo>
</target>
<!-- kill vhost -->
<target name="removeVhost" depends="checksudo"
description="Remove this vhost from apache &amp; restart the server">
<echo>Deleting: ${vhostConfPath}</echo>
<delete file="${vhostConfPath}"/>
<echo> done</echo>
<antcall target="restart" inheritAll="true" />
</target>
<!-- remove entry from ${etcHostsPath} -->
<target name="removeHostsEnry"
depends="checksudo"
description="Remove this host from ${etcHostsPath}">
<echo>Removing ${baseHostname} from ${etcHostsPath}</echo>
<loadfile srcfile="${etcHostsPath}" property="newHostsFileContent">
<filterchain>
<tabstospaces tablength="4"/>
<tokenfilter>
<replacestring from="${newHostsEntry}" to=""/>
</tokenfilter>
<ignoreblank/>
</filterchain>
</loadfile>
<echo file="${etcHostsPath}">${newHostsFileContent}</echo>
<echo> done</echo>
</target>
<!-- update ${etcHostsPath} with new info -->
<target
name="configEtcHosts"
depends="checksudo,removeHostsEnry"
description="Make sure ${etcHostsPath} has info for the new vhost">
<echo>Adding ${baseHostname} to ${etcHostsPath}</echo>
<echo file="${etcHostsPath}" append="true">${newHostsEntry}${line.separator}</echo>
<echo> done</echo>
</target>
<!-- restart apache -->
<target name="restart" description="Restart apache" depends="checksudo">
<echo>Restarting apache</echo>
<exec executable="apachectl">
<arg value="restart" />
</exec>
<echo> done</echo>
</target>
<!-- show vhosts -->
<target name="showVhosts" description="Show installed virtual hosts">
<exec executable="apachectl">
<arg value="-S" />
</exec>
</target>
</project>
Jump to Line
Something went wrong with that request. Please try again.