summaryrefslogtreecommitdiffstats
path: root/roles/distgit/files/setup_git_package
blob: 67103ecc19fba029ac0df3624107f15f48fe448a (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#
# Create a new repo.
# THIS HAS TO BE RUN ON THE GIT SERVER!

# WARNING:
# This file is maintained within ansible
# All local changes will be lost.


# Figure out the environment we're running in
GITROOT=/srv/git/rpms

# check if a moron is driving me
if [ ! -d $GITROOT ] ; then
    # we're not on the git server (this check is fragile)
    echo "ERROR: This script has to be run on the git server."
    echo "ERROR: Homer sez 'Duh'."
    exit -9
fi

# Local variables
VERBOSE=0
TEST=
IGNORE=
AUTHOR="Fedora Release Engineering <rel-eng@lists.fedoraproject.org>"
GIT_SSH_URL="ssh://localhost"

Usage() {
    cat <<EOF
Usage:
    $0 <package_name>

    Creates a new repo for <package_name>

Options:
    -h,--help			This help message
EOF
}

if [ $# -gt 2 ]; then
    Usage
    exit -1
fi

# parse the arguments
while [ -n "$1" ] ; do
    case "$1" in
	-h | --help )
	    Usage
	    exit 0
	    ;;

	* )
	    PACKAGE="$1"
	    ;;
    esac
    shift
done

# I hate shell scripting.  I'm sure the above is totally wrong

# check the arguments
if [ -z "$PACKAGE" ] ; then
    Usage
    exit -1
fi

# Sanity checks before we start doing damage
[ $VERBOSE -gt 1 ] && echo "Checking package $PACKAGE..."
if [ -f $GITROOT/$PACKAGE.git/refs/heads/master ] ; then
    echo "ERROR: Package module $PACKAGE already exists!" >&2
    exit -1
fi

# A cleanup in case gitolite came by this repo
if [ -f $GITROOT/$PACKAGE.git/hooks/update ] ; then
    echo "Gitolite already initialized this repo. Will remove its hooks"
    rm -f $GITROOT/$PACKAGE.git/hooks/update
fi

# "global" permissions check
if [ ! -w $GITROOT ] ; then
    echo "ERROR: You can not write to $GITROOT"
    echo "ERROR: You can not create repos"
    exit -1
fi

# Now start working on creating those branches
# Create a tmpdir to do some git work in
TMPDIR=$(mktemp -d /tmp/tmpXXXXXX)

# First create the master repo
mkdir -p $GITROOT/$PACKAGE.git
pushd $GITROOT/$PACKAGE.git >/dev/null
git init -q --shared --bare
echo "$PACKAGE" > description # This is used to figure out who to send mail to.
git config --add hooks.mailinglist "$PACKAGE-owner@fedoraproject.org,scm-commits@lists.fedoraproject.org"
git config --add hooks.maildomain fedoraproject.org
popd >/dev/null

# Now clone that repo and create the .gitignore and sources file
git init -q $TMPDIR/$PACKAGE
pushd $TMPDIR/$PACKAGE >/dev/null
touch .gitignore sources
git add .
git commit -q -m 'Initial setup of the repo' --author "$AUTHOR"
git remote add origin $GITROOT/$PACKAGE.git
git push -q origin master
popd >/dev/null

# Place the gitolite update hook in place since we're not using our own
ln -s /etc/gitolite/hooks/common/update $GITROOT/$PACKAGE.git/hooks/update


# Setup our post-receive hooks
mkdir -p $GITROOT/$PACKAGE.git/hooks/post-receive-chained.d
ln -s /usr/share/git-core/mail-hooks/gnome-post-receive-email \
    $GITROOT/$PACKAGE.git/hooks/post-receive-chained.d/post-receive-email
ln -s /usr/share/git-core/post-receive-fedmsg \
    $GITROOT/$PACKAGE.git/hooks/post-receive-chained.d/post-receive-fedmsg

# This one kicks off all the others in post-receive-chained.d
ln -s /usr/share/git-core/post-receive-chained \
    $GITROOT/$PACKAGE.git/hooks/post-receive

rm -rf $TMPDIR
echo "Done."