From 6cafba803ba5db047209d471378b6d4734b95123 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 19 Jan 2016 16:08:12 -0200 Subject: Simplify module --- files/wordpress.sh | 160 +++++++++++++++++++++++++++++++++++++++++++++ manifests/init.pp | 27 ++++---- templates/wordpress.sh.erb | 158 -------------------------------------------- 3 files changed, 174 insertions(+), 171 deletions(-) create mode 100644 files/wordpress.sh delete mode 100644 templates/wordpress.sh.erb 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 [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 -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 " + echo " $BASENAME upgrade " + 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 diff --git a/manifests/init.pp b/manifests/init.pp index 423b3ba..9af4b97 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,29 +1,30 @@ -class wordpress( - $folder = '/var/www/data', - $locale = hiera('wordpress::locale', '') -) { - - $real_wordpress_locale = $locale ? { - '' => '', - default => "-${locale}" - } - +class wordpress { file { "/usr/local/sbin/wordpress": ensure => present, - content => template('wordpress/wordpress.sh.erb'), + source => "puppet:///modules/wordpress/wordpress.sh", owner => root, group => root, mode => 755, } + # Composer + exec { 'getwp': + command => '/usr/bin/wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/local/bin/wp-cli', + user => 'root', + cwd => '/tmp', + creates => '/usr/local/bin/wp-cli', + } + + # TODO: remove in the future file { "/usr/local/sbin/wp": - ensure => '/usr/local/sbin/wordpress', + ensure => absent, owner => root, group => root, } + # TODO: remove in the future vcsrepo { "/usr/local/share/wp-cli": - ensure => present, + ensure => absent, provider => git, source => 'git://github.com/wp-cli/wp-cli.git', revision => 'b30a0745ef5ffe1c9f2a4d9a021aef213a78c867', diff --git a/templates/wordpress.sh.erb b/templates/wordpress.sh.erb deleted file mode 100644 index 052543c..0000000 --- a/templates/wordpress.sh.erb +++ /dev/null @@ -1,158 +0,0 @@ -#!/bin/bash -# -# wordpress management script. -# - -BASE="<%= 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 -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 " wp deploy " - echo " wp upgrade " - echo "" - echo -n "Wordpress CLI " - /usr/local/share/wp-cli/bin/wp 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 - #/usr/local/share/wp-cli/src/bin/wp --path=$BASE/wordpress $* - /usr/local/share/wp-cli/bin/wp $* -fi -- cgit v1.2.3