upgrade.sh.txt 4.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#! /bin/sh

# $Id$

########################################################################
# Aegir quick upgrade script
#
# This script also *DOES NOT CHECK* if the requirements have been met.
# It's up to the admin to follow the proper upgrade instructions or use
# the packages provided by their platform.
########################################################################

13 14 15 16
msg() {
  echo "==> $*"
}

17
# basic variables, change before running
18
AEGIR_VERSION="6.x-2.x"
19
DRUSH_DIR=$HOME/drush
20 21 22
DRUSH=$DRUSH_DIR/drush.php
if which drush 2> /dev/null > /dev/null && which drush | grep -v 'no drush in' > /dev/null; then
  msg "Drush is in the path, good"
23
  # we do not set DRUSH to `which drush` because we're not sure how 'which' will behave
24
  DRUSH=drush
25 26 27 28 29 30
  DRUSH_DIR=`which drush`
  # yes, this will fail on non-GNU readlink, but we don't care - it
  # just means drush won't be upgraded if it's the path on those
  # platforms
  DRUSH_DIR=`readlink -f $DRUSH_DIR`
  DRUSH_DIR=`dirname $DRUSH_DIR`
31 32 33 34 35 36 37 38
elif [ -x $DRUSH ] ; then
  msg "Drush found in $DRUSH, good"
  DRUSH="php $DRUSH"
else
  msg "Could not find drush in $DRUSH or in $PATH"
  exit 1
fi

39
TEMPFILE=`mktemp`
40 41 42 43 44 45 46 47 48
$DRUSH --pipe @hostmaster status | egrep "site_uri|drupal_root" >> $TEMPFILE || true
if grep -q 'site_uri' $TEMPFILE; then
    # this sources the result of drush --pipe so we initialise shell variables used later
    . $TEMPFILE
else
    msg 'could not find running hostmaster site'
    msg 'try running "drush @hostmaster status" to diagnose and repair'
    exit 1
fi
49

50 51
AEGIR_DOMAIN="$site_uri"
OLD_DRUPAL_DIR="$drupal_root"
52 53
HOME="$HOME"
DRUPAL_DIR=$HOME/hostmaster-$AEGIR_VERSION
54
DRUSH_VERSION=5.10.0
55
BACKUP_DIR=$HOME/pre-upgrade-`date '+%F-%H%M'`
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

########################################################################
# functions

# simple prompt
prompt_yes_no() {
  while true ; do
    printf "$* [Y/n] "
    read answer
    if [ -z "$answer" ] ; then
      return 0
    fi
    case $answer in
      [Yy]|[Yy][Ee][Ss])
        return 0
        ;;
      [Nn]|[Nn][Oo])
        return 1
        ;;
      *)
        echo "Please answer yes or no"
        ;;
    esac
 done 
}

########################################################################
# Main script

AEGIR_HOST=`uname -n`
AEGIR_DOMAIN=${1:-$AEGIR_DOMAIN}

msg "Aegir $AEGIR_VERSION automated upgrade script"

if [ `whoami` = "root" ] ; then
  msg "This script should be run as the aegir user, not as root."
  exit 1
fi

msg "This script makes the following assumptions: "
cat <<EOF
97
 * you have read http://community.aegirproject.org/upgrading and have prepared the server accordingly
98 99 100 101
 * you are executing this script as your "aegir" user
 * that the following settings are correct

The Aegir version to upgrade to is $AEGIR_VERSION
102
The Aegir home dir is $HOME
103 104 105 106
The new hostmaster platform will be $DRUPAL_DIR
Your Aegir domain is $AEGIR_DOMAIN
Your old hostmaster platform was $OLD_DRUPAL_DIR
The Drush command is "$DRUSH"
107
EOF
108

109 110 111
if [ -w $DRUSH_DIR ]; then
  cat <<EOF
The version of Drush will be $DRUSH_VERSION
112
EOF
113
else
114
  echo "Drush will not be upgraded as its directory is not writable: $DRUSH_DIR"
115
fi
116 117 118 119 120 121 122 123 124 125

if prompt_yes_no "Do you want to proceed with the upgrade?" ; then
  true
else
  echo "Upgrade aborted by user."
  exit 1
fi

mkdir -p $BACKUP_DIR

126 127 128 129 130 131 132
if [ -w $DRUSH_DIR ]; then
  # Can we check Drush version?
  if [ -d $DRUSH_DIR ]; then
    msg "Moving existing drush into $BACKUP_DIR"
    mv $DRUSH_DIR $BACKUP_DIR
  fi

133
  cd $HOME
134 135 136 137
  wget http://github.com/drush-ops/drush/archive/$DRUSH_VERSION.zip
  unzip $DRUSH_VERSION.zip
  rm $DRUSH_VERSION.zip
  mv drush-$DRUSH_VERSION $DRUSH_DIR
138 139 140 141 142 143 144 145 146 147 148
fi

# fetch new version of provision
# move existing provision
cd $HOME/.drush

if [ -d "provision" ] ; then
  msg "Moving existing provision into $BACKUP_DIR"
  mv provision $BACKUP_DIR
fi

Steven Jones's avatar
Steven Jones committed
149
if [ "$AEGIR_VERSION" = "6.x-2.x" ]; then
150
  git clone --branch "$AEGIR_VERSION" http://git.drupal.org/project/provision.git $HOME/.drush/provision
151
else
152 153 154
  wget http://ftp.drupal.org/files/projects/provision-$AEGIR_VERSION.tar.gz
  gunzip -c provision-$AEGIR_VERSION.tar.gz | tar -xf -
  rm provision-$AEGIR_VERSION.tar.gz
155 156
fi

157 158 159
# Clear the drush command cache
drush cache-clear drush

160 161
cd $OLD_DRUPAL_DIR
$DRUSH hostmaster-migrate $AEGIR_DOMAIN $DRUPAL_DIR