1+ #! /usr/bin/env bash
2+ # beporter@users.sourceforge.net
3+
4+ # ---------------------------------------------------------------------
5+ usage ()
6+ {
7+ cat << EOT
8+
9+ ${0##*/ }
10+ Wrapper around composer to make it "aware" of a custom
11+ \` COMPOSER_NODEV\` environment variable. If that variable is set
12+ when this script is executed, the ` --no-dev` flag will be prepended
13+ to the command line arguments. All arguments to this script are
14+ passed directly through to composer, except for -h which displays
15+ this wrapper script's help text. (Use \` --help\` to get composer's
16+ help.)
17+
18+ For this script to work effectively, you should be in the habit of
19+ calling \` composer\` (without the ".phar" and with the file available
20+ in your PATH already.)
21+
22+ This version of the script is "insidious" in that it will install
23+ itself in place of an existing composer binary. It's also capable of
24+ installing the real composer for you if it isn't already available,
25+ making it a drop-in replacement for the regular composer install
26+ instructions. Is this dangerous? Yup, it sure is. Should you trust
27+ this script? Probably not. To understand why it exists, see:
28+ https://github.com/composer/composer/issues/4408
29+
30+ To install composer and this wrapper, execute the following
31+ EXTREMELY DANGEROUS command from your system's command line:
32+
33+ $ curl -sS https://raw.githubusercontent.com/loadsys/CakePHP-Shell-Scripts/master/composer > composer && bash composer >/dev/null
34+
35+ NOTE: You may need to use \` sudo bash composer\` in the above command.
36+
37+ Usage:
38+ ${0##*/ } [options] [arguments]
39+
40+
41+ EOT
42+
43+ exit ${1:- 0} # Exit with code 0 unless an arg is passed to the method.
44+ }
45+ if [ " $1 " = ' -h' ]; then
46+ usage
47+ fi
48+
49+ COMPOSER_DEFAULT_PATH=" /usr/local/bin/composer"
50+
51+ # If there's already a `composer` in PATH, make sure it isn't already
52+ # THIS wrapper, and replace it with this wrapper.
53+ COMPOSER_WRAPPER=" $( which composer) "
54+ if [ -n " $COMPOSER_WRAPPER " ] && ! grep -q " COMPOSER_WRAPPER" " $COMPOSER_WRAPPER " ; then
55+ echo " Replacing existing $COMPOSER_WRAPPER with wrapper script $0 " >&2
56+ mv " $COMPOSER_WRAPPER " " ${COMPOSER_WRAPPER} .phar"
57+ mv " $0 " " ${COMPOSER_WRAPPER} "
58+ chmod a+x " ${COMPOSER_WRAPPER} "
59+ elif [ -z " $COMPOSER_WRAPPER " ]; then
60+ COMPOSER_WRAPPER=" $COMPOSER_DEFAULT_PATH "
61+ echo " Installing composer wrapper script as ${COMPOSER_WRAPPER} " >&2
62+ mv " $0 " " ${COMPOSER_WRAPPER} "
63+ chmod a+x " ${COMPOSER_WRAPPER} "
64+ fi
65+
66+ # If there isn't already a composer.phar executable, download and install it.
67+ COMPOSER_BINARY=" $( which composer.phar) "
68+ if [ -z " $COMPOSER_BINARY " ]; then
69+ COMPOSER_BINARY=" ${COMPOSER_WRAPPER} .phar"
70+ echo " composer.phar not found in PATH. Installing as $COMPOSER_BINARY " >&2
71+ curl -sS https://getcomposer.org/installer | \
72+ php -- --install-dir=${COMPOSER_BINARY%/* } --filename=${COMPOSER_BINARY##*/ }
73+ fi
74+
75+ # Execute the "real" composer with all args and all piped/redirected input.
76+ " $COMPOSER_BINARY " ${COMPOSER_NODEV+" --no-dev" } " $@ " < & 0
0 commit comments