Install script for MoinMoin-1.5.5.a

-----BEGIN WEBFACTION INSTALL SCRIPT-----
#!/usr/local/bin/python2.4

"""
MoinMoin-1.5.5.a install/uninstall script for WebFaction.
This installs the MoinMoin library in $HOME/lib/python2.4
and the MoinMoin CGI files in the webapp directory.

To prevent SPAM it removes the update rights for the anonymous
user and adds them for your username (you must create a MoinMoin
user with the same username in order to get these rights).

"autostart": not applicable
"extra info": leave empty
"""

"""
Command-line usage:
MoinMoin-1.5.5.a.py create|delete username pwd machine app_name autostart extra_info
"""

import xmlrpclib
import sys

def create(server, session_id, account, username, app_name, autostart, extra_info):
    home_dir = "%s/%s" % (account['home'], username)
    app_dir = '%s/webapps/%s' % (home_dir, app_name)

    # Create a simple static/cgi/php application
    new_app = server.create_app(session_id, app_name, 'static', False, '')

    # Get tarball and untar it
    cmd = """\
rm -f index.html
wget http://wiki.webfaction.com/attachment/wiki/MoinMoinFiles/moin-1.5.5a.tar.gz?format=raw > /dev/null 2>&1
tar xzvf moin-1.5.5a.tar.gz?format=raw > /dev/null 2>&1
cp -R moin-1.5.5a/MoinMoin %(home_dir)s/lib/python2.4
cp moin-1.5.5a/wiki/server/moin.cgi index.cgi
chmod 711 index.cgi .
cp moin-1.5.5a/wiki/config/wikiconfig.py .
cp -R moin-1.5.5a/wiki/data .
cp -R moin-1.5.5a/wiki/underlay .
cp -R moin-1.5.5a/wiki/htdocs wiki
""" % locals()
    server.system(session_id,  cmd)
    server.replace_in_file(session_id, 'index.cgi', (
            '/usr/bin/env python', '/usr/local/bin/python2.4'))
    # Remove update rights for anonymous user and add them for your username
    server.replace_in_file(session_id, 'wikiconfig.py', (
        '#acl_rights_before = u"YourName:read,write,delete,revert,admin"',
        'acl_rights_before = u"%(username)s:read,write,delete,revert,admin"\n    acl_rights_default = u"All:read"' % locals()))

    # 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 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-----