diff options
Diffstat (limited to 'add-git-repo')
-rwxr-xr-x | add-git-repo | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/add-git-repo b/add-git-repo new file mode 100755 index 0000000..f562f4b --- /dev/null +++ b/add-git-repo @@ -0,0 +1,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" |