-
Notifications
You must be signed in to change notification settings - Fork 11
/
composer
executable file
·47 lines (38 loc) · 1.32 KB
/
composer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
COMPOSERX_HOME=$HOME/.composerx
COMPOSERX_BIN=$COMPOSERX_HOME/bin
COMPOSERX_EXECUTABLE=$COMPOSERX_HOME/bin/composer
function __download_setup_php() {
# See:
# How do I install Composer programmatically? - Composer
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -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
}
function __rm_setup_php() {
rm -f composer-setup.php
}
function __install_composer() {
if [ ! -f $COMPOSERX_EXECUTABLE ]; then
if [ -f composer-setup.php ]; then
>&2 echo 'ERROR: Delete the existing composer-setup.php file before running this script'
exit 1
fi
__download_setup_php
trap __rm_setup_php EXIT
mkdir -p $COMPOSERX_BIN
php composer-setup.php --quiet --install-dir=$COMPOSERX_BIN --filename=composer
fi
}
function __main() {
__install_composer
$COMPOSERX_EXECUTABLE "$@"
}
__main "$@"