shell.rake 1.2 KB
Newer Older
D
Dmitriy Zaporozhets 已提交
1 2 3
namespace :gitlab do
  namespace :shell do
    desc "GITLAB | Setup gitlab-shell"
4
    task setup: :environment do
D
Dmitriy Zaporozhets 已提交
5 6
      setup
    end
7 8 9 10

    desc "GITLAB | Build missing projects"
    task build_missing_projects: :environment do
      Project.find_each(batch_size: 1000) do |project|
11
        path_to_repo = File.join(Gitlab.config.gitlab_shell.repos_path, "#{project.path_with_namespace}.git")
12 13 14 15 16 17 18 19 20 21 22
        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
D
Dmitriy Zaporozhets 已提交
23 24 25 26 27
  end

  def setup
    warn_user_is_not_gitlab

28 29
    unless ENV['force'] == 'yes'
      puts "This will rebuild an authorized_keys file."
30
      puts "You will lose any data stored in authorized_keys file."
31 32 33
      ask_to_continue
      puts ""
    end
D
Dmitriy Zaporozhets 已提交
34

35
    Gitlab::Shell.new.remove_all_keys
D
Dmitriy Zaporozhets 已提交
36

37
    Key.find_each(batch_size: 1000) do |key|
D
Dmitriy Zaporozhets 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50
      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