7 abort 'Error: Ruby >= 1.9.3 required.' if RUBY_VERSION < '1.9.3'
9 # Initialize config settings from config.yml
10 config = YAML.load_file('config.yml')
12 # ============================================================
13 # Add dynamically chosen config settings. These settings should
14 # be suitable for any installation.
16 # Any _PW/_SECRET config settings represent passwords/secrets. If they
17 # are blank, choose a password. Make sure the generated password
18 # doesn't change if config.yml doesn't change. Otherwise, keys won't
19 # match any more if (say) keep's files get regenerated but apiserver's
21 config.sort.map do |var,val|
22 if (var.end_with?('_PW') || var.end_with?('_SECRET')) && (config[var].nil? || config[var].empty?)
23 config[var] = Digest::SHA1.hexdigest(`hostname` + var + config.to_yaml)
27 # ============================================================
28 # For each *.in file in the docker directories, substitute any
29 # @@variables@@ found in the file with the appropriate config
30 # variable. Support up to 10 levels of nesting.
32 # TODO(twp): add the *.in files directory to the source tree, and
33 # when expanding them, add them to the "generated" directory with
34 # the same tree structure as in the original source. Then all
35 # the files can be added to the docker container with a single ADD.
37 if ARGV[0] and ARGV[0].length > 0
43 FileUtils.rm_r Dir.glob(globdir + '/generated/*')
46 Dir.glob(globdir + '/*.in') do |template_file|
47 generated_dir = File.join(File.dirname(template_file), 'generated')
48 Dir.mkdir(generated_dir) unless Dir.exists? generated_dir
49 output_path = File.join(generated_dir, File.basename(template_file, '.in'))
50 output_mode = (File.stat(template_file).mode & 0100) ? 0755 : 0644
51 File.open(output_path, "w", output_mode) do |output|
52 File.open(template_file) do |input|
53 input.each_line do |line|
55 # This count is used to short-circuit potential
56 # infinite loops of variable substitution.
59 @out = line.gsub!(/@@(.*?)@@/) do |var|
60 if config.key?(Regexp.last_match[1])
61 config[Regexp.last_match[1]]
63 var.gsub!(/@@/, '@_NOT_FOUND_@')