]> scripts.mit.edu Git - wizard.git/blob - wizard/app/phpBB.py
c8fa1f591d9bb4627e55a4e094e7b1132213ecc6
[wizard.git] / wizard / app / phpBB.py
1 import shutil
2 import logging
3 import os.path
4 import distutils.version
5
6 from wizard import app, install, resolve, sql, util
7 from wizard.app import php
8
9 #phpBB                104 installs
10 #    2.0.19            87  ++++++++++++++++++++++++++++++
11 #    3.0.4             17  ++++++
12
13 CONFIG = 'config.php'
14 def make_filename_regex(var):
15     """See :ref:`versioning config <seed>` for more information."""
16     return CONFIG, php.re_var(var)
17
18 seed = util.dictmap(make_filename_regex, {
19         'WIZARD_DBSERVER' : 'dbhost',
20         'WIZARD_DBNAME' : 'dbname',
21         'WIZARD_DBUSER' : 'dbuser',
22         'WIZARD_DBPASSWORD' : 'dbpasswd' })
23
24 class Application(app.Application):
25     install_schema = install.ArgSchema('db', 'admin', 'email', 'title')
26     database = 'mysql'
27     parametrized_files = [ CONFIG ] + php.parametrized_files
28     extractors = app.make_extractors(seed)
29     extractors.update(php.extractors)
30     substitutions = app.make_substitutions(seed)
31     substitutions.update(php.substitutions)
32
33     def checkConfig(self, deployment):
34         return os.path.getsize('config.php')
35
36     def detectVersion(self, deployment):
37         version = str(self.detectVersionFromFile('install/update_to_latest.php', php.re_var('updates_to_version')))
38         if version.startswith('.'): # blehh, but phpBB2 uses '.0.19'...
39             version = '2' + version
40         return distutils.version.LooseVersion(version)
41
42     @app.throws_database_errors
43     def remove(self, deployment, options):
44         sql.drop(deployment.dsn)
45
46     def install(self, version, options):
47         old_mode = os.stat(".").st_mode
48         os.chmod("config.php", 0777)
49         self.install_2(options)
50         os.chmod("config.php", old_mode)
51         php.ini_replace_vars()
52
53     def install_2(self, options):
54         database_dict = {
55                 'lang' : 'english',
56                 'dbms' : 'mysql',
57                 'upgrade' : '0',
58                 'dbhost' : options.dsn.host,
59                 'dbname' : options.dsn.database,
60                 'dbuser' : options.dsn.username,
61                 'dbpasswd' : options.dsn.password,
62                 'prefix' : '',
63                 'board_email' : options.email,
64                 'server_name' : options.web_host,
65                 'server_port' : '80',
66                 'script_path' : options.web_path,
67                 'admin_name' : options.admin_name,
68                 'admin_pass1' : options.admin_password,
69                 'admin_pass2' : options.admin_password,
70                 'install_step' : '1',
71                 'cur_lang' : 'english' }
72
73         result = install.fetch(options, 'install/install.php', database_dict)
74         logging.debug('install.php output:\n\n' + result)
75         if 'Thank you' not in result:
76             raise app.InstallFailure()
77         # Removing these trees will make upgrade merges annoying.  Maybe
78         # we should patch out the check and stick .htaccess files which
79         # block access for these folders (we'd probably have to make it
80         # available again for an upgrade though)
81         #shutil.rmtree('install')
82         #shutil.rmtree('contrib')
83
84     def install_3(self, options):
85         def install_helper(sub, post):
86             uri = 'install/index.php?mode=install&language=en'
87             if sub:
88                 uri += '&sub=%s' % sub
89             result = install.fetch(options, uri, post)
90             logging.debug('%s (%s) output:\n\n' % (uri, sub) + result)
91             return result
92
93         # *deep breath*
94         install_helper('', {})
95         install_helper('requirements', {})
96
97         database_dict = { 'img_imagick' : '/usr/bin/' }
98         install_helper('database', database_dict)
99
100         database_dict.update({
101                 'dbms' : 'mysql',
102                 'dbhost' : options.mysql_host,
103                 'dbname' : options.mysql_db,
104                 'dbuser' : options.mysql_user,
105                 'dbpasswd' : options.mysql_password,
106                 'table_prefix' : '',
107                 'img_imagick' : '/usr/bin/',
108                 'language' : 'en',
109                 'testdb' : 'true' })
110         install_helper('database', database_dict)
111
112         database_dict['dbport'] = ''
113         del database_dict['testdb']
114         install_helper('administrator', database_dict)
115
116         database_dict.update({
117                 'default_lang' : 'en',
118                 'admin_name' : options.admin_name,
119                 'admin_pass1' : options.admin_password,
120                 'admin_pass2' : options.admin_password,
121                 'board_email1' : options.email,
122                 'board_email2' : options.email,
123                 'check' : 'true' })
124         install_helper('administrator', database_dict)
125
126         del database_dict['check']
127         install_helper('config_file', database_dict)
128         install_helper('advanced', database_dict)
129
130         database_dict.update({
131                 'email_enable' : '1',
132                 'smtp_delivery' : '0',
133                 'smtp_auth' : 'PLAIN',
134                 'cookie_secure' : '0',
135                 'force_server_vars' : '0',
136                 'server_protocol' : 'http://',
137                 'server_name' : options.web_host,
138                 'server_port' : '80',
139                 'script_path' : options.web_path })
140         install_helper('create_table', database_dict)
141
142         database_dict.update({
143                 'ftp_path' : '',
144                 'ftp_user' : '',
145                 'ftp_pass' : '',
146                 'smtp_host' : '',
147                 'smtp_user' : '',
148                 'smtp_pass' : '' })
149         install_helper('final', database_dict)