X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/660e8d8345bfe7f34dfc8db655eff6a0af8bd47f..96fe9fc822c2270cb6e4212798d61e61481ec2e0:/docker/build_tools/config.rb diff --git a/docker/build_tools/config.rb b/docker/build_tools/config.rb index ae69fe29ec..ddf923736e 100755 --- a/docker/build_tools/config.rb +++ b/docker/build_tools/config.rb @@ -24,7 +24,7 @@ end # For each *.in file in the docker directories, substitute any # @@variables@@ found in the file with the appropriate config # variable. Support up to 10 levels of nesting. -# +# # TODO(twp): add the *.in files directory to the source tree, and # when expanding them, add them to the "generated" directory with # the same tree structure as in the original source. Then all @@ -34,37 +34,40 @@ Dir.glob('*/generated/*') do |stale_file| File.delete(stale_file) end +File.umask(022) Dir.glob('*/*.in') do |template_file| generated_dir = File.join(File.dirname(template_file), 'generated') Dir.mkdir(generated_dir) unless Dir.exists? generated_dir output_path = File.join(generated_dir, File.basename(template_file, '.in')) - output = File.open(output_path, "w") - File.open(template_file) do |input| - input.each_line do |line| + File.open(output_path, "w") do |output| + File.open(template_file) do |input| + input.each_line do |line| - @count = 0 - while @count < 10 - @out = line.gsub!(/@@(.*?)@@/) do |var| - if config.key?(Regexp.last_match[1]) - config[Regexp.last_match[1]] - else - var.gsub!(/@@/, '@_NOT_FOUND_@') + # This count is used to short-circuit potential + # infinite loops of variable substitution. + @count = 0 + while @count < 10 + @out = line.gsub!(/@@(.*?)@@/) do |var| + if config.key?(Regexp.last_match[1]) + config[Regexp.last_match[1]] + else + var.gsub!(/@@/, '@_NOT_FOUND_@') + end end + break if @out.nil? + @count += 1 end - break if @out.nil? - @count += 1 - end - output.write(line) + output.write(line) + end end end - output.close end # Copy the ssh public key file to base/generated (if a path is given) generated_dir = File.join('base/generated') Dir.mkdir(generated_dir) unless Dir.exists? generated_dir -if (config['PUBLIC_KEY_PATH'] != nil and +if (!config['PUBLIC_KEY_PATH'].nil? and File.readable? config['PUBLIC_KEY_PATH']) FileUtils.cp(config['PUBLIC_KEY_PATH'], File.join(generated_dir, 'id_rsa.pub'))