# HG changeset patch # User Paul Boddie # Date 1341930234 -7200 # Node ID a5aec502083f078246b718f25b8f7324e0633d83 # Parent f423c8325972b32f03c1aae2c77407297d226b04 Added support for separate static resources URL paths. Fixed .htaccess positioning where static resource directories are in use. Added edit/event log file ownership/permissions configuration in the postinstall scripts. diff -r f423c8325972 -r a5aec502083f README.txt --- a/README.txt Sat Oct 15 23:58:51 2011 +0200 +++ b/README.txt Tue Jul 10 16:23:54 2012 +0200 @@ -107,8 +107,7 @@ web_static_dir A directory from which static resources are to be served. This directory need only be specified in a limited hosting - environment (see below for more details), and only for - MoinMoin 1.8. + environment (see below for more details). web_site_dir The directory where sites available to the Apache Web server are defined. This directory may just be a place @@ -135,6 +134,12 @@ url_path The URL path (after the host details) of the Wiki. +static_url_path The URL path (after the host details) of the Wiki's static + resources. This is only required if a limited hosting + environment enforces separate "htdocs" and "cgi-bin" + directories, and the static resources must be placed in + the "htdocs" directory. + superuser The superuser of the Wiki. site_name The name of the Wiki. @@ -176,9 +181,13 @@ web_static_dir = /path/to/www/htdocs web_site_dir = +url_path = /mysite/cgi-bin +static_url_path = /mysite + If the web_static_dir setting is left blank, the static resources will be placed alongside the CGI script. Some environments have .cgi files served as -CGI scripts and other files served statically. +CGI scripts and other files served statically; in such cases, static_url_path +can also be left blank. Inside the directory used to hold static resources, a subdirectory will be created to hold the static content used by MoinMoin. @@ -277,6 +286,16 @@ CMDsyntax Tested with 0.91 Source: http://www.boddie.org.uk/david/Projects/Python/CMDSyntax/index.html +New in moinsetup 0.4 (Changes since moinsetup 0.3) +-------------------------------------------------- + + * Added edit and event log permissions/ownership commands to the postinstall + scripts. + * Fixed the .htaccess file location for limited hosting environments, using + the static resources directory in preference to the application directory. + * Added support for separate static URL paths enforced by limited hosting + environments. + New in moinsetup 0.3 (Changes since moinsetup 0.2) -------------------------------------------------- diff -r f423c8325972 -r a5aec502083f moinsetup.py --- a/moinsetup.py Sat Oct 15 23:58:51 2011 +0200 +++ b/moinsetup.py Tue Jul 10 16:23:54 2012 +0200 @@ -3,7 +3,7 @@ """ A setup and configuration script for MoinMoin. -Copyright (C) 2010, 2011 Paul Boddie +Copyright (C) 2010, 2011, 2012 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -57,23 +57,31 @@ """ apache_site_extra = """ -Alias %(static_url_path)s "%(htdocs_dir)s/" +Alias %(static_url_resources_path)s "%(htdocs_dir)s/" """ # Limited hosting .htaccess definitions require the following settings to be -# configured in the main Apache configuration files: +# configured in the main Apache configuration files for the directory where +# .htaccess is to be deployed: +# +# AllowOverride FileInfo Limit # -# Options ExecCGI FollowSymLinks Indexes SymLinksIfOwnerMatch -# AllowOverride FileInfo Limit +# The following settings are required for the directory where the moin.cgi +# script is to be deployed: +# +# Options ExecCGI FollowSymLinks SymLinksIfOwnerMatch # AddHandler cgi-script .cgi +# +# If a DirectoryIndex directive is also desired, the Indexes option must be set. +# Such a directive is not desirable where the static and dynamic resources are +# in different places, however. apache_htaccess_combined_mod_rewrite = """ -DirectoryIndex moin.cgi RewriteEngine On -RewriteBase %(url_path)s +RewriteBase %(final_url_path)s RewriteCond %%{REQUEST_FILENAME} !-f RewriteCond %%{REQUEST_FILENAME} !-d -RewriteRule ^(.*) moin.cgi/$1 [PT,L,QSA] +RewriteRule ^(.*) %(url_path)s/moin.cgi/$1 [PT,L,QSA] """ # Post-setup templates. @@ -91,6 +99,12 @@ find '%(htdocs_dir)s' -type d | xargs setfacl -m u:%(web_user)s:rx """ +postsetup_setfacl_logs = """ +if [ -e "%(common_dir)s/data/*-log" ]; then + setfacl -m g:%(web_group)s:rw %(common_dir)s/data/*-log +fi +""" + postsetup_chown_chmod = """#!/bin/sh chown -R %(this_user)s.%(web_group)s '%(common_dir)s/data' @@ -103,6 +117,12 @@ chown -R %(this_user)s.%(web_group)s '%(htdocs_dir)s' """ +postsetup_chown_logs = """ +if [ -e "%(common_dir)s/data/*-log" ]; then + chown %(this_user)s.%(web_group)s %(common_dir)s/data/*-log +fi +""" + # Utility functions. def readfile(filename): @@ -350,7 +370,8 @@ def __init__(self, moin_distribution=None, prefix=None, site_packages=None, web_app_dir=None, web_static_dir=None, web_site_dir=None, - common_dir=None, farm_config=None, site_config=None, url_path=None, + common_dir=None, farm_config=None, site_config=None, + url_path=None, static_url_path=None, superuser=None, site_name=None, site_identifier=None, front_page_name=None, theme_default=None): @@ -384,6 +405,8 @@ (overrides the 'common_dir' setting) * url_path - the URL path at which the Wiki will be made available (such as / or /mywiki) + * static_url_path - optional: the URL path at which static resources + will be made available (such as / or /mywiki) * superuser - the name of the site's superuser (such as "AdminUser", can be omitted) * site_name - the name of the site (such as "My Wiki") @@ -416,10 +439,8 @@ if not url_path: raise TypeError, "The 'url_path' setting must be specified." - if url_path != "/" and url_path.endswith("/"): - self.url_path = url_path[:-1] - else: - self.url_path = url_path + self.url_path = self._tidy_url_path(url_path) + self.static_url_path = self._tidy_url_path(static_url_path) # Define and create specific directories. # Here are the configuration and actual Wiki data directories. @@ -464,14 +485,38 @@ # # This allows multiple Wiki instances to have their own static resources # in the same hosting area. + # + # Where a separate static URL path has been given, the resources are + # located under that path: + # + # / -> /moin_static187 + # /hgwiki -> /hgwiki/moin_static187 - self.static_url_path = self.url_path + (self.url_path != "/" and "-" or "") + self.get_static_identifier() + # The final URL path is the principal location of the Wiki. + + self.final_url_path = self.static_url_path or self.url_path + + # The static URL resources path is the specific location of static + # resources. + + self.static_url_resources_path = \ + self.final_url_path + \ + (self.static_url_path + and (self.static_url_path != "/" + and "/" + or "") + or (self.final_url_path != "/" + and "-" + or "")) + \ + self.get_static_identifier() + + self.static_dir_name = self.static_url_resources_path.split("/")[-1] # In limited hosting, the static resources directory is related to - # the URL path. + # the URL path, either a specified static URL path or the general path. if self.limited_hosting(): - self.htdocs_dir = join(self.web_static_dir or self.web_app_dir, self.static_url_path.lstrip("/")) + self.htdocs_dir = join(self.web_static_dir or self.web_app_dir, self.static_dir_name) # Otherwise, a mapping is made to the directory. # This may be placed in a special static directory if desired. @@ -511,6 +556,12 @@ def _get_abspath(self, d): return d and abspath(d) or None + def _tidy_url_path(self, url_path): + if url_path != "/" and url_path.endswith("/"): + return url_path[:-1] + else: + return url_path + def get_moin_version(self): "Return the MoinMoin version." @@ -769,7 +820,7 @@ # NOTE: with the version, but more specific locations are probably # NOTE: acceptable if less efficient. - url_prefix_static = "%r" % self.static_url_path + url_prefix_static = "%r" % self.static_url_resources_path # Use a farm configuration file. @@ -882,10 +933,12 @@ if not site_file_configured: note("Site file not configured: script name not changed.") else: + url_path = self.final_url_path + if self.moin_version.startswith("1.9"): - s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % self.url_path, s) + s = moin_cgi_fix_script_name.sub(r"\1\2 %r" % url_path, s) else: - s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : self.url_path}, s) + s = moin_cgi_properties.sub(r"\1\2 %r" % {"script_name" : url_path}, s) # NOTE: Use CGI for now. @@ -953,7 +1006,7 @@ # Otherwise, use an .htaccess file. else: - site_def = join(self.web_app_dir, ".htaccess") + site_def = join(self.web_static_dir or self.web_app_dir, ".htaccess") s = apache_htaccess_combined_mod_rewrite % self.__dict__ @@ -990,13 +1043,14 @@ vars.update(self.__dict__) vars.update(locals()) - for postinst_script, start, extra in [ - (postinst_scripts[0], postsetup_chown_chmod, postsetup_chown_extra), - (postinst_scripts[1], postsetup_setfacl, postsetup_setfacl_extra) + for postinst_script, start, extra, logs in [ + (postinst_scripts[0], postsetup_chown_chmod, postsetup_chown_extra, postsetup_chown_logs), + (postinst_scripts[1], postsetup_setfacl, postsetup_setfacl_extra, postsetup_setfacl_logs) ]: s = start % vars s += extra % vars + s += logs % vars writefile(postinst_script, s) chmod(postinst_script, 0755)