summaryrefslogtreecommitdiff
path: root/lib/tasks/gitlab/shell.rake
blob: c02fbad0214ec8e2e277b6b20071e979f28a6291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace :gitlab do
  namespace :shell do
    desc "GITLAB | Setup gitlab-shell"
    task setup: :environment do
      setup
    end

    desc "GITLAB | Build missing projects"
    task build_missing_projects: :environment do
      Project.find_each(batch_size: 1000) do |project|
        path_to_repo = File.join(Gitlab.config.gitolite.repos_path, "#{project.path_with_namespace}.git")
        if File.exists?(path_to_repo)
          print '-'
        else
          if Gitlab::Shell.new.add_repository(project.path_with_namespace)
            print '.'
          else
            print 'F'
          end
        end
      end
    end
  end

  def setup
    warn_user_is_not_gitlab

    puts "This will rebuild an authorized_keys file."
    puts "You will lose any data stored in /home/git/.ssh/authorized_keys."
    ask_to_continue
    puts ""

    system("echo '# Managed by gitlab-shell' > /home/git/.ssh/authorized_keys")

    Key.find_each(batch_size: 1000) do |key|
      if Gitlab::Shell.new.add_key(key.shell_id, key.key)
        print '.'
      else
        print 'F'
      end
    end

  rescue Gitlab::TaskAbortedByUserError
    puts "Quitting...".red
    exit 1
  end
end