# HG changeset patch # User Paul Boddie # Date 1298421372 -3600 # Node ID 74893a8b3097d8fb098305eaa7751d4d6d3d6eda # Parent 980a592988c6c5a64af3a1d99a9bf51fd631f01a Introduced templates for the post-setup scripts, adding support for the use of setfacl instead of chown/chmod on ACL-enabled systems/filesystems. diff -r 980a592988c6 -r 74893a8b3097 moinsetup.py --- a/moinsetup.py Tue Feb 22 00:50:41 2011 +0100 +++ b/moinsetup.py Wed Feb 23 01:36:12 2011 +0100 @@ -27,6 +27,7 @@ import sys import shutil import re +import tempfile __version__ = "0.2" @@ -69,6 +70,33 @@ RewriteRule ^(.*) moin.cgi/$1 [PT,L,QSA] """ +# Post-setup templates. + +postsetup_setfacl = """#!/bin/sh + +find '%(conf_dir)s/data' -type f | xargs setfacl -m u:%(web_user)s:rw +find '%(conf_dir)s/data' -type d | xargs setfacl -m u:%(web_user)s:rwx +find '%(conf_dir)s/underlay' -type f | xargs setfacl -m u:%(web_user)s:rw +find '%(conf_dir)s/underlay' -type d | xargs setfacl -m u:%(web_user)s:rwx +""" + +postsetup_setfacl_moin18_extra = """ +find '%(htdocs_dir)s' -type f | xargs setfacl -m u:%(web_user)s:r +find '%(htdocs_dir)s' -type d | xargs setfacl -m u:%(web_user)s:rx +""" + +postsetup_chown_chmod = """#!/bin/sh + +chown -R %(this_user)s.%(web_group)s '%(conf_dir)s/data' +chown -R %(this_user)s.%(web_group)s '%(conf_dir)s/underlay' +chmod -R g+w '%(conf_dir)s/data' +chmod -R g+w '%(conf_dir)s/underlay' +""" + +postsetup_chown_moin18_extra = """ +chown -R %(this_user)s.%(web_group)s '%(htdocs_dir)s' +""" + # Utility functions. def readfile(filename): @@ -691,21 +719,44 @@ "Write a post-install script with additional actions." + # Work out whether setfacl works. + + fd, temp_filename = tempfile.mkstemp(dir=self.conf_dir) + os.close(fd) + + have_setfacl = os.system("setfacl -m user:%(web_user)s:r %(file)s > /dev/null 2>&1" % { + "web_user" : self.web_user, "file" : temp_filename}) == 0 + + os.remove(temp_filename) + + # Create the scripts. + this_user = os.environ["USER"] - postinst_script = "moinsetup-post.sh" - - s = "#!/bin/sh\n" + postinst_scripts = "moinsetup-post-chown.sh", "moinsetup-post-setfacl.sh" - for d in ("data", "underlay"): - s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, join(self.conf_dir, d)) - s += "chmod -R g+w '%s'\n" % join(self.conf_dir, d) + vars = {} + vars.update(Installation.__dict__) + vars.update(self.__dict__) + vars.update(locals()) + + for postinst_script, start, extra in [ + (postinst_scripts[0], postsetup_chown_chmod, postsetup_chown_moin18_extra), + (postinst_scripts[1], postsetup_setfacl, postsetup_setfacl_moin18_extra) + ]: + + s = start % vars - if not self.moin_version.startswith("1.9"): - s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, self.htdocs_dir) + if not self.moin_version.startswith("1.9"): + s += extra % vars + + writefile(postinst_script, s) + os.chmod(postinst_script, 0755) - writefile(postinst_script, s) - os.chmod(postinst_script, 0755) - note("Run %s as root to set file ownership and permissions." % postinst_script) + if have_setfacl: + note("Run %s to set file ownership and permissions." % postinst_scripts[1]) + note("If this somehow fails...") + + note("Run %s as root to set file ownership and permissions." % postinst_scripts[0]) # Accessory methods.