#!/bin/bash # # wordpress management script. # BASE="<%= wordpress_folder %>" LOCALE="<%= real_wordpress_locale %>" # 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 [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 [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 -a 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 for extra_folder in $extra_folders; do if [ -d ../wordpress-$old/$extra_folder ]; then cp -Rp ../wordpress-$old/$extra_folder . fi done # Exclusions exclude_plugins="--exclude=akismet --exclude=hello.php --exclude=index.php" exclude_themes="--exclude=index.php --exclude=twentytwelve --exclude=twentyeleven --exclude=twentyten" # Files, Plugins and Themes rsync -av wordpress-$old/wp-content/blogs.dir/ wordpress-$new/wp-content/blogs.dir/ rsync -av $exclude_plugins wordpress-$old/wp-content/plugins/ wordpress-$new/wp-content/plugins/ rsync -av $exclude_themes wordpress-$old/wp-content/themes/ wordpress-$new/wp-content/themes/ # Fix permissions chown -R root.root wordpress-$new/wp-content/{plugins,themes} # Change symlink to point to the new location #cd $BASE ; rm -f blogs && ln -s wordpress-$new blogs # 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." } # Main procedure if [ -z "$1" ]; then echo "Usage: `basename $0` [arguments]" exit 1 elif [ "$1" == "deploy" ]; then shift wordpress_deploy $* elif [ "$1" == "upgrade" ]; then shift wordpress_upgrade $* fi