]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - scripts/gitcreate
gitcreate: correct typo in error message
[repo_shell.git] / scripts / gitcreate
index 3c7cd36a447b7bee5ab0ef0207e14b88dece1650..4dadacd270f938328c1215e759d6b2543ee8cb36 100755 (executable)
@@ -6,7 +6,16 @@ if [ -z "$owner" -o -z "$git_root" ]; then
     echo "$0: please configure /etc/repo_shell.conf"
     exit 1
 fi
-gitacls="$git_root/.gitacls"
+gitacls=.gitacls
+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
@@ -45,7 +54,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
@@ -55,7 +64,16 @@ umask 027
 git --git-dir "$git_root/$repopath" init --bare
 [ $? -ne 0 ] && exit 1
 
-[ -f "$gitacls" ] && echo "Check $gitacls for proper access permissions"
+# 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')
+hookscripts=$(cd $githookspath 2>/dev/null && ls -d $hooks 2>/dev/null)
+for s in $hookscripts; do
+    echo "Linking default hook script $s"
+    ln -s $backdir/$githooks/$s $git_root/$repopath/hooks/
+done
+
+[ -f "$gitaclspath" ] && echo "Check $gitaclspath for proper access permissions"
 echo "Repository created."
-[ ! -f "$gitacls" ] && echo "WARNING: $gitacls DOES NOT EXIST!"
+[ ! -f "$gitaclspath" ] && echo "WARNING: $gitaclspath DOES NOT EXIST!"
 exit 0