install
changeset 80 fcb20d7593e6
parent 79 3a58a95fae2f
child 84 964b04126d01
equal deleted inserted replaced
79:3a58a95fae2f 80:fcb20d7593e6
     1 #!/bin/sh
     1 #!/usr/bin/env python
     2 
     2 
     3 set -e
     3 import shutil
       
     4 import os
       
     5 import pwd
       
     6 import subprocess
     4 
     7 
     5 install -o root -g root -d /usr/local/lib/mercurial-server
     8 def installFiles(d, *sources):
     6 install -o root -g root -t /usr/local/lib/mercurial-server \
     9     os.makedirs(d)
     7     src/hg-ssh \
    10     for f in sources:
     8     src/refresh-auth
    11         shutil.copy(f, d)
     9 install -o root -g root -d /usr/local/lib/mercurial-server/mercurialserver
       
    10 install -o root -g root -t /usr/local/lib/mercurial-server/mercurialserver -m 644 \
       
    11     src/mercurialserver/__init__.py \
       
    12     src/mercurialserver/paths.py \
       
    13     src/mercurialserver/changes.py \
       
    14     src/mercurialserver/access.py \
       
    15     src/mercurialserver/servelog.py \
       
    16     src/mercurialserver/refreshauth.py \
       
    17     src/mercurialserver/ruleset.py
       
    18 install -o root -g root -d /usr/local/lib/mercurial-server/init
       
    19 install -o root -g root -t /usr/local/lib/mercurial-server/init \
       
    20     src/init/hginit
       
    21 install -o root -g root -t /usr/local/lib/mercurial-server/init -m 644 \
       
    22     src/init/hgadmin-hgrc
       
    23 install -o root -g root -d /etc/mercurial-server
       
    24 install -o root -g root -t /etc/mercurial-server -m 644 \
       
    25     src/init/conf/remote-hgrc \
       
    26     src/init/conf/access.conf
       
    27 install -o root -g root -d /etc/mercurial-server/keys/root
       
    28 install -o root -g root -d /etc/mercurial-server/keys/users
       
    29 
    12 
    30 if [ x$(getent passwd hg | wc -c) = x0 ] ; then
    13 dest = '/usr/local/lib/mercurial-server'
    31     adduser --system --shell /bin/sh --group --disabled-password \
    14 
    32         --gecos "Mercurial repositories" hg
    15 installFiles(dest,
    33     su -c /usr/local/lib/mercurial-server/init/hginit hg
    16     'src/hg-ssh',
    34 fi
    17     'src/refresh-auth')
       
    18 installFiles(dest + '/mercurialserver',
       
    19     'src/mercurialserver/__init__.py',
       
    20     'src/mercurialserver/paths.py',
       
    21     'src/mercurialserver/changes.py',
       
    22     'src/mercurialserver/access.py',
       
    23     'src/mercurialserver/servelog.py',
       
    24     'src/mercurialserver/refreshauth.py',
       
    25     'src/mercurialserver/ruleset.py')
       
    26 installFiles(dest + '/init',
       
    27     'src/init/hginit',
       
    28     'src/init/hgadmin-hgrc')
       
    29 installFiles('/etc/mercurial-server',
       
    30     'src/init/conf/remote-hgrc',
       
    31     'src/init/conf/access.conf')
       
    32 installFiles('/etc/mercurial-server/keys/root')
       
    33 installFiles('/etc/mercurial-server/keys/users')
       
    34 
       
    35 def becomeFunc(u):
       
    36     p = pwd.getpwnam(u)
       
    37     def become():
       
    38         os.setgid(p.pw_gid)
       
    39         os.setegid(p.pw_gid)
       
    40         os.setuid(p.pw_uid)
       
    41         os.seteuid(p.pw_uid)
       
    42     return become
       
    43 
       
    44 try:
       
    45    pwd.getpwnam('hg')
       
    46 except KeyError:
       
    47     subprocess.check_call(
       
    48         "adduser --system --shell /bin/sh --group --disabled-password".split() + 
       
    49         ["--gecos", "Mercurial repositories", "hg"])
       
    50         
       
    51     subprocess.check_call([dest + '/init/hginit'], preexec_fn = becomeFunc('hg'))
       
    52