blob: f5836423f4b4eb16bf429a058cb28dcc1db4dedb (
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
|
#!/bin/sh
### Create a centralized Git repository
### Copyright (C) 2015 Rafael Laboissiere
###
### This program is free software; you can redistribute it and/or modify it under
### the terms of the GNU General Public License as published by the Free Software
### Foundation; either version 3 of the License, or (at your option) any later
### version.
###
### This program is distributed in the hope that it will be useful, but WITHOUT
### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
### FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
### details.
###
### You should have received a copy of the GNU General Public License along with
### this program; if not, see <http://www.gnu.org/licenses/>.
### Get the program name
prog=${0##*/}
usage () {
echo "Usage: $prog [-d description] user repo" 1>&2
exit 1
}
### Parse options
description=
while getopts "d:h" opt; do
case $opt in
d) description=$OPTARG ;;
h) usage ;;
esac
done
shift $((OPTIND-1))
### Ensure that the correct number of arguments are given
[ $# = 2 ] || usage
### Get the user name and check its sanity
user=$1
ret=false
id -u $user >/dev/null 2>&1 && ret=true
if [ $ret = false ] ; then
echo "$prog:E: User $user does not exist. Add it first." 1>&2
exit 1
fi
### Create the repo
home=$(getent passwd $user | cut -f6 -d:)
repo=$2
path=$home/$repo
if [ -d $path ] ; then
echo "$prog:E: Repository $repo already exists. Nothing will be done." 1>&2
exit 1
fi
mkdir $path
( cd $path ; git init --bare)
chown -R $user:$user $path
echo "$prog:I: Created Git repository $path"
echo "$prog:I: ls -ld $path"
ls -ld $path
### Set the repository description
[ -z "$description" ] && description="${repo%%.git} project"
echo "$description" > $path/description
echo "$prog:I: Set description to '$description'"
|