I took several hours to work through the MyComponent component. It was most impressive but we elected not to use it. Duplicating the customized settings looked pretty straightforward. Renesting the menus and moving them around looked a little more challenging but the killer was the subpackages. If I read the script correctly, they would be downloaded but not installed. Since we have well over 100 installed, I did not want to have us clicking on scores of Install buttons to set up a new client.
Instead, we developed this procedure. Would anyone care to cast an eye on it to see if we got it right. As a caveat from the beginning, the script will need to be adapted, e.g., pacifera.com www.pacifera.com are two separate sites right now (we are re-evaluating that decision) so we do not make any domain dependent changes to .htaccess but we do rename it to something else for security reasons. Thus, there is no reference to .htaccess in the script.
It assumes all clients are peers of the base installation in the file system, that the web server runs as the user apache, and several settings in the preferences such as site_name=MODXBase and
[email protected].
Here is the (expunged) procedure and script from our internal documentation:
This procedure will create a client MODx instance for either public or private access from a template MODx installation.
Enter the manager interface for the base site (
http://modx.mycompany.com/manager)
Clear the cache: Site --> Clear Cache
clear the error log: Reports --> Error Log
and clear sessions: Security --> Flush All Sessions
We next need to run the client creation script. One will need the following information:
database user name
database user password
database name
web site host name, e.g., www.mycompany.com
web site name, e.g., MySite
email contact address
database administrator password
Once we have that information, we can run the script:
cd /usr/local/modx
./newclientmodx <client ID> , e.g., ./newlicentmodx clientA
Once this is finished, go to the web site setup URI for the site, e.g., www.mycompany.com/setup and run it as an upgrade. Check the delete setup files on the last page.
Change the client's administrator user username and password
Make any customizations to the settings.
Here is the newclientmodx script:
#!/bin/bash
# Copyright 2011 - John A. Sullivan III / Pacifera, LP
# newclientmodx creates a new client instance of MODx from a MODx template site
# Collect the information; the Client ID is optionally passed on the command line
DBHOST="-h mysql.mycompany.com "
CID=${1}
if [ -z "${CID}" ];then
read -p "Please enter the client ID: " CID
fi
echo
read -p "Please enter the database user name: " DBUSER
echo
match=0
while [ ${match} -eq 0 ]
do
read -s -p "Please enter the database user password (characters will not display): " DBPW
echo
read -s -p "Please re-enter the database user password for confirmation (characters will not display): " DBPW2
echo
if [ "${DBPW}" = "${DBPW2}" ]; then
match=1
else
echo "Passwords do not match; please try again."
echo
fi
done
echo
read -p "Please enter the database name: " DBNAME
echo
read -p "Please enter the web site host name, e.g., www.pacifera.com : " URL
echo
read -p "Please enter the web site name, e.g., Pacifera: " SNAME
echo
read -p "Please enter the email contact address: " EMAIL
echo
# Setup the database
echo "Please enter the database administrator password when prompted. This will happen three times."
mysqldump ${DBHOST}-u root -p -e --single-transaction modxbase > ${CID}.sql
if [ $? -ne 0 ];then
echo "I could not dump the base database."
exit 4
fi
sed -i -e "s/\(\usr\/local\/modx\/\)modx\//\1${CID}\//g" -e "s/admin@mycompany\.com/${EMAIL}/g" -e "s/MODXBase/${SNAME}/g" ${CID}.sql
echo "Please enter the database administrator password again when prompted."
mysql ${DBHOST}-u root -p -e "create database ${DBNAME};grant all on ${DBNAME}.* to ${DBUSER} identified by '${DBPW}';"
if [ $? -ne 0 ];then
echo "I could not create the new database or grant needed permissions."
exit 4
fi
echo "Please enter the database administrator password for the last time when prompted."
mysql ${DBHOST}-u root -p ${DBNAME} < ${CID}.sql
if [ $? -ne 0 ];then
echo "I could not import the new client database."
exit 4
fi
# Create the file system
cp -a modx "${CID}" && chown -R apache:apache "${CID}"
if [ $? -ne 0 ];then
echo "I could not create the new client file system or set proper permissions."
exit 4
fi
cd "${CID}"
sed -i -e "s/^\(\$database_user = '\).*;/\1${DBUSER}\';/" -e "s/^\(\$database_password = '\).*;/\1${DBPW}\';/" -e "s/^\(\$dbase = '\).*;/\1${DBNAME}\';/" -e "s/\(;dbname=\)[^
if [ $? -ne 0 ];then
echo -e "I could not edit the new client file system;\nit is not safe to use the system until the new client\nfile system is destroyed and recreated without errors."
fi
IFSORIG=${IFS}
IFS=$'\n'
sed -i "s/\(\usr\/local\/modx\/\)modx\//\1${CID}\//g" $(grep -rl *)
if [ $? -ne 0 ];then
echo -e "I could not edit the new client file system;\nit is not safe to use the system until the new client\nfile system is destroyed and recreated without errors."
fi
IFS=${IFSORIG}
echo
echo "Please now point a browser to ${URL}/setup and run the upgrade routine."
echo