在没有用户提示的情况下安装PHP Pear

时间:2011-08-23 16:50:55

标签: php automation pear

是否有命令行参数允许您在没有用户提示的情况下安装PHP Pear?我想自动执行以下执行:

wget http://pear.php.net/go-pear.phar
php go-pear.phar
pear config-set preferred_state beta
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install --alldeps phpunit/PHPUnit
rm go-pear.phar

php go-pear.phar 会提示用户输入安装/配置信息。

2 个答案:

答案 0 :(得分:4)

原来expect成功了。以下是我最终的结果:

install-pear.sh

#!/usr/bin/expect
spawn wget -O /tmp/go-pear.phar http://pear.php.net/go-pear.phar
expect eof

spawn php /tmp/go-pear.phar

expect "1-11, 'all' or Enter to continue:"
send "\r"
expect eof

spawn rm /tmp/go-pear.phar

install-phpunit.sh

#!/bin/bash
./install-pear.sh
pear config-set preferred_state beta
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install --alldeps phpunit/PHPUnit

运行:

sudo apt-get install expect
chmod 744 ./install-pear.sh
chmod 744 ./install-phpunit.sh
sudo ./install-phpunit.sh

答案 1 :(得分:1)

go-pear.phar本身不通过CLI接受任何参数,因此无法在没有用户交互的情况下运行(除非使用expect等输入工具)

执行phar时,运行文件go-pear-phar.php,然后启动PEAR/Start/CLI.php。如您所见,getInstallLocations确实等待活动用户输入而无法跳过它。