aboutsummaryrefslogtreecommitdiff
path: root/templates/drupal-upgrade.sh.erb
blob: 670a6e54f8094808c36502434ef023eb63323084 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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."