Created
September 26, 2012 18:58
-
-
Save yyolk/3789855 to your computer and use it in GitHub Desktop.
Webfaction - MediaWiki - 1.19 Install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN WEBFACTION INSTALL SCRIPT----- | |
#!/usr/local/bin/python2.4 | |
""" | |
MediaWiki 1.8.2 | |
Requirements: | |
- 1 MySQL database. | |
Notes: | |
- The database will be named after your application. | |
- The default username and password are "WikiSysop" and "Password". | |
"autostart": not applicable | |
"extra info": enter the name of the wiki followed by the URL path of the wiki. For instance: | |
MyWiki /wiki | |
or: | |
'My wiki' / | |
""" | |
import re | |
import random | |
import string | |
import sys | |
import xmlrpclib | |
def arg_split(arg): | |
new_args = [] | |
while True: | |
arg = arg.strip() | |
if arg == '': | |
break | |
if (arg[0] != '"') and (arg[0] != "'"): | |
new_arg = re.split(' ', arg)[0] | |
arg = re.sub('^%s' % new_arg, '', arg) | |
else: | |
separator = arg[0] | |
arg = arg[1:] | |
new_arg = re.split(separator, arg)[0] | |
arg = re.sub('^%s%s' % (new_arg, separator), '', arg) | |
new_args.append(new_arg) | |
continue | |
return new_args | |
def create(account, app_name, autostart, extra_info, password, server, session_id, username): | |
# Parse and validate arguments. | |
db_name = db_user = '%s_%s' % (username, app_name) | |
try: | |
name, path = arg_split(extra_info) | |
except ValueError: | |
print 'Extra info is invalid.' | |
return | |
name, path = name.strip(), path.strip() | |
if path == '/': | |
path = '' | |
name = re.sub('"', r'\"', name) | |
# Create application and database. | |
app = server.create_app(session_id, app_name, 'static', False, '') | |
server.create_db(session_id, db_name, 'mysql', password) | |
# Download files. | |
cmd = '' | |
cmd += 'rm index.html;' | |
cmd += 'wget http://download.wikimedia.org/mediawiki/1.19/mediawiki-1.19.2.tar.gz > /dev/null 2>&1;' | |
cmd += 'tar zxf mediawiki-1.19.2.tar.gz > /dev/null 2>&1;' | |
cmd += 'rm mediawiki-1.19.2.tar.gz' | |
server.system(session_id, cmd) | |
# Edit configuration. | |
characters = string.lowercase + string.digits | |
proxy_key = '' | |
for i in range(1, 65): | |
proxy_key += random.choice(characters) | |
server.replace_in_file(session_id, 'LocalSettings.php', | |
('$wgDBname = "";', '$wgDBname = "%s";' % db_name), | |
('$wgDBpassword = "";', '$wgDBpassword = "%s";' % password), | |
('$wgDBuser = "";', '$wgDBuser = "%s";' % db_user), | |
('$wgProxyKey = "";', '$wgProxyKey = "%s";' % proxy_key), | |
('$wgScriptPath = "";', '$wgScriptPath = "%s";' % path), | |
('$wgSitename = "";', '$wgSitename = "%s";' % name) | |
) | |
# Populate database. | |
cmd = '' | |
cmd += 'mysql --password=%s --user=%s %s < schema.sql;' % (password, db_user, db_name) | |
cmd += 'rm schema.sql;' | |
server.system(session_id, cmd) | |
print app['id'] | |
def delete(account, app_name, autostart, extra_info, password, server, session_id, username): | |
# Delete application and database. | |
server.delete_app(session_id, app_name) | |
try: | |
server.delete_db(session_id, '%s_%s' % (username, app_name), 'mysql') | |
except: | |
pass | |
if __name__ == '__main__': | |
action, username, password, machine, app_name, autostart, extra_info = sys.argv[1:] | |
server = xmlrpclib.ServerProxy('https://api.webfaction.com/') | |
session_id, account = server.login(username, password, machine) | |
func = locals()[action] | |
func(account, app_name, autostart, extra_info, password, server, session_id, username) | |
-----END WEBFACTION INSTALL SCRIPT----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment