1.1 --- a/moinsetup.py Tue Feb 22 00:50:41 2011 +0100
1.2 +++ b/moinsetup.py Wed Feb 23 01:36:12 2011 +0100
1.3 @@ -27,6 +27,7 @@
1.4 import sys
1.5 import shutil
1.6 import re
1.7 +import tempfile
1.8
1.9 __version__ = "0.2"
1.10
1.11 @@ -69,6 +70,33 @@
1.12 RewriteRule ^(.*) moin.cgi/$1 [PT,L,QSA]
1.13 """
1.14
1.15 +# Post-setup templates.
1.16 +
1.17 +postsetup_setfacl = """#!/bin/sh
1.18 +
1.19 +find '%(conf_dir)s/data' -type f | xargs setfacl -m u:%(web_user)s:rw
1.20 +find '%(conf_dir)s/data' -type d | xargs setfacl -m u:%(web_user)s:rwx
1.21 +find '%(conf_dir)s/underlay' -type f | xargs setfacl -m u:%(web_user)s:rw
1.22 +find '%(conf_dir)s/underlay' -type d | xargs setfacl -m u:%(web_user)s:rwx
1.23 +"""
1.24 +
1.25 +postsetup_setfacl_moin18_extra = """
1.26 +find '%(htdocs_dir)s' -type f | xargs setfacl -m u:%(web_user)s:r
1.27 +find '%(htdocs_dir)s' -type d | xargs setfacl -m u:%(web_user)s:rx
1.28 +"""
1.29 +
1.30 +postsetup_chown_chmod = """#!/bin/sh
1.31 +
1.32 +chown -R %(this_user)s.%(web_group)s '%(conf_dir)s/data'
1.33 +chown -R %(this_user)s.%(web_group)s '%(conf_dir)s/underlay'
1.34 +chmod -R g+w '%(conf_dir)s/data'
1.35 +chmod -R g+w '%(conf_dir)s/underlay'
1.36 +"""
1.37 +
1.38 +postsetup_chown_moin18_extra = """
1.39 +chown -R %(this_user)s.%(web_group)s '%(htdocs_dir)s'
1.40 +"""
1.41 +
1.42 # Utility functions.
1.43
1.44 def readfile(filename):
1.45 @@ -691,21 +719,44 @@
1.46
1.47 "Write a post-install script with additional actions."
1.48
1.49 + # Work out whether setfacl works.
1.50 +
1.51 + fd, temp_filename = tempfile.mkstemp(dir=self.conf_dir)
1.52 + os.close(fd)
1.53 +
1.54 + have_setfacl = os.system("setfacl -m user:%(web_user)s:r %(file)s > /dev/null 2>&1" % {
1.55 + "web_user" : self.web_user, "file" : temp_filename}) == 0
1.56 +
1.57 + os.remove(temp_filename)
1.58 +
1.59 + # Create the scripts.
1.60 +
1.61 this_user = os.environ["USER"]
1.62 - postinst_script = "moinsetup-post.sh"
1.63 -
1.64 - s = "#!/bin/sh\n"
1.65 + postinst_scripts = "moinsetup-post-chown.sh", "moinsetup-post-setfacl.sh"
1.66
1.67 - for d in ("data", "underlay"):
1.68 - s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, join(self.conf_dir, d))
1.69 - s += "chmod -R g+w '%s'\n" % join(self.conf_dir, d)
1.70 + vars = {}
1.71 + vars.update(Installation.__dict__)
1.72 + vars.update(self.__dict__)
1.73 + vars.update(locals())
1.74 +
1.75 + for postinst_script, start, extra in [
1.76 + (postinst_scripts[0], postsetup_chown_chmod, postsetup_chown_moin18_extra),
1.77 + (postinst_scripts[1], postsetup_setfacl, postsetup_setfacl_moin18_extra)
1.78 + ]:
1.79 +
1.80 + s = start % vars
1.81
1.82 - if not self.moin_version.startswith("1.9"):
1.83 - s += "chown -R %s.%s '%s'\n" % (this_user, self.web_group, self.htdocs_dir)
1.84 + if not self.moin_version.startswith("1.9"):
1.85 + s += extra % vars
1.86 +
1.87 + writefile(postinst_script, s)
1.88 + os.chmod(postinst_script, 0755)
1.89
1.90 - writefile(postinst_script, s)
1.91 - os.chmod(postinst_script, 0755)
1.92 - note("Run %s as root to set file ownership and permissions." % postinst_script)
1.93 + if have_setfacl:
1.94 + note("Run %s to set file ownership and permissions." % postinst_scripts[1])
1.95 + note("If this somehow fails...")
1.96 +
1.97 + note("Run %s as root to set file ownership and permissions." % postinst_scripts[0])
1.98
1.99 # Accessory methods.
1.100