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.

Coreus
  • 5,360
  • 3
  • 35
  • 50
  • possible duplicate of [Ant run command with pipes](http://stackoverflow.com/questions/1187402/ant-run-command-with-pipes) – Mez Feb 07 '13 at 12:56

2 Answers2

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.

Community
  • 1
  • 1
Mez
  • 24,430
  • 14
  • 71
  • 93
  • 1
    Thanks. I ended up using Ant's "GET", which does the same apparently. https://ant.apache.org/manual/Tasks/get.html Marking this anyway as accepted. – Coreus Feb 12 '13 at 09:03
  • This is not secure because it does not verify the signature of the install script before executing it. – Damien Nov 17 '17 at 05: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
Damien
  • 1,140
  • 15
  • 22