]> gitweb.fluxo.info Git - puppet-drupal.git/commitdiff
Using a single drupal management script
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 29 Dec 2009 20:12:10 +0000 (18:12 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 29 Dec 2009 20:12:10 +0000 (18:12 -0200)
manifests/init.pp
templates/drupal-deploy.sh.erb [deleted file]
templates/drupal-update.sh.erb [deleted file]
templates/drupal-upgrade.sh.erb [deleted file]
templates/drupal.sh.erb [new file with mode: 0644]

index 47a9a06559b6ae331a61c4fa8b43a8ac571e14c8..1a8334a1dbc31293ab25239e8e7ea3b9251c8eb8 100644 (file)
@@ -9,29 +9,11 @@ class drupal inherits pear {
       ensure => installed,
   }
 
-  # Drupal update script
-  file { "/usr/local/sbin/drupal-update.sh":
+  # Drupal management script
+  file { "/usr/local/sbin/drupal":
     ensure  => present,
-    content => template('drupal/drupal-update.sh.erb'),
-    user    => root,
-    group   => root,
-    mode    => 755,
-  }
-
-  # Drupal upgrade script
-  file { "/usr/local/sbin/drupal-upgrade.sh":
-    ensure  => present,
-    content => template('drupal/drupal-upgrade.sh.erb'),
-    user    => root,
-    group   => root,
-    mode    => 755,
-  }
-
-  # Drupal deployment script
-  file { "/usr/local/sbin/drupal-deploy.sh":
-    ensure  => present,
-    content => template('drupal/drupal-deploy.sh.erb'),
-    user    => root,
+    content => template('drupal/drupal.sh.erb'),
+    owner   => root,
     group   => root,
     mode    => 755,
   }
diff --git a/templates/drupal-deploy.sh.erb b/templates/drupal-deploy.sh.erb
deleted file mode 100644 (file)
index e7b51ae..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-#
-# Deploy a fresh drupal tree.
-#
-
-if [ "$#" != "1" ]; then
-  echo "Usage: `basename $0` <version>"
-  exit 1
-fi
-
-NEW="$1"
-BASE="<%= $apache_www_folder %>"
-
-cd $BASE
-
-# Deploy a fresh drupal tree
-wget http://ftp.drupal.org/files/projects/drupal-$NEW.tar.gz
-tar zxvf drupal-$NEW.tar.gz && rm drupal-$NEW.tar.gz
-chown -R root.root drupal-$NEW/
-cd drupal-$NEW && rm -rf sites
diff --git a/templates/drupal-update.sh.erb b/templates/drupal-update.sh.erb
deleted file mode 100644 (file)
index 75e8381..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-#
-# This file is used to update all drupal instances in the host.
-#
-
-for version in 5 6; do
-  # Setup base and sites folders
-  base="<%= $apache_www_folder %>/drupal-$version"
-  cd $base/sites
-  drupals="`ls -I default -I all`"
-
-  # Issue updates
-  for drupal in $drupals; do
-    # Ignore symlinks so sites are updated just once
-    if [ ! -h $drupal ]; then
-      echo "Processing $drupal..."
-      drush -l $drupal update
-    fi
-  done
-
-  # Fix permissions
-  chown -R root.root $base/sites/all/modules
-  chown -R root.root $base/sites/all/themes
-done
diff --git a/templates/drupal-upgrade.sh.erb b/templates/drupal-upgrade.sh.erb
deleted file mode 100644 (file)
index 670a6e5..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/bash
-#
-# Upgrade a drupal instance using upstream source.
-#
-
-if [ "$#" != "2" ]; then
-  echo "Usage: `basename $0` <old_version> <new_version>"
-  exit 1
-fi
-
-function get_major {
-  echo $1 | sed -e 's/\(^.\).*/\1/'
-}
-
-OLD="$1"
-NEW="$2"
-OLD_MAJOR="`get_major $OLD`"
-NEW_MAJOR="`get_major $NEW`"
-BASE="<%= $apache_www_folder %>"
-EXTRA_FOLDERS=""
-
-if [ "$OLD_MAJOR" != "$NEW_MAJOR" ]; then
-  echo "Major versions doesn't match"
-  exit 1
-fi
-
-# Set drupal series
-if [ "$NEW_MAJOR" == "4" ]; then
-  # Get minor versions
-  NEW_MINOR="`echo $NEW | sed -e "s/^$NEW_MAJOR\.//"`"
-  OLD_MINOR="`echo $OLD | sed -e "s/^$OLD_MAJOR\.//"`"
-
-  if [ "$OLD_MINOR" != "$NEW_MINOR" ]; then
-    echo "Minor versions doesn't match"
-    exit 1
-  fi
-  DRUPAL_SERIES="$NEW_MAJOR.$MINOR"
-else
-  DRUPAL_SERIES="$NEW_MAJOR"
-fi
-
-cd $BASE
-
-# Deploy a fresh drupal tree
-drupal-deploy.sh $NEW
-
-# Copy files
-cp -Rp ../drupal-$OLD/{.htaccess,favicon.ico,files/,sites/} . &> /dev/null
-for extra_folder in $EXTRA_FOLDERS; do
-  if [ -d ../drupal-$OLD/$extra_folder ]; then
-    cp -Rp ../drupal-$OLD/$extra_folder .
-  fi
-done
-
-# Legacy stuff for Drupal 4.x.x
-if [ "$NEW_MAJOR" == "4" ]; then
-  rsync -av ../drupal-$OLD/themes/ themes/
-  for module in `ls ../drupal-$OLD/modules`; do
-    if [ -d "../drupal-$OLD/modules/$module" ]; then
-      cp -Rp ../drupal-$OLD/modules/$module modules/
-    fi
-  done
-fi
-
-# Copy installation profiles for Drupal 5.x or newer
-if [ "$NEW_MAJOR" != "4" ]; then
-  rsync -av --exclude=default ../drupal-$OLD/profiles/ profiles/
-fi
-
-# Change symlink to point to the new location
-cd $BASE ; rm drupal-$DRUPAL_SERIES && ln -s drupal-$NEW drupal-$DRUPAL_SERIES
-
-# Done
-echo "Check procedure and remove drupal-$OLD once you make sure that everything is fine."
diff --git a/templates/drupal.sh.erb b/templates/drupal.sh.erb
new file mode 100644 (file)
index 0000000..ac44da5
--- /dev/null
@@ -0,0 +1,137 @@
+#!/bin/bash
+#
+# Drupal management script.
+#
+
+BASE="<%= $apache_www_folder %>"
+SERIES="5 6"
+
+# Get drupal major version
+function get_major {
+  echo $1 | sed -e 's/\(^.\).*/\1/'
+}
+
+# Deploy a fresh drupal tree
+function drupal_deploy {
+  if [ "$#" != "1" ]; then
+    echo "Usage: `basename $0` deploy <version>"
+    exit 1
+  fi
+
+  # Setup
+  new="$1"
+  cd $BASE
+
+  # Deploy a fresh drupal tree
+  wget http://ftp.drupal.org/files/projects/drupal-$new.tar.gz
+  tar zxvf drupal-$new.tar.gz && rm drupal-$new.tar.gz
+  chown -R root.root drupal-$new/
+  cd drupal-$new && rm -rf sites
+}
+
+# Update all drupal instances in the host
+function drupal_update {
+  for version in $SERIES; do
+    # Setup base and sites folders
+    base="$BASE/drupal-$version"
+    cd $base/sites
+    drupals="`ls -I default -I all`"
+  
+    # Issue updates
+    for drupal in $drupals; do
+      # Ignore symlinks so sites are updated just once
+      if [ ! -h $drupal ]; then
+        echo "Processing $drupal..."
+        drush -l $drupal update
+      fi
+    done
+  
+    # Fix permissions
+    chown -R root.root $base/sites/all/modules
+    chown -R root.root $base/sites/all/themes
+  done
+}
+
+# Upgrade a drupal instance using upstream source.
+function drupal_upgrade {
+  if [ "$#" != "2" ]; then
+    echo "Usage: `basename $0` upgrade <old_version> <new_version>"
+    exit 1
+  fi
+
+  # Setup
+  old="$1"
+  new="$2"
+  old_major="`get_major $old`"
+  new_major="`get_major $new`"
+  extra_folders=""
+  
+  if [ "$old_major" != "$new_major" ]; then
+    echo "Major versions doesn't match"
+    exit 1
+  fi
+  
+  # Set drupal series
+  if [ "$new_MAJOR" == "4" ]; then
+    # Get minor versions
+    new_minor="`echo $new | sed -e "s/^$new_major\.//"`"
+    old_minor="`echo $old | sed -e "s/^$old_major\.//"`"
+  
+    if [ "$old_minor" != "$new_minor" ]; then
+      echo "Minor versions doesn't match"
+      exit 1
+    fi
+    drupal_series="$new_MAJOR.$MINOR"
+  else
+    drupal_series="$new_MAJOR"
+  fi
+  
+  cd $BASE
+  
+  # Deploy a fresh drupal tree
+  drupal_deploy $new
+  
+  # Copy files
+  cp -Rp ../drupal-$old/{.htaccess,favicon.ico,files/,sites/} . &> /dev/null
+  for extra_folder in $extra_folders; do
+    if [ -d ../drupal-$old/$extra_folder ]; then
+      cp -Rp ../drupal-$old/$extra_folder .
+    fi
+  done
+  
+  # Legacy stuff for Drupal 4.x.x
+  if [ "$new_MAJOR" == "4" ]; then
+    rsync -av ../drupal-$old/themes/ themes/
+    for module in `ls ../drupal-$old/modules`; do
+      if [ -d "../drupal-$old/modules/$module" ]; then
+        cp -Rp ../drupal-$old/modules/$module modules/
+      fi
+    done
+  fi
+  
+  # Copy installation profiles for Drupal 5.x or newer
+  if [ "$new_MAJOR" != "4" ]; then
+    rsync -av --exclude=default ../drupal-$old/profiles/ profiles/
+  fi
+  
+  # Change symlink to point to the new location
+  cd $BASE ; rm drupal-$drupal_series && ln -s drupal-$new drupal-$drupal_series
+  
+  # Done
+  echo "Check procedure and remove drupal-$old once you make sure that everything is fine."
+}
+
+# Main procedure
+if [ -z "$1" ]; then
+  echo "Usage: `basename $0` <command> [arguments]"
+  exit 1
+elif [ "$1" == "deploy" ]; then
+  shift
+  drupal_deploy $*
+elif [ "$1" == "update" ]; then
+  shift
+  drupal_update $*
+elif [ "$1" == "upgrade" ]; then
+  shift
+  drupal_upgrade $*
+fi