-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomposer-install
executable file
·65 lines (50 loc) · 1.72 KB
/
composer-install
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
#---------------------------------------------------------------------
usage ()
{
cat <<EOT
${0##*/}
Provides a wrapper around \`composer install\` that takes into
account the availability of the composer executable, as well as
the presence or absence of a composer.json file. Can be safely
called even if these items are missing (with the result being
essentially a no-op and >0 exit code.)
There is a certain amount of irony in this script being
included in a composer package, since you would have had to
already run 'composer install' in order to have access to this
convenience script. If nothing else, this script exists here
as a copy/paste reference of how to achieve a certain amount
of gracefulness in running a tool that may or may not be
present.
Usage:
bin/${0##*/}
EOT
exit ${1:-0} # Exit with code 0 unless an arg is passed to the method.
}
if [ "$1" = '-h' ]; then
usage
fi
# Set up working vars.
COMPOSER_CONFIG_FILE="composer.json"
GUESSES=( "$( which composer )" "bin/composer" "$( which composer.phar )" "bin/composer.phar" )
# Bail out if there's no config file present.
if [ ! -e "$COMPOSER_CONFIG_FILE" ]; then
echo "!! No composer config file at '$COMPOSER_CONFIG_FILE'."
exit 2
fi
echo "## Found composer config at: ${COMPOSER_CONFIG_FILE}"
# Bail out if composer isn't available to us.
for GUESS in "$GUESSES"; do
if [ -x "$GUESS" ]; then
COMPOSER="$GUESS"
break
fi
done
if [ -z "$COMPOSER" ]; then
echo "!! The 'composer' command was not found on this system."
echo ""
exit 1
fi
echo "## Found composer at: ${COMPOSER}"
# Execute `composer install`
"$COMPOSER" install --no-interaction --ignore-platform-reqs --optimize-autoloader "$@"