I’d like to include a runcmd that will install Composer on a newly created instance, but the command contains both single and double quotes already when used manually.

This is what I’d like to execute with cloud-init.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

mv composer.phar /usr/local/bin/composer

I’ve read the cloud init documentation for the runcmd module, but didn’t made much sense about how to implement the above. I hope it’s possible, otherwise I have to bundle the commands into a downloadable bash script for cloud-init to run.

1 comment
  • Btw, I’ve never took a step back to look the getcomposer provided commands.

    I think the first line could be a done with a curl pipped into a sha384 hash verifier command (I guess it should exists) then followed by the php command that runs the downloaded file. Finally move the composer.phar file into the folder mentioned in the instructions and finally finally delete the downloaded file.

Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!