install
author Paul Crowley <paul@lshift.net>
Sat, 07 Mar 2009 08:58:30 +0000
changeset 82 7369ff737684
parent 80 fcb20d7593e6
child 84 964b04126d01
permissions -rwxr-xr-x
License properly

#!/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'))