#!/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 . ### 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'"