From 63a91a7fd2417d8502a6b51f1c50248e1a23b130 Mon Sep 17 00:00:00 2001
From: Jacob Vosmaer <jacob@gitlab.com>
Date: Tue, 11 Apr 2017 18:48:38 +0200
Subject: [PATCH] Install gitlab-shell with symlink and Go

---
 .gitignore                   |  2 ++
 Makefile                     | 11 ++++++++---
 support/symlink-gitlab-shell | 21 +++++++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100755 support/symlink-gitlab-shell

diff --git a/.gitignore b/.gitignore
index 0bbc648..330a4d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 /gitlab-shell/
+/gitlab-shell
 /.ssh/
 /gitlab-satellites/
 /repositories/
@@ -53,3 +54,4 @@
 /gitaly/
 /gitlab-workhorse/config.toml
 /gitlab-workhorse/.cache
+/go-gitlab-shell
diff --git a/Makefile b/Makefile
index 7108681..d903b73 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
 gitlab_repo = https://gitlab.com/gitlab-org/gitlab-ce.git
 gitlab_shell_repo = https://gitlab.com/gitlab-org/gitlab-shell.git
+gitlab_shell_clone_dir = go-gitlab-shell/src/gitlab.com/gitlab-org/gitlab-shell
 gitlab_workhorse_repo = https://gitlab.com/gitlab-org/gitlab-workhorse.git
 gitlab_workhorse_clone_dir = gitlab-workhorse/src/gitlab.com/gitlab-org/gitlab-workhorse
 gitaly_repo = https://gitlab.com/gitlab-org/gitaly.git
@@ -59,10 +60,14 @@ bundler:
 
 # Set up gitlab-shell
 
-gitlab-shell-setup: gitlab-shell/.git gitlab-shell/config.yml bundler .gitlab-shell-bundle gitlab-shell/.gitlab_shell_secret
+gitlab-shell-setup: symlink-gitlab-shell ${gitlab_shell_clone_dir}/.git gitlab-shell/config.yml bundler .gitlab-shell-bundle gitlab-shell/.gitlab_shell_secret
+	if [ -x gitlab-shell/bin/compile ] ; then gitlab-shell/bin/compile; fi
 
-gitlab-shell/.git:
-	git clone ${gitlab_shell_repo} gitlab-shell
+symlink-gitlab-shell:
+	support/symlink-gitlab-shell gitlab-shell ${gitlab_shell_clone_dir}
+
+${gitlab_shell_clone_dir}/.git:
+	git clone ${gitlab_shell_repo} ${gitlab_shell_clone_dir}
 
 gitlab-shell/config.yml:
 	sed -e "s|/home/git|${gitlab_development_root}|"\
diff --git a/support/symlink-gitlab-shell b/support/symlink-gitlab-shell
new file mode 100755
index 0000000..995bd1c
--- /dev/null
+++ b/support/symlink-gitlab-shell
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+require 'fileutils'
+require 'time'
+
+def main(symlink, target)
+  return if File.symlink?(symlink)
+
+  if File.exist?(symlink)
+    # there is an old directory at the symlink location
+    FileUtils.mv(symlink, "#{symlink}.#{Time.now.iso8601}")
+  end
+
+  FileUtils.ln_s(target, symlink)
+end
+
+if ARGV.count != 2
+  abort "Usage: #{$0} SYMLINK TARGET"
+end
+
+main(*ARGV)
-- 
GitLab