2016-06-02 11:05:42 +05:30
|
|
|
user_args = {
|
|
|
|
email: ENV['GITLAB_ROOT_EMAIL'].presence || 'admin@example.com',
|
|
|
|
name: 'Administrator',
|
|
|
|
username: 'root',
|
|
|
|
admin: true
|
|
|
|
}
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
if ENV['GITLAB_ROOT_PASSWORD'].blank?
|
2016-06-02 11:05:42 +05:30
|
|
|
user_args[:password_automatically_set] = true
|
|
|
|
user_args[:force_random_password] = true
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
2016-06-02 11:05:42 +05:30
|
|
|
user_args[:password] = ENV['GITLAB_ROOT_PASSWORD']
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
# 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
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
if user.persisted?
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "Administrator account created:".color(:green)
|
2016-06-02 11:05:42 +05:30
|
|
|
puts
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "login: root".color(:green)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
if user_args.key?(:password)
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "password: #{user_args[:password]}".color(:green)
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "password: You'll be prompted to create one on your first visit.".color(:green)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
puts
|
|
|
|
else
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "Could not create the default administrator account:".color(:red)
|
2016-06-02 11:05:42 +05:30
|
|
|
puts
|
|
|
|
user.errors.full_messages.map do |message|
|
2016-06-16 23:09:34 +05:30
|
|
|
puts "--> #{message}".color(:red)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
puts
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
exit 1
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|