install
author Paul Crowley <paul@lshift.net>
Fri, 06 Mar 2009 16:15:28 +0000
changeset 80 fcb20d7593e6
parent 79 3a58a95fae2f
child 84 964b04126d01
permissions -rwxr-xr-x
Rewrite install script in Python

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