From cbf51276c8b57b598de3a25fadc7b3fcde7ab741 Mon Sep 17 00:00:00 2001
From: Sam Gleske <sag47@drexel.edu>
Date: Thu, 12 Sep 2013 12:35:36 -0400
Subject: [PATCH] Some argument parsing in add_mirror.sh (not functional)

---
 .gitignore    |   2 +
 add_mirror.sh | 105 ++++++++++++++++++++++++++++++++++++++++++++++++--
 config.sh     |  22 -----------
 3 files changed, 104 insertions(+), 25 deletions(-)
 create mode 100644 .gitignore
 delete mode 100644 config.sh

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3a26abf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+config.sh
+*.pyc
diff --git a/add_mirror.sh b/add_mirror.sh
index 53bb095..bf82bfa 100755
--- a/add_mirror.sh
+++ b/add_mirror.sh
@@ -3,15 +3,114 @@
 #USAGE
 #  ./add_mirror.sh project_name http://example.com/project.git
 
+#Include all user options
+. "$(dirname $0)/config.sh"
+cd $(dirname $0)
+
+PROGNAME="${0##*/}"
+PROGVERSION="v0.2"
+
+
+#Default script options
+svn=false
+git=false
+project_name=""
+mirror=""
+
+#Short options are one letter.  If an argument follows a short opt then put a colon (:) after it
+SHORTOPTS="hvm:p:"
+LONGOPTS="help,version,git,svn,mirror:,project:"
+
+usage()
+{
+  cat <<EOF
+${PROGNAME} ${PROGVERSION} - MIT License by Sam Gleske
+
+DESCRIPTION:
+  This will add a git or SVN repository to be mirrored by GitLab.  It 
+  first checks to see if the project exists in gitlab.  If it does
+  not exist then it creates it.  It will then clone and check in the
+  first copy into GitLab.  From there you must use the update_mirror.sh
+  script or git git-mirrors.sh script.
+
+  -h,--help          Show help
+  -v,--version       Show program version
+  --git              Mirror a git repository (must be explicitly set)
+  --svn              Mirror a SVN repository (must be explicitly set)
+  --project NAME     Set a GitLab project name to NAME.
+  --mirror URL       Repository URL to be mirrored.
+
+
+EOF
+}
+
+ARGS=$(getopt -s bash --options "${SHORTOPTS}" --longoptions "${LONGOPTS}" --name "${PROGNAME}" -- "$@")
+eval set -- "$ARGS"
+echo "$ARGS"
+while true; do
+  case $1 in
+    -h|--help)
+        usage
+        exit 1
+      ;;
+    -v|--version)
+        echo "${PROGNAME} ${PROGVERSION}"
+        exit 1
+      ;;
+    --git)
+        git=true
+        shift
+      ;;
+    --svn)
+        svn=true
+        shift
+      ;;
+    -p|--project)
+        project_name="${2}"
+        shift 2
+      ;;
+    -m|--mirror)
+        mirror="${2}"
+        shift 2
+      ;;
+    --)
+        shift
+        break
+      ;;
+    *)
+        shift
+        break
+      ;;
+    esac
+done
+
+
+echo "svn=${svn}"
+echo "git=${git}"
+echo "project_name=${project_name}"
+echo "mirror=${mirror}"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+exit
+
 if [ "${#}" -lt "2" ];then
   echo "Not enough arguments." 1>&2
   echo "e.g. ./add_mirror.sh project_name http://example.com/project.git" 1>&2
   exit 1
 fi
 
-#Include all user options
-. "$(dirname $0)/config.sh"
-cd $(dirname $0)
 
 #export env vars for python script
 export gitlab_user_token_secret gitlab_url gitlab_namespace gitlab_user
diff --git a/config.sh b/config.sh
deleted file mode 100644
index 2bc5152..0000000
--- a/config.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#Environment file
-
-#
-# gitlab-mirror settings
-#
-
-system_user="gitmirror"
-user_home="/home/${system_user}"
-repo_dir="${user_home}/repositories"
-
-#
-# Gitlab settings
-#
-
-#This is the Gitlab group where all project mirrors will be grouped.
-gitlab_namespace="Mirrors"
-#This is the web url of your Gitlab server. no trailing slash, just the protocol and server name.
-gitlab_url="https://comet.irt.drexel.edu"
-#Special user you created in Gitlab whose only purpose is to update mirror sites and admin the $gitlab_namespace group.
-gitlab_user="gitmirror"
-#Generate a token for your $gitlab_user and set it here.
-gitlab_user_token_secret="$(head -n1 "${user_home}/private_token")"
-- 
GitLab