aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xadd-git-repo40
1 files 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'"