BigW Consortium Gitlab

001_admin.rb 1.13 KB
Newer Older
1 2 3 4 5 6 7
user_args = {
  email:    ENV['GITLAB_ROOT_EMAIL'].presence || 'admin@example.com',
  name:     'Administrator',
  username: 'root',
  admin:    true
}

8
if ENV['GITLAB_ROOT_PASSWORD'].blank?
9 10
  user_args[:password_automatically_set] = true
  user_args[:force_random_password] = true
11
else
12
  user_args[:password] = ENV['GITLAB_ROOT_PASSWORD']
13
end
14

15 16 17 18
# Only admins can create other admin users in Users::CreateService so to solve
# the chicken-and-egg problem, we pass a non-persisted admin user to the service.
transient_admin = User.new(admin: true)
user = Users::CreateService.new(transient_admin, user_args.merge!(skip_confirmation: true)).execute
gitlabhq committed
19

20
if user.persisted?
21
  puts "Administrator account created:".color(:green)
22
  puts
23
  puts "login:    root".color(:green)
gitlabhq committed
24

25
  if user_args.key?(:password)
26
    puts "password: #{user_args[:password]}".color(:green)
27
  else
28
    puts "password: You'll be prompted to create one on your first visit.".color(:green)
29 30 31
  end
  puts
else
32
  puts "Could not create the default administrator account:".color(:red)
33 34
  puts
  user.errors.full_messages.map do |message|
35
    puts "--> #{message}".color(:red)
36 37
  end
  puts
gitlabhq committed
38

39
  exit 1
gitlabhq committed
40
end