-
Notifications
You must be signed in to change notification settings - Fork 52
/
gitlabgen.rb
68 lines (48 loc) · 1.94 KB
/
gitlabgen.rb
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'openssl'
require 'gitlab/license'
# Generate a key pair. You should do this only once.
#key_pair = OpenSSL::PKey::RSA.generate(2048)
# Write it to a file to use in the license generation application.
#File.open("license_key", "w") { |f| f.write(key_pair.to_pem) }
# Extract the public key.
#public_key = key_pair.public_key
# Write it to a file to ship along with the main application.
#File.open("license_key.pub", "w") { |f| f.write(public_key.to_pem) }
# In the license generation application, load the private key from a file.
private_key = OpenSSL::PKey::RSA.new File.read("license_key")
Gitlab::License.encryption_key = private_key
# Build a new license.
license = Gitlab::License.new
name = nil
company = nil
email = nil
# License information to be rendered as a table in the admin panel.
# E.g.: "This instance of GitLab Enterprise Edition is licensed to:"
# Specific keys don't matter, but there needs to be at least one.
#First we query the user for their info
puts "Please enter your name: "
name = gets.chomp
puts "Great, now your company name: "
company = gets.chomp
puts "Amazing! Lastly please input your email: "
email = gets.chomp
license.licensee = {
"Name" => name,
"Company" => company,
"Email" => email
}
# The date the license starts.
# Required.
license.starts_at = Date.today
# Restrictions bundled with this license.
# Not required, to allow unlimited-user licenses for things like educational organizations.
license.restrictions = {
:plan => "ultimate",
:id => rand(1000..99999999)
}
# Export the license, which encrypts and encodes it.
data = license.export
puts "Exported license to file '#{company}.gitlab-license'"
File.open("#{company}.gitlab-license", 'w') { |file| file.write(data) }
puts data
puts "Don't forget to replace the public key in /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub! Good luck!"