151 lines
3.5 KiB
Bash
Executable file
151 lines
3.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
PLATFORMDIR=/home/drupal/core
|
|
DBHOST=mysql0
|
|
DEVGROUP=drupaladm
|
|
VHOSTSVNBASE=http://devel.egressive.com/egressive/egpuppet/trunk/virtualhosts/dev
|
|
ADDPUPPETCONF=0
|
|
FIXMISSING=1
|
|
|
|
usage() {
|
|
cat <<EOT
|
|
|
|
Usage: `basename $0` [ OPTIONS ] siteuri svnuri platform
|
|
|
|
Deploy a Drupal site to the specified docroot.
|
|
|
|
OPTIONS
|
|
|
|
-h - Show this help
|
|
-l - List available platforms
|
|
-d dbhost - Specify an alternative database host (Default: $DBHOST)
|
|
-u user - Site will be owned by user (Default: $USER)
|
|
|
|
EOT
|
|
}
|
|
|
|
[ -f "/etc/egscripts/egdrupaldeploy.conf" ] && . /etc/egscripts/egdrupaldeploy.conf
|
|
|
|
while getopts "d:u:hl" OPT ; do
|
|
case $OPT in
|
|
d) DBHOST=$OPTARG ;;
|
|
u) SITEUSER=$OPTARG ;;
|
|
l) ls -1 $PLATFORMDIR ; exit 0 ;;
|
|
h) usage ; exit 0 ;;
|
|
*) usage ; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
if [ $# -ne 3 ] ; then
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
user=${SITEUSER-$USER}
|
|
siteuri=$1
|
|
svnuri=$2
|
|
platform=$3
|
|
docroot=$PLATFORMDIR/$platform
|
|
group=`id -g $user`
|
|
|
|
# Do some sanity checks
|
|
if [ -z "$docroot" ] ; then
|
|
echo "Err: Cannot find docroot for platform $platform" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d $docroot ] || [ ! -f "$docroot/update.php" ] ; then
|
|
echo "Err: $docroot does not look like a valid Drupal DocumentRoot" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! id $user > /dev/null ; then
|
|
echo "Err: User $user does not exist" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! getent group $group ; then
|
|
echo "Err: Group id $group does not exist" >&2
|
|
exit 1
|
|
fi
|
|
|
|
sitedir=$docroot/sites/$siteuri
|
|
|
|
if [ -d "$sitedir" ] ; then
|
|
echo "$sitedir already exists" >&2
|
|
exit 1
|
|
fi
|
|
|
|
set -e
|
|
|
|
# Checkout the site code
|
|
svn co $svnuri $sitedir
|
|
|
|
# Create a database for the user
|
|
dbname=`echo "${user}__${platform}__${siteuri}" | sed -e 's/\./_/g'`
|
|
|
|
ret=`egmakedb -H $DBHOST $user $dbname`
|
|
eval "$ret"
|
|
|
|
# Generate the site settings.php
|
|
# Default for D6
|
|
default_settings=$docroot/sites/default/default.settings.php
|
|
if [ ! -f $default_settings ] ; then
|
|
# Default for D5
|
|
default_settings=$docroot/sites/default/settings.php
|
|
fi
|
|
|
|
# Create a drushrc.php
|
|
cat <<EOT > $sitedir/drushrc.php
|
|
<?php
|
|
\$options['site_url'] = '$siteuri';
|
|
EOT
|
|
|
|
if [ ! -f $default_settings ] ; then
|
|
echo "Unable to find default settings file in $docroot/sites/default/" >&2
|
|
exit 1
|
|
fi
|
|
|
|
settings=$sitedir/settings.php
|
|
sed -e "s/^\$db_url.*/\$db_url = 'mysql:\/\/$DBUSER:$DBPASS@$DBHOST\/$DBNAME';/" $default_settings > $settings
|
|
|
|
cat >> $settings <<EOT
|
|
// Include local settings file if present
|
|
if (file_exists(dirname(__FILE__) .'/settings.local.php')) {
|
|
require_once(dirname(__FILE__) .'/settings.local.php');
|
|
}
|
|
EOT
|
|
|
|
mkdir -v $sitedir/files
|
|
|
|
# Fix missing module symlinks, if any
|
|
if [ $FIXMISSING -eq 1 ] && [ -d "$sitedir/modules" ] ; then
|
|
pushd $sitedir/modules
|
|
egdrupalsymlinks -m
|
|
fi
|
|
|
|
# Make all site dirs and file readable by the web user
|
|
egsetdiracls $sitedir
|
|
# Make files directory writeable by the web user
|
|
egsetdiracls -w $sitedir/files
|
|
# Make all site files writeable by the site owner
|
|
egsetdiracls -w -u $user $sitedir
|
|
# Make all site files writeable by the site owners primary group
|
|
egsetdiracls -w -u $group $sitedir
|
|
# Make all site files writeable by the developer group
|
|
egsetdiracls -w -g $DEVGROUP $sitedir
|
|
|
|
if [ "$ADDPUPPETCONF" -eq 1 ] ; then
|
|
# Create a virtualhost configuration file
|
|
tmpfile=`mktemp /tmp/egdrupaldeploy-XXXXXX`
|
|
cat > $tmpfile <<EOT
|
|
virtualhost { "$siteuri":
|
|
documentroot => "$docroot",
|
|
owner => "$user",
|
|
}
|
|
EOT
|
|
svn import -m "egdrupaldeploy: Auto Puppet vhost conf ($siteuri)" $tmpfile $VHOSTSVNBASE/$siteuri.pp
|
|
rm -v $tmpfile
|
|
fi
|