summaryrefslogtreecommitdiffstats
path: root/make-shared-repo
blob: d0df8a96b6ac20b468c315c6cbd7d619d8b9869c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# Shell script to create new repositories on a remote server.
#
# (c) 2010, B. Brandenburg.

REPO=`basename "$1"`

### configuration section ###

# where to copy it to
REMOTE_PATH="/cvs/proj/litmus/repo/${REPO}.git"
if [ -z "$SERVER" ]
then
    SERVER="cvs.cs.unc.edu"
fi

# command to execute after repository creation
CHMOD="/cvs/proj/litmus/sw/bin/set_repo_rights --quiet"

### end of configuration ###


# implementation from here on dow
CONFIG="$1/.git/config"
BARE="/tmp/${REPO}.git"
TARGET="$SERVER:$REMOTE_PATH"

function die {
    echo "(EE) $*"
    exit 1
}

function info {
    echo "(II) $*"
}

function warn {
    echo "(WW) $*"
}

if [ -z "$1" ]
then
    die "Argument missing. Usage: '$0 /path/to/git/repo'."
fi

info "Creating shared repository for $REPO on $SERVER at $REMOTE_PATH."

info "Checking whether ${TARGET} exists."
ssh "$SERVER" test -e "$REMOTE_PATH" && die "Remote path exists already."

if [ -e "$BARE" ]
then
    warn "$BARE exists. Moving it out of the way."
    warn "Faking" rm -rf "$BARE"
    die "Not yet implemented..."
fi

info "Cloning repository ${REPO} to ${BARE}."
git clone --bare "$1" "$BARE" || die "git clone failed."

info "Copying to ${TARGET}."
scp -rpq "$BARE" "$TARGET" || die "scp failed."

if [ ! -z "$CHMOD" ]
then
    info "Setting up permissions."
    ssh "$SERVER" "$CHMOD" "$REMOTE_PATH" || die "$CHMOD failed"
fi

info "Cleaning up."
rm -rf "$BARE" || die "rm failed."

info "Appending origin setup to $CONFIG"
cat  >> "$CONFIG" <<EOF

# config added by $0
[remote "origin"]
	url = ${TARGET}
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
EOF

echo "****************************"
info  "Your new remote repository is at: $TARGET"
info "Enjoy!"
echo