]> oss.titaniummirror.com Git - repo_shell.git/blobdiff - scripts/gitcreate
Fixes for when /etc/repo_shell.conf is not present
[repo_shell.git] / scripts / gitcreate
index 7a46d1b0ab6e0b62652339e9ba4fc6da27e46dea..c19839f35844137716b9f6f1d0274468f41cf7c8 100755 (executable)
@@ -1,9 +1,10 @@
 #!/bin/sh
 # gitcreate is part of the repo_shell distribution.
 
-eval $(sed -e 's| ||g' < /etc/repo_shell.conf)
+eval $([ -f /etc/repo_shell.conf ] && sed -e 's| ||g' < /etc/repo_shell.conf)
 if [ -z "$owner" -o -z "$git_root" ]; then
     echo "$0: please configure /etc/repo_shell.conf"
+    exit 1
 fi
 gitacls="$git_root/.gitacls"
 
@@ -12,6 +13,12 @@ if [ "$(whoami)" != "$owner" ]; then
     exit 1
 fi
 
+unset yes
+if [ "$1" = "-y" ]; then
+  yes=y
+  shift
+fi
+
 if [ $# -ne 1 ]; then
     echo "usage: $0 <repopath>" >&2
     exit 1
@@ -25,18 +32,19 @@ fi
 # Do not create subdirectories without asking first
 repopath=$(dirname $1)
 if [ ! -d "$git_root/$repopath" ]; then
-  echo -n "Create git subdir '$repopath' (y/N)? "
-  read ans
-  if [ "$ans" = "y" -o "$ans" = "Y" -o "$ans" = "yes" -o "$ans" = "Yes" \
-      -o "$ans" = "YES" ];then
-    mkdir -p "$git_root/$repopath" 2>/dev/null
-    if [ ! -d "$git_root/$repopath" ]; then
-      echo "%0: repository not created, git subdir '$repopath' create failed" >&2
-      exit 1
+  if [ ! $yes ]; then
+    echo -n "Create git subdir '$repopath' (y/N)? "
+    read ans
+    ans=$(expr "$ans" : '\(.\).*') # works with dash too
+    if [ "$ans" != "y" -a "$ans" != "Y" ];then
+      echo "repository creation aborted at user request"
+      exit 0
     fi
-  else
-    echo "repository creation aborted at user request"
-    exit 0
+  fi
+  mkdir -p "$git_root/$repopath" 2>/dev/null
+  if [ ! -d "$git_root/$repopath" ]; then
+    echo "%0: repository not created, git subdir '$repopath' create failed" >&2
+    exit 1
   fi
 fi