From a121b28e023053ca94f24b1c1d9e80fd77515e05 Mon Sep 17 00:00:00 2001 From: Rafael Laboissiere Date: Thu, 14 May 2015 04:04:51 +0200 Subject: Add option for adding the repository description --- add-git-repo | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/add-git-repo b/add-git-repo index f562f4b..f583642 100755 --- a/add-git-repo +++ b/add-git-repo @@ -20,11 +20,23 @@ ### 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 +usage () { + echo "Usage: $prog [-d description] user repo" 1>&2 exit 1 -fi +} + +### 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 @@ -39,12 +51,20 @@ fi ### Create the repo home=$(getent passwd $user | cut -f6 -d:) -repo=$home/$2 -if [ -d $repo ] ; then +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 $repo -( cd $repo ; git init --bare) -chown -R $user:$user $repo -echo "$prog:I: Created Git repository $repo" +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'" -- cgit v1.2.3