Test commit
[cogito/jonas.git] / cg-admin-setuprepo
blobd40779851e2e272b2818d2f919dd694e6758ce95
1 #!/usr/bin/env bash
3 # Setup a public repository
4 # Copyright (c) Petr Baudis, 2005
6 # Setup a public GIT repository, that is, one that has no attached working
7 # copy and you typically only push into it and pull from it. You need to run
8 # this command before you will be able to push into the repository for the
9 # first time, but you will be also unable to pull from the repository until
10 # you push into it at first.
12 # Therefore the workflow is to first init a regular private repository, then
13 # use this command to create the public one, then add the appropriate remote
14 # branch (`cg-branch-add origin ...`) in your private repository and then
15 # push to the public repository.
17 # Use `cg-init` if you want to instead create a new GIT project.
19 # The command will create the repository to reside in REPOSITORY (either local
20 # path or git+ssh URL; the directory must not exist before calling this
21 # command). By default, it will be world-readable, but writable only by you. If
22 # you want to make it possible for multiple users to push, create a group for
23 # them and use the '-g' parameter, which will make `cg-admin-setuprepo` set up
24 # the permissions properly.
26 # Note that in case you are using cg-admin-setuprepo with SSH URL instead of
27 # a local path, you need a full shell access at the remote machine, the
28 # restricted git-shell access is not enough.
30 # The repository will also be set up so that `git-update-server-info` will
31 # be automagically re-ran after each push, in short making it suitable for
32 # HTTP access.
34 # Note that you might need to do other additional steps, like touching the
35 # 'git-daemon-export-ok' file if you want to make the repository accessible
36 # by the git daemon (serving the 'git://...' URIs).
38 # OPTIONS
39 # -------
40 # -g GROUP:: Specify group ownership for the repository
41 # Name of the UNIX group covering the users authorized to push into
42 # the repository. If unspecified, only you (who ran this command) will
43 # have write (push) access.
45 # NOTES
46 # -----
47 # It may happen that you are using version of GIT missing the default
48 # post-update hook, or that the relevant template hooks are not available
49 # on your system or with your GIT installation. In that case, in order to
50 # have your repository properly accessible with HTTP, you need to add this
51 # to .git/hooks/post-update (and then make it eXecutable):
53 # #!/bin/sh
54 # exec git-update-server-info
56 # Testsuite: TODO
58 USAGE="cg-admin-setuprepo [-g GROUP] REPOSITORY"
59 _git_repo_unneeded=1
61 . "${COGITO_LIB}"cg-Xlib || exit 1
63 shared=
64 unixgroup=
65 while optparse; do
66 if optparse -g=; then
67 unixgroup="$OPTARG"
68 shared=--shared
69 else
70 optfail
72 done
75 uri="${ARGS[0]}"
76 if echo "$uri" | grep -q "^git+ssh://"; then
77 shell=ssh
78 shellarg="$(echo "$uri" | sed 's!^git+ssh://\([^/]*\)/.*!\1!')"
79 uri="$(echo "$uri" | sed 's!^git+ssh://[^/]*!!')"
80 else
81 shell=bash
82 shellarg=
86 # Careful here, no cg-Xlib functions! Also, mind that the variables
87 # are substituted _before_ executing the script, not as we go. Which
88 # is somewhat unfortunate in case the user passed us a path containing
89 # quotes or backslashes, but only sick people do that and they receive
90 # what they deserve. ;-)
91 _git="$uri"
92 cat <<_SCRIPT_EOF_ | $shell $shellarg
94 die() { echo "$*" >&2; exit 1; }
96 export GIT_DIR="$uri"
98 [ "$_git" ] || die "missing name of the repository directory"
99 [ -e "$_git" ] && die "$_git already exists"
102 if [ "$unixgroup" ]; then
103 umask 002
104 else
105 umask 022
108 mkdir "$_git" || exit 1
109 if [ "$unixgroup" ]; then
110 chgrp "$unixgroup" "$_git" && chmod 2775 "$_git" || exit 1
113 git-init-db $shared || die "git-init-db failed"
115 # Enable git-update-server-info after each push.
116 if ! chmod a+x "$_git/hooks/post-update"; then
117 echo "Due to a missing post-update hook, HTTP pull will not work properly on this repository." >&2
118 echo "See the NOTES section of cg-admin-setuprepo(1)'s documentation for more details." >&2
120 true
122 _SCRIPT_EOF_