#!/bin/bash
###############################################
# Official centminmod.com addon: wpcli.sh installer
# written by George Liu (eva2000) vbtechsupport.com
###############################################
# http://wp-cli.org/
# WP-CLI is a set of command-line tools for managing WordPress 
# installations. You can update plugins, set up multisite installs, 
# create posts etc
###############################################
# install instructions
# chmod +x /usr/local/src/centmin-v1.2.3mod/addons/wpcli.sh
# cd /usr/local/src/centmin-v1.2.3mod/addons
# ./wpcli.sh install
###############################################
# functions

installwpcli() {

yum -q -y install git

if [[ ! -f /root/.composer/bin/wp ]]; then

echo ""
curl http://wp-cli.org/installer.sh | bash
echo ""

WPCLICHECK=$(grep 'WP-CLI' /root/.bash_profile)

if [[ -z "$WPCLICHECK" ]]; then
	echo ""
	echo "" >> /root/.bash_profile
	echo "# Composer scripts" >> /root/.bash_profile
	echo "PATH=$HOME/.wp-cli/bin:$PATH" >> /root/.bash_profile
	echo "" >> /root/.bash_profile
	echo "# WP-CLI completions" >> /root/.bash_profile
	echo "source $HOME/.wp-cli/vendor/wp-cli/wp-cli/utils/wp-completion.bash" >> /root/.bash_profile
fi

echo "-------------------------------------------------------------"
/root/.wp-cli/bin/wp --info
echo "-------------------------------------------------------------"

echo ""
echo "-------------------------------------------------------------"
echo "wp-cli install completed"
echo "Read http://wp-cli.org/ for full usage info"

echo ""
echo "-------------------------------------------------------------"
echo "Please log out of SSH session and log back in"
echo "You can then call wp-cli via command: wp"
echo "i.e. wp --info"
echo "-------------------------------------------------------------"

fi

}

###############################################

case "$1" in
install)
installwpcli
;;
*)
echo "$0 install"
;;
esac

exit