Skip to content
upgrade.sh.txt 5.23 KiB
Newer Older

########################################################################
# 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.
########################################################################

# Basic variables, change before running.
Herman van Rink's avatar
Herman van Rink committed
NEW_DRUSH_VERSION=7.0.0
# Extra variables, no changes needed for most use-cases.
BACKUP_DIR=$HOME/pre-upgrade-$(date '+%F-%H%M')

if [ "$AEGIR_VERSION" = "7.x-3.x" ]; then
  DRUPAL_DIR=$HOME/hostmaster-${AEGIR_VERSION}-$(date +'%F-%H%M')
else
  DRUPAL_DIR=$HOME/hostmaster-$AEGIR_VERSION
fi

########################################################################
# Functions

# Indent printed messages.
msg() {
  echo "==> $*"
}

# 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
}

########################################################################
# Preparation

# Test if we have Drush.
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"
  # we do not set DRUSH to `which drush` because we're not sure how 'which' will behave
  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`
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

# Detect the current Drush version to work with.
CURRENT_DRUSH_VERSION=`drush --version --pipe`
case "$CURRENT_DRUSH_VERSION" in
  5*)
  TEMPFILE=`mktemp`
  $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
  AEGIR_DOMAIN="$site_uri"
  OLD_DRUPAL_DIR="$drupal_root"
  ;;

  [67]*)
Herman van Rink's avatar
Herman van Rink committed
  AEGIR_DOMAIN=`drush @hostmaster status --fields="uri" --field-labels=0 | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*\$//g'`
  OLD_DRUPAL_DIR=`drush @hostmaster status --fields="root" --field-labels=0 | sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*\$//g'`


########################################################################
# 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
 * you have read http://community.aegirproject.org/upgrading and have prepared the server accordingly
 * you are executing this script as your "aegir" user
 * that the following settings are correct

The Aegir version to upgrade to is $AEGIR_VERSION
The Aegir home dir is $HOME
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"
if [ -w $DRUSH_DIR ]; then
  cat <<EOF
The version of Drush will be $NEW_DRUSH_VERSION
  echo "Drush will not be upgraded as its directory is not writable: $DRUSH_DIR"

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

# Upgrade drush if desired and writable.
if [ $NEW_DRUSH_VERSION != $CURRENT_DRUSH_VERSION ]; then
  if [ -w $DRUSH_DIR ]; then
    if [ -d $DRUSH_DIR ]; then
      msg "Moving existing drush into $BACKUP_DIR"
      mv $DRUSH_DIR $BACKUP_DIR
    fi
    cd $HOME
    wget http://github.com/drush-ops/drush/archive/${NEW_DRUSH_VERSION}.zip
    unzip ${NEW_DRUSH_VERSION}.zip
    rm ${NEW_DRUSH_VERSION}.zip
    mv drush-$NEW_DRUSH_VERSION $DRUSH_DIR
  else
    msg "Drush dir($DRUSH_DIR) is not writable, not upgrading Drush."
  fi
else
  mgs "Not upgrading Drush, $CURRENT_DRUSH_VERSION will be used."
# 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

if [ "$AEGIR_VERSION" = "7.x-3.x" ]; then
  git clone --branch "$AEGIR_VERSION" http://git.drupal.org/project/provision.git $HOME/.drush/provision
  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
# Clear the drush command cache.
# Start the actual upgrade of Aegir itself.
cd $OLD_DRUPAL_DIR
$DRUSH hostmaster-migrate $AEGIR_DOMAIN $DRUPAL_DIR

# All should be done.