Install script for Joomla-1.5.6
-----BEGIN WEBFACTION INSTALL SCRIPT-----
#!/usr/local/bin/python2.4
"""
Joomla-1.5.6 install/uninstall script for WebFaction.
This installs the Joomla PHP files in the webapp directory.
It also creates a database and configures Joomla with the
database settings.
"autostart": not applicable
"extra info": choose the database password, which will also be the Joomla admin user password
"""
"""
Command-line usage:
joomla-1.5.6.py create|delete username pwd machine app_name autostart extra_info
"""
import md5
import xmlrpclib
import sys
def create(server, session_id, account, username, app_name, autostart, extra_info):
# Validate extra_info
if len(extra_info) < 4:
print "The password (extra info) must be at least 4 characters long"
return
home_dir = "%s/%s" % (account['home'], username)
app_dir = '%s/webapps/%s' % (home_dir, app_name)
# Create simple "static/CGI/php" app
new_app = server.create_app(session_id, app_name, 'static', False, '')
# Get Joomla tarball and untar it
# Note that we redirect all output to /dev/null
cmd = "rm -f index.html;" # This file would shadow index.php
cmd += "wget http://wiki.webfaction.com/attachment/wiki/JoomlaFiles/Joomla-1.5.6.tar.gz?format=raw > /dev/null 2>&1;"
cmd += "tar xzvf Joomla-1.5.6.tar.gz?format=raw > /dev/null 2>&1;"
server.system(session_id, cmd)
# Create database using "extra_info" as the password
password = extra_info
db_name = '%s_%s' % (username, app_name)
server.create_db(session_id, db_name, 'mysql', password)
# Replace "#__" with "jos_" in joomla.sql file
joomla_sql = 'installation/sql/mysql/joomla.sql'
server.replace_in_file(session_id, joomla_sql, ('#__', 'jos_'))
sample_data = 'installation/sql/mysql/sample_data.sql'
server.replace_in_file(session_id, sample_data, ('#__', 'jos_'))
# Append SQL commands to create admin user at the end of joomla.sql
pwdhash = md5.new(password).hexdigest()
admin_user_queries = """
INSERT INTO `jos_users` VALUES (62, 'Administrator', 'admin', 'your-email@email.com', '%(pwdhash)s', 'Super Administrator', 0, 1, 25, '2005-09-28 00:00:00', '2005-09-28 00:00:00', '', '');
INSERT INTO `jos_core_acl_aro` VALUES (10,'users','62',0,'Administrator',0);
INSERT INTO `jos_core_acl_groups_aro_map` VALUES (25,'',10);
""" % locals()
server.write_file(session_id, joomla_sql, admin_user_queries, 'ab')
# Run joomla.sql file from mysql. This will create the tables and add the admin user
cmd = """mysql -u %(db_name)s --password=%(password)s %(db_name)s < %(joomla_sql)s;""" % locals()
cmd += """mysql -u %(db_name)s --password=%(password)s %(db_name)s < %(sample_data)s;""" % locals()
# Copy sample config file to real one
cmd += """cp configuration.php-dist configuration.php;""" % locals()
# Configure DB variables, secret key and cachepath in config file
cmd += r'''sed -i "s/var \$user = '';/var \$user = '%(db_name)s';/" configuration.php;'''%locals()
cmd += r'''sed -i "s/var \$password = '';/var \$password = '%(password)s';/" configuration.php;'''%locals()
cmd += r'''sed -i "s/var \$db = '';/var \$db = '%(db_name)s';/" configuration.php;'''%locals()
cmd += r'''sed -i "s/var \$secret = '';/var \$secret = '%(password)s';/" configuration.php;'''%locals()
cmd += r'''sed -i "s@var \$cachepath = '';@var \$cachepath = '%(app_dir)s/cache';@" configuration.php;'''%locals()
cmd += r'''rm -rf installation;'''
server.system(session_id, cmd)
# We return the id of the new app
print new_app['id']
def delete(server, session_id, account, username, app_name, autostart, extra_info):
# Delete database
db_name = '%s_%s' % (username, app_name)
server.delete_db(session_id, db_name, 'mysql')
# Delete app
server.delete_app(session_id, app_name)
if __name__ == '__main__':
# Parse command line arguments
command, username, password, machine, app_name, autostart, extra_info = sys.argv[1:]
# Connect to API server
url = 'https://api.webfaction.com/'
server = xmlrpclib.ServerProxy(url)
# Login
session_id, account = server.login(username, password, machine)
# Call create or delete method
method = locals()[command] # create or delete
method(server, session_id, account, username, app_name, autostart, extra_info)
-----END WEBFACTION INSTALL SCRIPT-----