author | Paul Crowley <paul@lshift.net> |
Sat, 07 Mar 2009 09:48:10 +0000 | |
changeset 85 | 80fa761c7f5d |
parent 84 | 964b04126d01 |
child 87 | 535502c18eaa |
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 |
|
84
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
3 |
import sys |
80
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
4 |
import shutil |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
5 |
import os |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
6 |
import pwd |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
7 |
import subprocess |
27
ec31ba248edd
Installer to set things up automatically
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
8 |
|
84
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
9 |
# This must be run as root, because it must create an hg user. |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
10 |
# Normally the clean thing to do is let it fail with a permission error |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
11 |
# if a non-root user tries to run it, but I don't want anyone thinking |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
12 |
# that they can make it work as non-root by changing install paths. |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
13 |
# Patches welcome for doing this more cleanly of course. |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
14 |
|
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
15 |
if os.getgid() != 0: |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
16 |
print >>sys.stderr, "Install must be run as root user" |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
17 |
sys.exit(-1) |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
18 |
|
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
19 |
if len(sys.argv) > 2: |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
20 |
print >>sys.stderr, "Usage: install [<destination-prefix>]" |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
21 |
sys.exit(-1) |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
22 |
if len(sys.argv) == 2: |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
23 |
dest = sys.argv[1] + '/lib/mercurial-server' |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
24 |
else: |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
25 |
dest = '/usr/local/lib/mercurial-server' |
964b04126d01
Force install as root and allow path to change.
Paul Crowley <paul@lshift.net>
parents:
80
diff
changeset
|
26 |
|
80
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
27 |
def installFiles(d, *sources): |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
28 |
os.makedirs(d) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
29 |
for f in sources: |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
30 |
shutil.copy(f, d) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
31 |
|
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
32 |
installFiles(dest, |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
33 |
'src/hg-ssh', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
34 |
'src/refresh-auth') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
35 |
installFiles(dest + '/mercurialserver', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
36 |
'src/mercurialserver/__init__.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
37 |
'src/mercurialserver/paths.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
38 |
'src/mercurialserver/changes.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
39 |
'src/mercurialserver/access.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
40 |
'src/mercurialserver/servelog.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
41 |
'src/mercurialserver/refreshauth.py', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
42 |
'src/mercurialserver/ruleset.py') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
43 |
installFiles(dest + '/init', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
44 |
'src/init/hginit', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
45 |
'src/init/hgadmin-hgrc') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
46 |
installFiles('/etc/mercurial-server', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
47 |
'src/init/conf/remote-hgrc', |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
48 |
'src/init/conf/access.conf') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
49 |
installFiles('/etc/mercurial-server/keys/root') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
50 |
installFiles('/etc/mercurial-server/keys/users') |
27
ec31ba248edd
Installer to set things up automatically
Paul Crowley <paul@ciphergoth.org>
parents:
diff
changeset
|
51 |
|
80
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
52 |
def becomeFunc(u): |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
53 |
p = pwd.getpwnam(u) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
54 |
def become(): |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
55 |
os.setgid(p.pw_gid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
56 |
os.setegid(p.pw_gid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
57 |
os.setuid(p.pw_uid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
58 |
os.seteuid(p.pw_uid) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
59 |
return become |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
60 |
|
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
61 |
try: |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
62 |
pwd.getpwnam('hg') |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
63 |
except KeyError: |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
64 |
subprocess.check_call( |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
65 |
"adduser --system --shell /bin/sh --group --disabled-password".split() + |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
66 |
["--gecos", "Mercurial repositories", "hg"]) |
fcb20d7593e6
Rewrite install script in Python
Paul Crowley <paul@lshift.net>
parents:
79
diff
changeset
|
67 |
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
|
68 |