diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-03 20:43:25 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-03 20:43:25 +0200 |
commit | e620575dcdfa3214229d5e660016e6410117729f (patch) | |
tree | 7feb657b070e2290240eb32ada29ede3d3f74d35 | |
parent | bb9863e87055daf8347de65847c4a0a82ab0dfa8 (diff) | |
download | gitlab-shell-e620575dcdfa3214229d5e660016e6410117729f.tar.gz |
working git upload
-rwxr-xr-x | bin/gitlab-shell | 11 | ||||
-rw-r--r-- | lib/gitlab_shell.rb | 31 |
2 files changed, 38 insertions, 4 deletions
diff --git a/bin/gitlab-shell b/bin/gitlab-shell index e8799bb..0c3b654 100755 --- a/bin/gitlab-shell +++ b/bin/gitlab-shell @@ -1,11 +1,14 @@ #!/usr/bin/env ruby +unless ENV['SSH_CONNECTION'] + puts "Only ssh allowed" + exit +end # # GitLab shell, invoked from ~/.ssh/authorized_keys # - -ROOT_PATH = File.expand_path('..', __FILE__) - -puts ENV['SSH_CONNECTION'].inspect +ROOT_PATH = File.join(File.expand_path(File.dirname(__FILE__)), "..") +require File.join(ROOT_PATH, 'lib', 'gitlab_shell') +GitlabShell.new.exec exit diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb new file mode 100644 index 0000000..4d4d240 --- /dev/null +++ b/lib/gitlab_shell.rb @@ -0,0 +1,31 @@ +require 'open3' +class GitlabShell + attr_accessor :username, :repo_name, :git_cmd + + def initialize + @username = ARGV.shift + @origin_cmd = ENV['SSH_ORIGINAL_COMMAND'] + end + + def exec + if @origin_cmd + parse_cmd + + return system("git-upload-pack /home/gip/repositories/#{@repo_name}") + else + puts "Welcome #{@username}!" + end + end + + protected + + def parse_cmd + args = @origin_cmd.split(' ') + @git_cmd = args.shift + @repo_name = args.shift + end + + def git_cmds + %w(git-upload-pack git-receive-pack git-upload-archive) + end +end |