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 |
80
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
1 |
#!/usr/bin/env python |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
2 |
|
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
3 |
import shutil |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
4 |
import os |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
5 |
import pwd |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
6 |
import subprocess |
27
ec31ba248edd
Installer to set things up automatically
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
7 |
|
80
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
8 |
def installFiles(d, *sources): |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
9 |
os.makedirs(d) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
10 |
for f in sources: |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
11 |
shutil.copy(f, d) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
12 |
|
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
13 |
dest = '/usr/local/lib/mercurial-server' |
27
ec31ba248edd
Installer to set things up automatically
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
14 |
|
80
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
15 |
installFiles(dest, |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
16 |
'src/hg-ssh', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
17 |
'src/refresh-auth') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
18 |
installFiles(dest + '/mercurialserver', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
19 |
'src/mercurialserver/__init__.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
20 |
'src/mercurialserver/paths.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
21 |
'src/mercurialserver/changes.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
22 |
'src/mercurialserver/access.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
23 |
'src/mercurialserver/servelog.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
24 |
'src/mercurialserver/refreshauth.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
25 |
'src/mercurialserver/ruleset.py') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
26 |
installFiles(dest + '/init', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
27 |
'src/init/hginit', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
28 |
'src/init/hgadmin-hgrc') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
29 |
installFiles('/etc/mercurial-server', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
30 |
'src/init/conf/remote-hgrc', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
31 |
'src/init/conf/access.conf') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
32 |
installFiles('/etc/mercurial-server/keys/root') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
33 |
installFiles('/etc/mercurial-server/keys/users') |
27
ec31ba248edd
Installer to set things up automatically
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
34 |
|
80
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
35 |
def becomeFunc(u): |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
36 |
p = pwd.getpwnam(u) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
37 |
def become(): |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
38 |
os.setgid(p.pw_gid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
39 |
os.setegid(p.pw_gid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
40 |
os.setuid(p.pw_uid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
41 |
os.seteuid(p.pw_uid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
42 |
return become |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
43 |
|
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
44 |
try: |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
45 |
pwd.getpwnam('hg') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
46 |
except KeyError: |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
47 |
subprocess.check_call( |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
48 |
"adduser --system --shell /bin/sh --group --disabled-password".split() + |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
49 |
["--gecos", "Mercurial repositories", "hg"]) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
50 |
|
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
51 |
subprocess.check_call([dest + '/init/hginit'], preexec_fn = becomeFunc('hg')) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
52 |