Browse Source

Unfinished support for git

Serj Kalichev 10 years ago
parent
commit
94e34b24e6
1 changed files with 69 additions and 70 deletions
  1. 69 70
      scripts/rfa

+ 69 - 70
scripts/rfa

@@ -1,32 +1,15 @@
-#!/bin/bash
-
-# Config file name
-rfa_conf=/etc/repoforge/rfa.conf
-
-# Defaults for rfa.conf
-group_gid_min=3000
-group_w_prefix=svn_w-
-group_r_prefix=svn_r-
-repository_root=
-repository_link=
-
-# Options
-opts_force=0
-
-todo=""
+#!/bin/sh
 
 # Echo help information
 usage()
 {
 	cat <<EOF
 Usage: $0 [options] <command> <parameters>
-Tool for VCS repository administration. Now supports
-Subversion only.
-
+  Tool for VCS repository administration.
+  VCS support: $possible_vcs
 Options:
   -h, --help
 	Print help message.
-
 Commands:
   add <repository1> [repository2] ...
 	Create new repository.
@@ -191,89 +174,105 @@ user_del()
 	done
 }
 
+#------------------ MAIN -----------------------------------------
+
+possible_vcs="svn git"
+
+# Defaults for rfa.conf
+group_gid_min="3000"
+group_w_prefix="vcs_w-"
+group_r_prefix="vcs_r-"
+repository_root=
+repository_link=
+
 # Parse command line options
-cmd_options=$(getopt -o "+hfl:" -l help,force,level -- "$@")
-if test "$?" != 0; then
-	usage
-	exit 1
-fi
+action="help"
+opts_force=0
+opts_conf="/etc/repoforge/rfa.conf"
+opts_vcs="svn"
 
-eval set -- ${cmd_options}
-while  test "$1" != "--"; do
-	case "$1" in
-	-h|--help) 
+while test "x$1" != "x"; do
+	option="$1"
+	case "$option" in
+	-h|--help)
 		usage
-		exit 0 
+		exit 0
 		;;
 	-f|--force)
 		opts_force=1
 		;;
-	-l|--level)
+	# Config file
+	-c)
 		shift
-		level=$1 
+		opts_conf="$1"
 		;;
+	--config=*)
+		opts_conf=`echo "$option" | sed 's/--config=//'`
+		;;
+	# Choose VCS
+	-s)
+		shift
+		opts_vcs="$1"
+		;;
+	--vcs=*)
+		opts_vcs=`echo "$option" | sed 's/--vcs=//'`
+		;;
+	# Default
 	*)
+		action="$option"
+		shift
+		break
 		;;
 	esac
 	shift
 done
-shift
 
-. $rfa_conf
+test "x$action" = "xhelp" && { usage; exit 0; }
 
-if [ $# -lt 1 ]; then
-	echo "Command is expected"
-	exit -1
-fi
+# Check options
+bad_vcs=1
+for v in $possible_vcs; do
+	test "x$opts_vcs" = "x$v" && { bad_vcs=""; break; }
+done
+test "x$bad_vcs" = "x" || { echo "Error: Illegal VCS \"$opts_vcs\"" 1>&2; exit 1; }
 
-case "$1" in
-"help") 
-	usage
-	exit 0 
-	;;
+# Include config file
+test -r "$opts_conf" && . $opts_conf
+# Compatibility (suppose SVN)
+test "x$repository_svn_root" = "x" && repository_svn_root="$repository_root"
+test "x$repository_svn_link" = "x" && repository_svn_link="$repository_link"
+eval repository_root="\$repository_${opts_vcs}_root"
+eval repository_link="\$repository_${opts_vcs}_link"
+test "x$repository_root" = "x" && { echo "Error: Illegal repository root \"\"" 1>&2; exit 1; }
+test "x$repository_link" = "x" && { echo "Error: Illegal repository link \"\"" 1>&2; exit 1; }
+test -d "$repository_root" || { echo "Error: Illegal repository root \"$repository_root\"" 1>&2; exit 1; }
+test -d "$repository_link" || { echo "Error: Illegal repository link \"$repository_link\"" 1>&2; exit 1; }
+
+# Action
+case "$action" in
 "add")
-	if [ $# -lt 2 ]; then
-		echo "Repository name is expected"
-		exit -1
-	fi
-	shift
+	test $# -lt 1 && { echo "Error: Repository name is expected" 1>&2; exit 1; }
 	repository_add "$@"
 	;;
 "fixmod")
-	if [ $# -lt 2 ]; then
-		echo "Repository name is expected"
-		exit -1
-	fi
-	shift
+	test $# -lt 1 && { echo "Error: Repository name is expected" 1>&2; exit 1; }
 	repository_fixmod "$@"
 	;;
 "del")
-	if [ $# -lt 2 ]; then
-		echo "Repository name is expected"
-		exit -1
-	fi
-	shift
+	test $# -lt 1 && { echo "Error: Repository name is expected" 1>&2; exit 1; }
 	repository_del "$@"
 	;;
 "adduser"|"useradd")
-	if [ $# -lt 4 ]; then
-		echo "Not enought parameters"
-		exit -1
-	fi
-	shift
+	test $# -lt 3 && { echo "Error: Not enough parameters" 1>&2; exit 1; }
 	user_add "$@"
 	;;
 "deluser"|"userdel")
-	if [ $# -lt 4 ]; then
-		echo "Not enought parameters"
-		exit -1
-	fi
-	shift
+	test $# -lt 3 && { echo "Error: Not enough parameters" 1>&2; exit 1; }
 	user_del "$@"
 	;;
 *)
-	echo "Unknown command"
-	exit -1
+	echo "Error: Unknown command" 1>&2
+	exit 1
 	;;
 esac