-----BEGIN WEBFACTION INSTALL SCRIPT-----
"""
Joomla-1.0.12 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.
After accessing the URL for the first time you need to delete
the "installation" directory and edit configuration.php and
replace "http://your_joomla_site.com" with your actual URL
"autostart": not applicable
"extra info": choose the database password, which will also be the Joomla admin user password
"""
"""
Command-line usage:
joomla-1.0.12.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):
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)
new_app = server.create_app(session_id, app_name, 'static', False, '')
cmd = "rm -f index.html;" cmd += "wget http://wiki.webfaction.com/attachment/wiki/JoomlaFiles/Joomla_1.0.12-Stable-Full_Package.tar.gz?format=raw > /dev/null 2>&1;"
cmd += "tar xzvf Joomla_1.0.12-Stable-Full_Package.tar.gz?format=raw > /dev/null 2>&1;"
server.system(session_id, cmd)
password = extra_info
db_name = '%s_%s' % (username, app_name)
server.create_db(session_id, db_name, 'mysql', password)
joomla_sql = 'installation/sql/joomla.sql'
server.replace_in_file(session_id, joomla_sql, ('#__', 'jos_'))
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')
cmd = """mysql -u %(db_name)s --password=%(password)s %(db_name)s < %(joomla_sql)s;""" % locals()
cmd += """cp configuration.php-dist configuration.php;""" % locals()
server.system(session_id, cmd)
server.replace_in_file(session_id, 'configuration.php',
("$mosConfig_user = '';", "$mosConfig_user = '%(db_name)s';" % locals()),
("$mosConfig_db = '';", "$mosConfig_db = '%(db_name)s';" % locals()),
("$mosConfig_password = '';", "$mosConfig_password = '%(password)s';" % locals()),
("$mosConfig_absolute_path = '/path/to/joomla/install';", "$mosConfig_absolute_path = '%(app_dir)s';" % locals()),
("$mosConfig_cachepath = '/path/to/joomla/install/cache';", "$mosConfig_cachepath = '%(app_dir)s/cache';" % locals()))
print new_app['id']
def delete(server, session_id, account, username, app_name, autostart, extra_info):
db_name = '%s_%s' % (username, app_name)
server.delete_db(session_id, db_name, 'mysql')
server.delete_app(session_id, app_name)
if __name__ == '__main__':
command, username, password, machine, app_name, autostart, extra_info = sys.argv[1:]
url = 'https://api.webfaction.com/'
server = xmlrpclib.ServerProxy(url)
session_id, account = server.login(username, password, machine)
method = locals()[command] method(server, session_id, account, username, app_name, autostart, extra_info)
-----END WEBFACTION INSTALL SCRIPT-----