## These variable should be set in Bitbucket repository
## If you want to try in local system without bitbucket pipeline
## You can do so with update variable value
## One thing is required collect Aws ssh key for ssh connect
## Create a ssh key in Aws server and add public key in your bitbucket account
## Otherwise this code will not work
# export WP_PROD_ROOT_PATH="/var/www/html/pipelines/wp-testing";\
# export DB_NAME_PROD="wppipelineprod";\
# export DB_USER="root";\
# export DB_PASS="123456";\
# export WP_PROD_ROOT_URL="http://domain/wp-prod";\
# export AWSDOMAINANDUSER="ec2-user@awsdomain";\
# export GITURL="git@bitbucket.org:username/wp-pipeline.git";\
# export LOCALURL="http://localhost/wp-pipeline";\
## End Bitbucket variable
ssh $AWSDOMAINANDUSER '
export WP_PROD_ROOT_PATH="'$WP_PROD_ROOT_PATH'";\
export DB_NAME_PROD="'$DB_NAME_PROD'";\
export DB_USER="'$DB_USER'";\
export DB_PASS="'$DB_PASS'";\
export WP_PROD_ROOT_URL="'$WP_PROD_ROOT_URL'";\
export GITURL="'$GITURL'";\
export LOCALURL="'$LOCALURL'";\
if [ wp core version --path=$WP_PROD_ROOT_PATH ]
then
echo "already Setup"
else
echo "Setup starting" ;\
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
git clone $GITURL $WP_PROD_ROOT_PATH --progress ; \
wp core download --path=$WP_PROD_ROOT_PATH; \
wp core config --dbname=$DB_NAME_PROD --dbuser=$DB_USER --dbpass=$DB_PASS --dbhost=localhost --path=$WP_PROD_ROOT_PATH; \
wp db create --path=$WP_PROD_ROOT_PATH; \
wp db import $WP_PROD_ROOT_PATH/db/db.txt --path=$WP_PROD_ROOT_PATH; \
fi
wp search-replace $LOCALURL $WP_PROD_ROOT_URL --path=$WP_PROD_ROOT_PATH; \
';