Skip to content
upgrade.sh.txt 3.41 KiB
Newer Older
#! /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.
########################################################################

# basic variables, change before running
AEGIR_VERSION="0.4-alpha15"
AEGIR_DOMAIN=aegir.example.com

AEGIR_DIR=/var/aegir
DRUPAL_DIR=$AEGIR_DIR/hostmaster-$AEGIR_VERSION
DRUSH_VERSION=6.x-3.3
DRUSH_MAKE_VERSION=6.x-2.0-beta9
OLD_DRUPAL_DIR=$AEGIR_DIR/hostmaster-0.4-alpha14
DRUSH_DIR=$AEGIR_DIR/drush
DRUSH="php $DRUSH_DIR/drush.php"
BACKUP_DIR=$AEGIR_DIR/pre-upgrade-`date '+%F-%H%M'`

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

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

########################################################################
# 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 UPGRADE.txt and 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 $AEGIR_DIR
The new hostmaster platform will be $DRUPAL_DIR
The version of Drush is $DRUSH_VERSION
The version of Drush Make is $DRUSH_MAKE_VERSION
Your Aegir domain is $AEGIR_DOMAIN
Your old hostmaster platform was $OLD_DRUPAL_DIR
The Drush command is "$DRUSH"

EOF

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

# Can we check Drush version?
if [ -d $DRUSH_DIR ]; then
  msg "Moving existing drush into $BACKUP_DIR"
  mv $DRUSH_DIR $BACKUP_DIR
fi

cd $AEGIR_DIR
wget http://ftp.drupal.org/files/projects/drush-$DRUSH_VERSION.tar.gz 
gunzip -c drush-$DRUSH_VERSION.tar.gz | tar -xf -
rm drush-$DRUSH_VERSION.tar.gz

# 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" = "HEAD" ]; then
  git clone git://git.aegirproject.org/provision $HOME/.drush/provision
else
  wget http://files.aegirproject.org/provision-$AEGIR_VERSION.tgz
  gunzip -c provision-$AEGIR_VERSION.tgz | tar -xf -
  rm provision-$AEGIR_VERSION.tgz
fi

# fetch new version of drush_make
if [ `$DRUSH make --version | grep "$DRUSH_MAKE_VERSION" ` ] ; then
  msg "Correct version of Drush Make already seems to be installed."
else
  cd $HOME/.drush
  if [ -d "drush_make" ] ; then
    msg "Moving existing drush_make into $BACKUP_DIR"
    mv drush_make $BACKUP_DIR
  fi
  $DRUSH dl drush_make-$DRUSH_MAKE_VERSION --destination="$HOME/.drush"
fi

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