Skip to content

Instantly share code, notes, and snippets.

@reneluria
Forked from ajaegers/inf-install-wp-cli.sh
Last active August 29, 2015 14:25
Show Gist options
  • Save reneluria/f7557c7dd2549c61fa62 to your computer and use it in GitHub Desktop.
Save reneluria/f7557c7dd2549c61fa62 to your computer and use it in GitHub Desktop.
One command to install WP-CLI on hosting using alias (if you cannot move wp-cli.phar in PATH)
#!/bin/bash
# initialy https://gist.github.com/ajaegers/d4c5286e52581821cb43
PATH=/opt/php/bin:/usr/bin:/bin
URL="https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar"
NAME="wp-cli.phar"
cd
if [ -d bin ] && [ -e bin/$NAME ]; then
echo "Error: WP-CLI already installed" >&2
exit 1
fi
echo '1. Downloading WP-CLI in ~/bin/...'
mkdir -p bin
pushd bin > /dev/null
if ! curl -O $URL; then
echo "Error: could not download $NAME" >&2
exit 1
fi
chmod +x $NAME
popd > /dev/null
echo '2. WP-CLI test...'
php bin/$NAME --info
echo '3. Making wp alias...'
if ! [ -e .bash_aliases ] || ! grep -q "^alias wp=" .bash_aliases; then
echo "alias wp='php ~/bin/$NAME'" >> .bash_aliases
fi
source ~/.bash_aliases
echo '4. Making bash wp alias to be available on each login...'
if ! [ -e .bash_profile ] || ! grep -q '\.bash_aliases' .bash_profile; then
cat >> ~/.bash_profile <<-EOD
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
EOD
fi
echo '5. Finished :)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment