8

I'm trying to get make my Ant script retrieve Composer for me. Composer is a dependancy manager for PHP. According to the doc one needs to run this command: "curl -s https://getcomposer.org/installer | php" which will download Composer.phar into the directory I'm in. This works as intended when running from a terminal.

How do I setup the Ant build file for this? So far I've got this segment for the "composerget" target, but it's doesn't save the file, only output it in my command shell:

....    
<target name="composerget" description="Composer update dependencies">
    <exec executable="curl"> 
        <arg line="-s" />
            <arg line="https://getcomposer.org/installer"/>
        <arg line="| php" />
    </exec>
  </target>
....

Any help is greatly appeciated.

1

2 Answers 2

8
<target name="composerget" description="Composer update dependencies">
    <exec executable="/bin/bash">
        <arg value="-c" />
        <arg value="curl -s https://getcomposer.org/installer | php" />
    </exec>
</target>

Should do the trick.

The pipe (|) can only be used in a shell script. You're passing it as an argument to curl. So you need to execute a shell script - which you can do with bash -c and passing the command as a shell statement.

Attribution.

2
  • 1
    Thanks. I ended up using Ant's "GET", which does the same apparently. ant.apache.org/manual/Tasks/get.html Marking this anyway as accepted.
    – Coreus
    Feb 12, 2013 at 9:03
  • This is not secure because it does not verify the signature of the install script before executing it.
    – Damien
    Nov 17, 2017 at 5:27
0

This will download the Composer installer, verify its signature, and run the installer:

    <target name="composer" description="Install composer">
        <exec executable="wget">
            <arg value="-O" />
            <arg value="composer-setup.sig" />
            <arg value="https://composer.github.io/installer.sig" />
        </exec>
        <exec executable="wget">
            <arg value="-O" />
            <arg value="composer-setup.php" />
            <arg value="https://getcomposer.org/installer" />
        </exec>
        <exec executable="bash">
            <arg value="-c" />
            <arg value="awk '{print $$0 &quot;  composer-setup.php&quot;}' composer-setup.sig | sha384sum --check" />
        </exec>
        <exec executable="php">
            <arg value="composer-setup.php" />
        </exec>
        <exec executable="rm">
            <arg value="composer-setup.php" />
        </exec>
        <exec executable="rm">
            <arg value="composer-setup.sig" />
        </exec>
        <exec executable="mv">
            <arg value="composer.phar" />
            <arg value="composer" />
        </exec>
    </target>

If you are using GNU Make, this is the equivalent:

all: vendor

vendor: composer composer.json composer.lock
        ./composer install

composer:
        wget -O composer-setup.sig https://composer.github.io/installer.sig
        wget -O composer-setup.php https://getcomposer.org/installer
        awk '{print $$0 "  composer-setup.php"}' composer-setup.sig | sha384sum --check
        php composer-setup.php --quiet
        rm composer-setup.*
        mv composer.phar composer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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