From c53d4cede6bc46d03fa9866c9e0920e6d8a16a93 Mon Sep 17 00:00:00 2001
From: Sam Gleske <sag47@drexel.edu>
Date: Tue, 10 Sep 2013 23:37:01 -0400
Subject: [PATCH] Fully working add_mirror.sh

add_mirror.sh script will now add a git mirror to gitlab!

update_mirror.sh will now update mirrors that have been
added to gitlab!
---
 add_mirror.sh                | 29 ++++++++++++++++++++++++++++-
 git-mirrors.sh               |  1 +
 lib/create_gitlab_project.py |  3 ++-
 update_mirror.sh             | 22 ++++++++++++++++++++++
 4 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100755 update_mirror.sh

diff --git a/add_mirror.sh b/add_mirror.sh
index ed58fda..579135f 100755
--- a/add_mirror.sh
+++ b/add_mirror.sh
@@ -1,8 +1,35 @@
 #!/bin/bash
+#Tue Sep 10 23:01:08 EDT 2013
+#USAGE
+#  ./add_mirror.sh project_name http://example.com/project.git
+
 
 #Include all user options
 . "$(dirname $0)/config.sh"
 cd $(dirname $0)
 
 export token_secret gitlab_url gitlab_namespace gitlab_user
-python lib/create_gitlab_project.py test3
+
+#Get the remote gitlab url for the specified project.
+#If the project doesn't already exist in gitlab then create it.
+if python lib/create_gitlab_project.py $1 &> /dev/null;then
+  gitlab_remote=$(python lib/create_gitlab_project.py $1)
+else
+  echo "There was an unknown issue with create_gitlab_project.py" 1>&2
+  exit 1
+fi
+
+mkdir -p "${repo_dir}/${gitlab_namespace}"
+
+#create a mirror
+cd "${repo_dir}/${gitlab_namespace}"
+git clone --mirror $2 "$1"
+cd "$1"
+#add the gitlab remote
+git remote add gitlab ${gitlab_remote}
+git config --add remote.gitlab.push '+refs/heads/*:refs/heads/*'
+git config --add remote.gitlab.push '+refs/heads/*:refs/heads/*'
+#Check the initial repository into gitlab
+git fetch
+git remote prune origin
+git push gitlab
diff --git a/git-mirrors.sh b/git-mirrors.sh
index 622d113..7bfaf26 100755
--- a/git-mirrors.sh
+++ b/git-mirrors.sh
@@ -1,4 +1,5 @@
 #!/bin/bash
+#Tue Sep 10 23:01:08 EDT 2013
 
 #Include all user options
 
diff --git a/lib/create_gitlab_project.py b/lib/create_gitlab_project.py
index d600c1e..6ffd2e8 100755
--- a/lib/create_gitlab_project.py
+++ b/lib/create_gitlab_project.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+#Tue Sep 10 23:01:08 EDT 2013
 
 from sys import argv,exit,stderr
 import os
@@ -57,4 +58,4 @@ if not found_project:
     print >> stderr, "There was a problem creating {group}/{project}.  Did you give {user} user Admin rights in gitlab?".format(group=gitlab_namespace,project=project_name,user=gitlab_user)
     exit(1)
 
-print found_project['http_url_to_repo']
+print found_project['ssh_url_to_repo']
diff --git a/update_mirror.sh b/update_mirror.sh
new file mode 100755
index 0000000..d07819b
--- /dev/null
+++ b/update_mirror.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+#Tue Sep 10 23:01:08 EDT 2013
+#USAGE
+#  ./update_mirror.sh project_name
+
+
+#Include all user options
+. "$(dirname $0)/config.sh"
+cd $(dirname $0)
+
+if [ -z "$1" ];then
+  echo "Must specify a project_name!" 1>&2
+  exit 1
+elif [ ! -d "${repo_dir}/${gitlab_namespace}/$1" ];then
+  echo "No git repository for $1!  Perhaps run add_mirror.sh?" 1>&2
+  exit 1
+fi
+
+cd "${repo_dir}/${gitlab_namespace}/$1"
+git fetch
+git remote prune origin
+git push gitlab
-- 
GitLab