egscripts/egdrupalhelpers/egdrupalmovesite

110 lines
2 KiB
Bash
Executable file

#!/bin/bash
PLATFORMDIR=/home/drupal/core
usage() {
cat <<EOT
Usage: `basename $0` servername oldplatform newplatform
Migrate drupal site servername from oldplatform to newplatform.
EXAMPLE
`basename $0` www.mysite.com drupal-6.15 drupal-6.16
EOT
}
if [ $# -ne 3 ] ; then
usage
exit 1
fi
servername=$1
currentplatform=$2
newplatform=$3
platform_dir() {
echo "$PLATFORMDIR/$1"
}
platform_exists() {
platform=$1
if [ -d "`platform_dir $platform`" ] ; then
return 0
else
return 1
fi
}
site_dir() {
echo "`platform_dir $2`/sites/$1"
}
site_exists() {
site=$1
platform=$2
if [ -z "$platform" ] || [ -z "$site" ] ; then
echo "Argument error: site_exists '$platform' '$site'" >&2
return 1
fi
dir=`site_dir $site $platform`
if [ -d "$dir" ] && [ ! -L "$dir" ] ; then
return 0
else
return 1
fi
}
findlinks() {
site=$1
platform=$2
find `platform_dir $platform`/sites -maxdepth 1 -lname "$site/" -or -lname "$site"
}
if ! platform_exists $currentplatform ; then
echo "Platform '$currentplatform' does not exist"
exit 1
fi
if ! platform_exists $newplatform ; then
echo "Platform '$newplatform' does not exist"
exit 1
fi
if [ "$currentplatform" == "$newplatform" ] ; then
echo "$currentplatform and $newplatform are the same platform!"
exit 1
fi
if ! site_exists $servername $currentplatform ; then
echo "$site does not exist under $platform/sites, or is not a directory"
exit 1
fi
# Check for any symlinks to the current dir
links=`findlinks $servername $currentplatform`
# Everything checked out, do the work
set -e
pushd `platform_dir $newplatform`/sites
# Create symlinks first
for link in $links ; do
sudo cp -va $link .
done
# Move the directory, and symlink from the old location
sudo mv -v `site_dir $servername $currentplatform` . && ln -v -s `site_dir $servername $newplatform` `site_dir $servername $currentplatform`
pushd `site_dir $servername $newplatform` && drush updatedb
popd
popd