]> gitweb.fluxo.info Git - puppet-drupal.git/commitdiff
Drupal script: support for latest version and other enhancements
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 27 Oct 2017 20:48:25 +0000 (18:48 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 27 Oct 2017 20:48:25 +0000 (18:48 -0200)
files/drupal

index b22e893873c602f5d012e03f5e3f45459247aa03..30af12837041513106577c34eec21e5c9c608590 100755 (executable)
@@ -39,7 +39,7 @@ function drupal_get_major {
 function drupal_check_existing {
   if [ -e "$BASE/drupal-$1" ]; then
     echo "Folder $BASE/drupal-$1 already exists, skipping"
-    exit 1
+    exit
   fi  
 }
 
@@ -102,15 +102,17 @@ function drupal_iterate {
         fi
       fi
     done
-  
+
     # Fix permissions
-    #chown -R drupal.drupal $base/modules
-    #chown -R drupal.drupal $base/themes
-    #if [ -e "$base/sites/all/modules" ]; then
-    #  chown -R drupal.drupal $base/sites/all/modules
-    #fi
-    #if [ -e "$base/sites/all/themes" ]; then
-    #  chown -R drupal.drupal $base/sites/all/themes
+    #if [ "`whoami`" == "root" ]; then
+    #  chown -R drupal.drupal $base/modules
+    #  chown -R drupal.drupal $base/themes
+    #  if [ -e "$base/sites/all/modules" ]; then
+    #    chown -R drupal.drupal $base/sites/all/modules
+    #  fi
+    #  if [ -e "$base/sites/all/themes" ]; then
+    #    chown -R drupal.drupal $base/sites/all/themes
+    #  fi
     #fi
   done
 }
@@ -141,23 +143,48 @@ function drupal_update {
   done
 }
 
+# Get the latest version of a given series
+# https://drupal.stackexchange.com/questions/23700/how-to-find-download-latest-drupal-version-via-bash#23704
+function drupal_latest {
+  latest="`wget -O- -q https://updates.drupal.org/release-history/drupal/${1}.x | grep -oPm1 "(?<=<download_link>)[^<]+" | head -1`"
+  latest="`basename $latest`"
+
+  echo $latest | sed -e 's/^drupal-//' -e 's/.tar.gz$//'
+}
+
 # Deploy a fresh drupal tree
 function drupal_download {
   if [ -z "$1" ]; then
     echo "Usage: `basename $0` download <version> [--upgrade]"
     exit 1
+  else
+    new="$1"
+  fi
+
+  # Check for latest releases if no specific version was given
+  if [ "$new" == "8" ]; then
+    drupal_series="8"
+    new="`drupal_latest 8`"
+  elif [ "$new" == "7" ]; then
+    drupal_series="7"
+    new="`drupal_latest 7`"
+  elif [ "$new" == "6" ]; then
+    drupal_series="6"
+    new="`drupal_latest 6`"
+  else
+    drupal_series="`drupal_get_major $new`"
   fi
 
-  # Setup
-  new="$1"
-  drupal_series="`drupal_get_major $new`"
   cd $BASE
   drupal_check_existing $new
 
   # 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 drupal.drupal drupal-$new/
+
+  if [ "`whoami`" == "root" ]; then
+    chown -R drupal.drupal drupal-$new/
+  fi
 
   # Upgrade mode, erase sites folder as the previous should be copied.
   if [ "$2" == "--upgrade" ]; then
@@ -230,7 +257,7 @@ function drupal_upgrade {
   fi
 
   # Change symlink to point to the new location
-  cd $BASE ; rm -rf drupal-$drupal_series && ln -s drupal-$new drupal-$drupal_series
+  cd $BASE ; rm -rf drupal-$drupal_series && ln -sf drupal-$new drupal-$drupal_series
 
   # Done
   echo "Audit: `du -hs drupal-$old`"
@@ -264,6 +291,14 @@ function drupal_make {
   fi
 }
 
+# Ensure base is absolute
+if [ ! -d "$BASE" ]; then
+  echo "Folder $BASE does not exist"
+  exit 1
+else
+  BASE="`cd $BASE &> /dev/null && pwd`"
+fi
+
 # Main procedure
 if [ -z "$1" ]; then
   echo "Usage: `basename $0` <cron|download|update|updatedb|upgrade|run|make> [arguments]"