diff --git a/README.rst b/README.rst index deea666..1bd14e3 100644 --- a/README.rst +++ b/README.rst @@ -40,6 +40,11 @@ Installs the php-cgi package. Installs the php-cli package. +``php.composer`` +----------- + +Installs [composer](https://getcomposer.org) and keeps it updated. + ``php.curl`` ------------ diff --git a/php/composer.sls b/php/composer.sls new file mode 100644 index 0000000..530c723 --- /dev/null +++ b/php/composer.sls @@ -0,0 +1,34 @@ +{% from "php/map.jinja" import php with context %} +{% set install_file = php.local_bin + '/composer' %} + +include: + - php + +get-composer: + cmd.run: + - name: 'CURL=`which curl`; $CURL -sS https://getcomposer.org/installer | php' + - unless: test -f {{ install_file }} + - cwd: {{ php.temp_dir }} + - require: + - pkg: php + +install-composer: + cmd.wait: + - name: mv {{ php.temp_dir }}/composer.phar {{ install_file }} + - cwd: {{ php.temp_dir }} + - watch: + - cmd: get-composer + +# Get COMPOSER_DEV_WARNING_TIME from the installed composer, and if that time has passed +# then it's time to run `composer selfupdate` +# +# It would be nice if composer had a command line switch to get this, but it doesn't, +# and so we just grep for it. +# +update-composer: + cmd.run: + - name: "{{ install_file }} selfupdate" + - unless: test $(grep --text COMPOSER_DEV_WARNING_TIME {{ install_file }} | egrep '^\s*define' | sed -e 's,[^[:digit:]],,g') \> $(php -r 'echo time();') + - cwd: {{ php.temp_dir }} + - require: + - cmd: install-composer diff --git a/php/map.jinja b/php/map.jinja index 0c7b677..5491117 100644 --- a/php/map.jinja +++ b/php/map.jinja @@ -32,6 +32,8 @@ 'mongo_pecl': 'mongo', 'mongo_ext': 'mongo.so', 'ext_conf_path': '/etc/php5/mods-available', + 'local_bin': '/usr/local/bin', + 'temp_dir': '/tmp', }, 'RedHat': { 'php_pkg': 'php', @@ -66,5 +68,7 @@ 'mongo_pecl': 'mongo', 'mongo_ext': 'mongo.so', 'ext_conf_path': '/etc/php5/conf.d', + 'local_bin': '/usr/local/bin', + 'temp_dir': '/tmp', }, }, merge=salt['pillar.get']('php:lookup')) %}