如何在'vagrant up'时安装composer-asset-plugin?

时间:2015-11-17 15:30:06

标签: shell vagrant composer-php expect puphpet

我按puphpet.com生成配置。我想在第一次运行composer-asset-plugin时安装vagrant up

我编写了简单的脚本puphpet\files\exec-once\composer-asset-plugin.sh,试图这样做:

#!/usr/bin/bash echo "Installing Composer Asset Plugin" composer global require "fxp/composer-asset-plugin:~1.0.0"

它在/root/.composer中安装插件,因此当我通过vagrant ssh(在用户vagrant下)连接并尝试使用Composer时出现错误,这意味着插件不存在,因为Composer在/home/vagrant/.composer中真的缺席了。在我安装插件后,malualy Composer工作正常。

我尝试在安装插件之前将用户从root更改为vagrant

#!/usr/bin/bash echo "Installing Composer Asset Plugin" expect -c 'set timeout 3600; spawn su - vagrant; expect "Password:" {send -- "vagrant\r";}; exit 0' composer global require fxp/composer-asset-plugin:~1.0.0;

它在命令expect之后挂起。我做错了什么?

1 个答案:

答案 0 :(得分:0)

以下内容可能有所帮助:

# Install Composer
if [ ! -f /usr/local/bin/composer ]; then
    cd /tmp
    curl -sS https://getcomposer.org/installer | php
    mv composer.phar /usr/local/bin/composer
fi
# Install necessary plugin
sudo -H -u vagrant bash -c "composer global require fxp/composer-asset-plugin:~1.0.0"

在这种情况下,命令将在vagrant用户上下文中执行,并且将使用他的家。