aboutsummaryrefslogtreecommitdiff
path: root/add-git-repo
blob: f562f4b59a13a9f46b71c19797d88b61d7c435d1 (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
#!/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##*/}

### Ensure that the correct number of arguments are given
if [ $# != 2 ] ; then
    echo "Usage: $prog user repo" 1>&2
    exit 1
fi

### 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=$home/$2
if [ -d $repo ] ; then
    echo "$prog:E: Repository $repo already exists.  Nothing will be done." 1>&2
    exit 1
fi
mkdir $repo
( cd $repo ; git init --bare)
chown -R $user:$user $repo
echo "$prog:I: Created Git repository $repo"