レンタルサーバーのコアサーバー(CORESERVER)だと、以前に投稿したスクリプトが動作しなかったので、書き直しました。
問題点
php
コマンドだと-r
オプションが使えませんでした。。。
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Error in argument 1, char 2: option not found r
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file> [args...]
-a Run interactively
-b <address:port>|<port> Bind Path for external FASTCGI Server mode
-C Do not chdir to the script's directory
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse <file>. Implies `-q'
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
-T <count> Measure execution time of script repeated <count> times.
対応
コマンドライン用(?)のphpcli
コマンドを使うようにしました。あとインストール先が、/usr/local/bin
だと無理なので、パスが通っていた、ホームディレクトリ下のbinにしました。
スクリプト
#!/bin/sh
PHP_CMD="phpcli"
INSTALL_DIR="${HOME}/bin"
EXPECTED_CHECKSUM="$(wget -q -O - https://composer.github.io/installer.sig)"
${PHP_CMD} -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(${PHP_CMD} -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
${PHP_CMD} composer-setup.php --quiet --install-dir=${INSTALL_DIR} --filename=composer
RESULT=$?
rm composer-setup.php
exit $RESULT
コマンドやインストール先は変数にしたので、必要に応じて変更する感じになります。