install
changeset 84 964b04126d01
parent 80 fcb20d7593e6
child 87 535502c18eaa
equal deleted inserted replaced
83:86ec1268d306 84:964b04126d01
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 
     2 
       
     3 import sys
     3 import shutil
     4 import shutil
     4 import os
     5 import os
     5 import pwd
     6 import pwd
     6 import subprocess
     7 import subprocess
     7 
     8 
       
     9 # This must be run as root, because it must create an hg user.
       
    10 # Normally the clean thing to do is let it fail with a permission error
       
    11 # if a non-root user tries to run it, but I don't want anyone thinking
       
    12 # that they can make it work as non-root by changing install paths.
       
    13 # Patches welcome for doing this more cleanly of course.
       
    14 
       
    15 if os.getgid() != 0:
       
    16     print >>sys.stderr, "Install must be run as root user"
       
    17     sys.exit(-1)
       
    18 
       
    19 if len(sys.argv) > 2:
       
    20     print >>sys.stderr, "Usage: install [<destination-prefix>]"
       
    21     sys.exit(-1)
       
    22 if len(sys.argv) == 2:
       
    23     dest = sys.argv[1] + '/lib/mercurial-server'
       
    24 else:
       
    25     dest = '/usr/local/lib/mercurial-server'
       
    26 
     8 def installFiles(d, *sources):
    27 def installFiles(d, *sources):
     9     os.makedirs(d)
    28     os.makedirs(d)
    10     for f in sources:
    29     for f in sources:
    11         shutil.copy(f, d)
    30         shutil.copy(f, d)
    12 
       
    13 dest = '/usr/local/lib/mercurial-server'
       
    14 
    31 
    15 installFiles(dest,
    32 installFiles(dest,
    16     'src/hg-ssh',
    33     'src/hg-ssh',
    17     'src/refresh-auth')
    34     'src/refresh-auth')
    18 installFiles(dest + '/mercurialserver',
    35 installFiles(dest + '/mercurialserver',
    45    pwd.getpwnam('hg')
    62    pwd.getpwnam('hg')
    46 except KeyError:
    63 except KeyError:
    47     subprocess.check_call(
    64     subprocess.check_call(
    48         "adduser --system --shell /bin/sh --group --disabled-password".split() + 
    65         "adduser --system --shell /bin/sh --group --disabled-password".split() + 
    49         ["--gecos", "Mercurial repositories", "hg"])
    66         ["--gecos", "Mercurial repositories", "hg"])
    50         
       
    51     subprocess.check_call([dest + '/init/hginit'], preexec_fn = becomeFunc('hg'))
    67     subprocess.check_call([dest + '/init/hginit'], preexec_fn = becomeFunc('hg'))
    52 
    68