install
author Paul Crowley <paul@lshift.net>
Sat, 07 Mar 2009 08:55:42 +0000
changeset 81 f23736ad66bc
parent 80 fcb20d7593e6
child 84 964b04126d01
permissions -rwxr-xr-x
Update README to reflect absence of wrappers

#!/usr/bin/env python

import shutil
import os
import pwd
import subprocess

def installFiles(d, *sources):
    os.makedirs(d)
    for f in sources:
        shutil.copy(f, d)

dest = '/usr/local/lib/mercurial-server'

installFiles(dest,
    'src/hg-ssh',
    'src/refresh-auth')
installFiles(dest + '/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(dest + '/init',
    'src/init/hginit',
    'src/init/hgadmin-hgrc')
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)
    return become

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([dest + '/init/hginit'], preexec_fn = becomeFunc('hg'))