Show More
@@ -1,45 +1,48 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 by Intevation GmbH <intevation@intevation.de> |
|
3 | # Copyright 2005, 2006 by Intevation GmbH <intevation@intevation.de> | |
4 | # Author(s): |
|
4 | # Author(s): | |
5 | # Thomas Arendsen Hein <thomas@intevation.de> |
|
5 | # Thomas Arendsen Hein <thomas@intevation.de> | |
6 | # |
|
6 | # | |
7 | # This software may be used and distributed according to the terms |
|
7 | # This software may be used and distributed according to the terms | |
8 | # of the GNU General Public License, incorporated herein by reference. |
|
8 | # of the GNU General Public License, incorporated herein by reference. | |
9 |
|
9 | |||
10 | """ |
|
10 | """ | |
11 | hg-ssh - a wrapper for ssh access to a limited set of mercurial repos |
|
11 | hg-ssh - a wrapper for ssh access to a limited set of mercurial repos | |
12 |
|
12 | |||
13 | To be used in ~/.ssh/authorized_keys with the "command" option, see sshd(8): |
|
13 | To be used in ~/.ssh/authorized_keys with the "command" option, see sshd(8): | |
14 | command="hg-ssh path/to/repo1 /path/to/repo2 ~/repo3 ~user/repo4" ssh-dss ... |
|
14 | command="hg-ssh path/to/repo1 /path/to/repo2 ~/repo3 ~user/repo4" ssh-dss ... | |
15 | (probably together with these other useful options: |
|
15 | (probably together with these other useful options: | |
16 | no-port-forwarding,no-X11-forwarding,no-agent-forwarding) |
|
16 | no-port-forwarding,no-X11-forwarding,no-agent-forwarding) | |
17 |
|
17 | |||
18 | This allows pull/push over ssh to to the repositories given as arguments. |
|
18 | This allows pull/push over ssh to to the repositories given as arguments. | |
19 |
|
19 | |||
20 | If all your repositories are subdirectories of a common directory, you can |
|
20 | If all your repositories are subdirectories of a common directory, you can | |
21 | allow shorter paths with: |
|
21 | allow shorter paths with: | |
22 | command="cd path/to/my/repositories && hg-ssh repo1 subdir/repo2" |
|
22 | command="cd path/to/my/repositories && hg-ssh repo1 subdir/repo2" | |
|
23 | ||||
|
24 | You can use pattern matching of your normal shell, e.g.: | |||
|
25 | command="cd repos && hg-ssh user/thomas/* projects/{mercurial,foo}" | |||
23 | """ |
|
26 | """ | |
24 |
|
27 | |||
25 | from mercurial import commands |
|
28 | from mercurial import commands | |
26 |
|
29 | |||
27 | import sys, os |
|
30 | import sys, os | |
28 |
|
31 | |||
29 | cwd = os.getcwd() |
|
32 | cwd = os.getcwd() | |
30 | allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path))) |
|
33 | allowed_paths = [os.path.normpath(os.path.join(cwd, os.path.expanduser(path))) | |
31 | for path in sys.argv[1:]] |
|
34 | for path in sys.argv[1:]] | |
32 | orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?') |
|
35 | orig_cmd = os.getenv('SSH_ORIGINAL_COMMAND', '?') | |
33 |
|
36 | |||
34 | if orig_cmd.startswith('hg -R ') and orig_cmd.endswith(' serve --stdio'): |
|
37 | if orig_cmd.startswith('hg -R ') and orig_cmd.endswith(' serve --stdio'): | |
35 | path = orig_cmd[6:-14] |
|
38 | path = orig_cmd[6:-14] | |
36 | repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path))) |
|
39 | repo = os.path.normpath(os.path.join(cwd, os.path.expanduser(path))) | |
37 | if repo in allowed_paths: |
|
40 | if repo in allowed_paths: | |
38 | commands.dispatch(['-R', repo, 'serve', '--stdio']) |
|
41 | commands.dispatch(['-R', repo, 'serve', '--stdio']) | |
39 | else: |
|
42 | else: | |
40 | sys.stderr.write("Illegal repository %r\n" % repo) |
|
43 | sys.stderr.write("Illegal repository %r\n" % repo) | |
41 | sys.exit(-1) |
|
44 | sys.exit(-1) | |
42 | else: |
|
45 | else: | |
43 | sys.stderr.write("Illegal command %r\n" % orig_cmd) |
|
46 | sys.stderr.write("Illegal command %r\n" % orig_cmd) | |
44 | sys.exit(-1) |
|
47 | sys.exit(-1) | |
45 |
|
48 |
General Comments 0
You need to be logged in to leave comments.
Login now