Created
September 29, 2018 01:36
-
-
Save keriat/f10d16d1bc3cc1eb4fc5d78fc95474f9 to your computer and use it in GitHub Desktop.
Wordpress Bedrock git deployment update file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
WP_ENV=production | |
FORCE=0 | |
source .env | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-f) | |
FORCE=1 | |
;; | |
--help) | |
echo "***************************" | |
echo "Usage:" | |
echo " ./update.sh [-f]" | |
echo "" | |
echo "Options:" | |
echo " -f force update" | |
echo "***************************" | |
;; | |
*) | |
echo "***************************" | |
echo "* Error: Invalid argument ${1}" | |
echo "***************************" | |
exit 1 | |
esac | |
shift | |
done | |
PHP_VERSION=$(php -v | grep "PHP 5" | sed 's/.*PHP \([^-]*\).*/\1/' | cut -c 1-3) | |
echo "Installed PHP version: '$PHP_VERSION'" | |
git fetch origin | |
# check git updates | |
GIT_CHANGED=false | |
CURENT_BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | |
if [ -n "`git diff HEAD origin/${CURENT_BRANCH}`" ]; then GIT_CHANGED=true; fi; | |
if [ ${FORCE} == 0 ]; then | |
if [ ${GIT_CHANGED} == false ]; then | |
echo 'Already up-to-date' | |
exit | |
fi | |
fi; | |
if [ ${WP_ENV} == 'development' ]; | |
then | |
git pull origin ${CURENT_BRANCH} | |
else | |
git reset --hard origin/${CURENT_BRANCH} | |
fi; | |
# composer | |
COMPOSER_OPT='' | |
if [ ${WP_ENV} != 'development' ]; | |
then | |
COMPOSER_OPT="-o --no-dev" | |
fi; | |
composer install ${COMPOSER_OPT} --prefer-dist | |
composer dump-autoload --optimize ${COMPOSER_OPT} | |
if [ ${WP_ENV} != 'production' ]; | |
then | |
vendor/wp-cli/wp-cli/bin/wp option update scripts_version "`date +'%s'`" | |
vendor/wp-cli/wp-cli/bin/wp transient delete --all | |
vendor/wp-cli/wp-cli/bin/wp w3-total-cache flush all | |
fi; | |
# image optimizer | |
#echo 'Image optimization' | |
#find web/app/uploads -type f -name "*.jpg" -exec jpegoptim --strip-all -q {} \; | |
#find web/app/uploads -type f -name "*.jpeg" -exec jpegoptim --strip-all -q {} \; | |
#find web/app/uploads -type f -name "*.png" -exec optipng -nc -nb -o2 -quiet {} \; | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment