From db6a27e1050630f9376dc2d118faa63d08cfeaa5 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Fri, 27 Oct 2017 18:48:25 -0200 Subject: Drupal script: support for latest version and other enhancements --- files/drupal | 63 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/files/drupal b/files/drupal index b22e893..30af128 100755 --- a/files/drupal +++ b/files/drupal @@ -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 "(?<=)[^<]+" | 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 [--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` [arguments]" -- cgit v1.2.3