forked from wp-cli/wp-cli.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
executable file
·102 lines (83 loc) · 2.02 KB
/
installer.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
find_php() {
read -r -d '' AMP_PATHS <<EOB
/Applications/MAMP/bin/php5.3/bin/php
/Applications/MAMP/bin/php/*/bin/php
/Applications/xampp/xamppfiles/bin/php
/opt/lampp/bin/php
EOB
# Special case for *AMP installers, since they normally don't set themselves
# as the default cli php out of the box.
for amp_php in $AMP_PATHS; do
if [[ "$amp_php" == *php5.2* ]]; then
continue
fi
if [ -x $amp_php ]; then
echo $amp_php
exit
fi
done
which php || which php-cli || return 1
}
if [ -z "$INSTALL_DIR" ]; then
INSTALL_DIR=$HOME/.wp-cli
fi
if [ -z "$VERSION" ]; then
VERSION='@stable'
fi
# Find a PHP binary
if [ -z "$WP_CLI_PHP" ]; then
WP_CLI_PHP=`find_php`
if [ $? -gt 0 ]; then
read -p "path to PHP binary: " WP_CLI_PHP
fi
else
command -v $WP_CLI_PHP > /dev/null || {
echo "invalid PHP binary: $WP_CLI_PHP" 1>&2
exit 1
}
fi
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
# install Composer
if [ ! -x composer.phar ]; then
echo "Installing Composer in $INSTALL_DIR"
echo "-------------------"
curl -sS https://getcomposer.org/installer | $WP_CLI_PHP
if [ $? -gt 0 ]; then
exit 1
fi
fi
COMPOSER="$WP_CLI_PHP composer.phar"
# set up global composer.json file
if [ ! -f composer.json ]; then
$COMPOSER init --stability dev --no-interaction
$COMPOSER config bin-dir bin
$COMPOSER config vendor-dir vendor
$COMPOSER config repositories.wp-cli composer http://wp-cli.org/package-index/
fi
command -v bin/wp > /dev/null || {
echo
echo "Installing WP-CLI in $INSTALL_DIR"
echo "-----------------"
$COMPOSER require --prefer-source wp-cli/wp-cli="$VERSION"
if [ $? -gt 0 ]; then
echo "WP-CLI was not successfully installed."
exit 1
else
echo
echo "WP-CLI files have been successfully installed."
fi
}
cat <<EOB
To test WP-CLI, run:
"$INSTALL_DIR"/bin/wp --info
Make sure you have the following line in your .bash_profile file:
# WP-CLI directory
export PATH="$INSTALL_DIR/bin:\$PATH"
EOB
if [ "$WP_CLI_PHP" != "$(which php)" ]; then
cat <<EOB
export WP_CLI_PHP=$WP_CLI_PHP
EOB
fi