# HG changeset patch # User Paul Crowley # Date 1257781565 0 # Node ID f9bf8f84df7f86addf874c8cd05bf6ab7af877b0 # Parent aeeba4d0dd4ed19f1a435d531afabc2292276618 Kill install in favour of setup.py and Makefile diff -r aeeba4d0dd4e -r f9bf8f84df7f Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Nov 09 15:46:05 2009 +0000 @@ -0,0 +1,57 @@ +#!/usr/bin/env make -f + +PREFIX=/usr/local/share +LIBDIR=$(PREFIX)/mercurial-server +DOCDIR=$(PREFIX)/doc/mercurial-server +ETCDIR=/etc/mercurial-server +NEWUSER=hg + +INSTALL=install + +setup-adduser: installfiles adduser inituser + +# WARNING: this is experimental +setup-useradd: installfiles useradd inituser + +installetc: + $(INSTALL) -d $(ETCDIR) + $(INSTALL) -m 644 -t $(ETCDIR) \ + src/init/conf/remote-hgrc src/init/conf/access.conf + $(INSTALL) -d $(ETCDIR)/keys/root + $(INSTALL) -d $(ETCDIR)/keys/user + +installdoc: build/html/index.html + $(INSTALL) -d $(DOCDIR) + $(INSTALL) -m 644 -t $(DOCDIR) README build/html/index.html + +build/html/index.html: doc/manual.docbook + xsltproc -o $@ /usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl $^ + +pythonbuild: + python setup.py build + +build: build/html/index.html pythonbuild + +pythoninstall: + python setup.py install \ + --install-purelib=$(LIBDIR) \ + --install-platlib=$(LIBDIR) \ + --install-scripts=$(LIBDIR) \ + --install-data=$(LIBDIR) + +installfiles: installetc installdoc pythoninstall + +adduser: + adduser --system --shell /bin/sh --group --disabled-password \ + --home /var/lib/mercurial-server \ + --gecos "Mercurial repositories" $(NEWUSER) + +# WARNING: this is experimental +useradd: + useradd --system --shell /bin/sh \ + --home /var/lib/mercurial-server --create-home \ + --comment "Mercurial repositories" $(NEWUSER) + +inituser: + su -l -c "$(LIBDIR)/init/hginit $(LIBDIR)" $(NEWUSER) + diff -r aeeba4d0dd4e -r f9bf8f84df7f install --- a/install Mon Nov 09 13:23:45 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -#!/usr/bin/env python - -import sys -import shutil -import os -import pwd -import subprocess -import optparse - -oparser = optparse.OptionParser() - -oparser.add_option("--prefix") -oparser.add_option("--root") -oparser.set_defaults(root="", prefix="/usr/local") -(options, args) = oparser.parse_args() - -if len(args) > 0: - oparser.print_help() - sys.exit(-1) - -# This must be run as root, because it must create an hg user. -# Normally the clean thing to do is let it fail with a permission error -# if a non-root user tries to run it, but I don't want anyone thinking -# that they can make it work as non-root by changing install paths. -# Patches for doing this more cleanly welcome of course. - -if os.getgid() != 0: - print >>sys.stderr, "Install must be run as root user" - sys.exit(-1) - -def installFiles(d, *sources): - d = options.root + d - os.makedirs(d) - for f in sources: - shutil.copy(f, d) - -installFiles(options.prefix + '/share/mercurial-server', - 'src/hg-ssh', - 'src/refresh-auth') -installFiles(options.prefix + '/share/mercurial-server/mercurialserver', - 'src/mercurialserver/__init__.py', - 'src/mercurialserver/paths.py', - 'src/mercurialserver/changes.py', - 'src/mercurialserver/access.py', - 'src/mercurialserver/servelog.py', - 'src/mercurialserver/refreshauth.py', - 'src/mercurialserver/ruleset.py') -installFiles(options.prefix + '/share/mercurial-server/init', - 'src/init/hginit', - 'src/init/dot-mercurial-server', - 'src/init/hgadmin-hgrc') -installFiles(options.prefix + '/share/doc/mercurial-server', - 'README', - 'build/html/index.html') -installFiles('/etc/mercurial-server', - 'src/init/conf/remote-hgrc', - 'src/init/conf/access.conf') -installFiles('/etc/mercurial-server/keys/root') -installFiles('/etc/mercurial-server/keys/users') - -def becomeFunc(u): - p = pwd.getpwnam(u) - def become(): - os.setgid(p.pw_gid) - os.setegid(p.pw_gid) - os.setuid(p.pw_uid) - os.seteuid(p.pw_uid) - os.chdir(p.pw_dir) - return become - -if options.root == '': - try: - pwd.getpwnam('hg') - except KeyError: - subprocess.check_call( - "adduser --system --shell /bin/sh --group --disabled-password".split() + - ["--gecos", "Mercurial repositories", "hg"]) - subprocess.check_call([options.prefix + '/share/mercurial-server/init/hginit', - options.prefix + '/share/mercurial-server'], - preexec_fn = becomeFunc('hg')) - diff -r aeeba4d0dd4e -r f9bf8f84df7f setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Mon Nov 09 15:46:05 2009 +0000 @@ -0,0 +1,26 @@ +# WARNING: this file is NOT meant to be directly executed, but +# run from the Makefile. + +from distutils.core import setup + +setup( + name="mercurial-server", + description="Centralized Mercurial repository manager", + url="http://www.lshift.net/mercurial-server.html", + version="0.6+", # FIXME: infer this + package_dir = {'': 'src'}, + packages = ["mercurialserver"], + requires = ["mercurial"], # FIXME: what version? + scripts = ['src/hg-ssh', 'src/refresh-auth'], + data_files = [ + ('init', [ + 'src/init/hginit', + 'src/init/dot-mercurial-server', + 'src/init/hgadmin-hgrc' + ]), ('init/conf', [ + 'src/init/conf/remote-hgrc', + 'src/init/conf/access.conf', + ]), + ], +) + diff -r aeeba4d0dd4e -r f9bf8f84df7f src/init/hginit --- a/src/init/hginit Mon Nov 09 13:23:45 2009 +0000 +++ b/src/init/hginit Mon Nov 09 15:46:05 2009 +0000 @@ -1,11 +1,17 @@ #!/bin/sh -# WARNING: this must be run from the hg user's home directory +set -e + +cd -set -e +if [ -e .ssh/authorized_keys ] ; then + echo "This user already exists with authorized keys, aborting" + exit -1 +fi cp $1/init/dot-mercurial-server .mercurial-server mkdir -p repos/hgadmin .ssh cd repos/hgadmin hg init . cp $1/init/hgadmin-hgrc .hg/hgrc +