Skip to content

Instantly share code, notes, and snippets.

@MattLoyeD
Last active April 19, 2022 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattLoyeD/f910bf052f7371eb35810f9aac0e0d55 to your computer and use it in GitHub Desktop.
Save MattLoyeD/f910bf052f7371eb35810f9aac0e0d55 to your computer and use it in GitHub Desktop.
Update & Deploy tool for wordpress installations
#!/bin/sh
# Use it as sudoer for better results, not optimal I know
# Usage : cd /path && sudo sh wp-tools.sh deploy|update|push
# Deploy will go to dir and make databases updates along with chmod after git pull
# Update will update all components inside the wp install
# Push will create a commit and push it to origin/master
# Verify if wp cli is installed, installing if not
WP_FILE=/usr/local/bin/wp
if [ -f "$WP_FILE" ]; then
echo "$WP_FILE exists.";
echo "trying update the tool";
sudo wp cli update --allow-root;
else
echo "trying to install WP tool as it's not on the system already";
sudo curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar;
sudo chmod +x wp-cli.phar;
sudo mv wp-cli.phar /usr/local/bin/wp;
fi
# Check if worked and then use methods
if [ -f "$WP_FILE" ]; then
if [ $1 = "deploy" ]; then
sudo git pull origin master && sudo chmod 777 -R wp-content;
sudo wp core update-db --allow-root && sudo wp wc update --allow-root;
fi
if [ $1 = "update" ]; then
sudo wp plugin update --all --allow-root;
sudo wp core update --allow-root;
sudo wp core update-db --allow-root;
sudo wp theme update --all --allow-root;
sudo wp core language update --allow-root;
sudo wp language theme update --all --allow-root;
sudo wp language plugin update --all --allow-root;
fi
if [ $1 = "push" ]; then
sudo chmod 777 -R wp-content;
sudo git add -A;
sudo git commit;
sudo git push origin master;
fi
else
# WP tool not here, thats a bit sad
echo "No WP Cli installed, could not install it as well it seems";
fi
@MattLoyeD
Copy link
Author

Update 19/04/22 :

  • Adding push command
  • Changin CHMOD for wp-content root folder. Mainly for Autoptimize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment