]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - scripts/gitcreate
gitcreate: add option to set description
[repo_shell.git] / scripts / gitcreate
index e1363c76aca93c69cfff539b074ad4e9101ba7b0..ecd9f0ffa8e6966a66901a0f25e87a1a9377d376 100755 (executable)
@@ -11,6 +11,12 @@ gitaclspath="$git_root/$gitacls"
 githooks=.githooks
 githookspath="$git_root/$githooks"
 
+# If running as root, rerun via sudo as user $owner to ensure proper permissions
+if [ "$(whoami)" == "root" ]; then
+    sudo -u $owner $0 $*
+    exit $?
+fi
+
 if [ "$(whoami)" != "$owner" ]; then
     echo "$0: must run as user $owner" >&2
     exit 1
@@ -22,12 +28,13 @@ if [ "$1" = "-y" ]; then
   shift
 fi
 
-if [ $# -ne 1 ]; then
-    echo "usage: $0 <repopath>" >&2
+if [ $# -lt 1 -o $# -gt 2 ]; then
+    echo "usage: $0 <repopath> [\"Short description\"]" >&2
     exit 1
 fi
 
 repopath=$1
+repodesc=$2
 
 if [ -e $git_root/$repopath ]; then
     echo "$0: repository $repopath already exists" >&2
@@ -48,7 +55,7 @@ if [ ! -d "$git_root/$repodir" ]; then
   fi
   mkdir -p "$git_root/$repodir" 2>/dev/null
   if [ ! -d "$git_root/$repodir" ]; then
-    echo "%0: repository not created, git subdir '$repodir' create failed" >&2
+    echo "$0: repository not created, git subdir '$repodir' create failed" >&2
     exit 1
   fi
 fi
@@ -58,6 +65,11 @@ umask 027
 git --git-dir "$git_root/$repopath" init --bare
 [ $? -ne 0 ] && exit 1
 
+# Update the description
+if [ -n "$2" ]; then
+    echo $2 > $git_root/$repopath/description
+fi
+
 # Create symbolic links to any hook scripts in $githookspath
 hooks="pre-receive post-receive update post-update"
 backdir=$(echo "$repopath/hooks" | sed -e 's|[^/]*|..|g')