summaryrefslogtreecommitdiff
path: root/files
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2016-01-19 16:08:12 -0200
committerSilvio Rhatto <rhatto@riseup.net>2016-01-19 16:08:12 -0200
commit6cafba803ba5db047209d471378b6d4734b95123 (patch)
tree3fd085f6e03edeb4a15dd9560b4557216c7d5582 /files
parent8e3d9bed30f3bb9e292a57d0f51cff5ac080a7c4 (diff)
downloadpuppet-wordpress-6cafba803ba5db047209d471378b6d4734b95123.tar.gz
puppet-wordpress-6cafba803ba5db047209d471378b6d4734b95123.tar.bz2
Simplify module
Diffstat (limited to 'files')
-rw-r--r--files/wordpress.sh160
1 files changed, 160 insertions, 0 deletions
diff --git a/files/wordpress.sh b/files/wordpress.sh
new file mode 100644
index 0000000..773eab7
--- /dev/null
+++ b/files/wordpress.sh
@@ -0,0 +1,160 @@
+#!/bin/bash
+#
+# wordpress management script.
+#
+
+BASE="/var/www/data"
+LOCALE="-pt_BR"
+WP_CLI="/usr/local/bin/wp-cli"
+BASENAME="`basename $0`"
+
+# Set alternative base
+function wordpress_set_base {
+ if [ ! -z "$1" ]; then
+ BASE="$1"
+
+ if [ ! -d "$BASE" ]; then
+ echo "No such folder $BASE"
+ exit 1
+ fi
+ fi
+}
+
+# Check for existing installations
+function wordpress_check_existing {
+ if [ -e "$BASE/wordpress-$1" ]; then
+ echo "Folder $BASE/wordpress-$1 already exists, skipping."
+ exit 1
+ fi
+}
+
+# Deploy a fresh wordpress tree
+function wordpress_deploy {
+ if [ -z "$1" ]; then
+ echo "Usage: `basename $0` deploy <version> [folder]"
+ exit 1
+ fi
+
+ # Setup
+ new="$1"
+ wordpress_set_base $2
+ wordpress_check_existing $new
+
+ # Deploy a fresh wordpress tree
+ cd $BASE
+ wget http://br.wordpress.org/wordpress-$new$LOCALE.zip
+ unzip wordpress-$new$LOCALE.zip && rm wordpress-$new$LOCALE.zip
+ mv wordpress wordpress-$new/
+ chown -R root.root wordpress-$new/
+}
+
+# Upgrade a wordpress instance using upstream source.
+function wordpress_upgrade {
+ if [ -z "2" ]; then
+ echo "Usage: `basename $0` upgrade <old_version> <new_version> [folder]"
+ exit 1
+ fi
+
+ # Setup
+ old="$1"
+ new="$2"
+ extra_folders=""
+ wordpress_set_base $3
+ wordpress_check_existing $new
+
+ cd $BASE
+
+ if [ ! -d "wordpress-$old" ]; then
+ echo "Installation not found: wordpress-$old"
+ exit
+ fi
+
+ cp -alf wordpress-$old wordpress-$old.backup
+
+ # Deploy a fresh wordpress tree
+ wordpress_deploy $new
+
+ # Copy files
+ for file in .htaccess wp-config.php; do
+ if [ -e "wordpress-$old/$file" ]; then
+ cp -a wordpress-$old/$file wordpress-$new/
+ fi
+ done
+
+ # Extra folders
+ for extra_folder in $extra_folders; do
+ if [ -d ../wordpress-$old/$extra_folder ]; then
+ cp -Rp ../wordpress-$old/$extra_folder .
+ fi
+ done
+
+ # Files
+ rsync -av wordpress-$old/wp-content/uploads/ wordpress-$new/wp-content/uploads/
+ rsync -av wordpress-$old/wp-content/blogs.dir/ wordpress-$new/wp-content/blogs.dir/
+
+ # Plugins
+ for plugin in `ls wordpress-$old/wp-content/plugins/`; do
+ if [ ! -e "wordpress-$new/wp-content/plugins/$plugin" ]; then
+ cp -r wordpress-$old/wp-content/plugins/$plugin wordpress-$new/wp-content/plugins/
+ fi
+ done
+
+ # Themes
+ for theme in `ls wordpress-$old/wp-content/themes/`; do
+ if [ ! -e "wordpress-$new/wp-content/themes/$theme" ]; then
+ cp -r wordpress-$old/wp-content/themes/$theme wordpress-$new/wp-content/themes/
+ fi
+ done
+
+ # Fix permissions
+ chown -R root.root wordpress-$new/wp-content/{plugins,themes}
+
+ # Set sunrise symlink
+ if [ -f "wordpress-$new/wp-content/plugins/wordpress-mu-domain-mapping/sunrise.php" ]; then
+ ( cd wordpress-$new/wp-content && ln -s plugins/wordpress-mu-domain-mapping/sunrise.php )
+ fi
+
+ # Change symlink to point to the new location
+ if [ -h "site" ]; then
+ link="`readlink site`"
+ if [ "`basename $link`" == "wordpress-$old" ]; then
+ rm site && ln -s wordpress-$new site
+ fi
+ fi
+
+ # Done
+ echo "Audit: `du -hs wordpress-$old`"
+ echo "Audit: `du -hs wordpress-$new`"
+ echo "Check procedure and remove wordpress-$old once you make sure that everything is fine."
+ echo "Then run 'wordpress core update-db'"
+}
+
+# Usage
+function wordpress_usage {
+ echo "Installation management commands:"
+ echo " $BASENAME deploy <version>"
+ echo " $BASENAME upgrade <old-version> <new-version>"
+ echo ""
+ echo -n "Wordpress CLI "
+ $WP_CLI help
+}
+
+# Main procedure
+if [ -z "$1" ]; then
+ wordpress_usage
+ exit 1
+elif [ "$1" == "deploy" ]; then
+ shift
+ wordpress_deploy $*
+elif [ "$1" == "upgrade" ]; then
+ shift
+ wordpress_upgrade $*
+elif [ "$1" == "help" ]; then
+ wordpress_usage
+#elif [ "$1" == "core" ]; then
+# echo "Please use deploy or upgrade instead."
+else
+ # Send all other requests to wp-cli
+ #$WP_CLI --path=$BASE/wordpress $*
+ $WP_CLI $*
+fi