Work in progress arv-mount based on llfuse and supporting directories listings.
[arvados.git] / docker / config.rb
index 49004dad825b4f8c915e4374de4e704b18e98349..5e7242b4d50a23eeeabbc55daab684c94e8f9e6e 100755 (executable)
@@ -1,6 +1,9 @@
 #! /usr/bin/env ruby
 
 require 'yaml'
+require 'fileutils'
+
+abort 'Error: Ruby >= 1.9.3 required.' if RUBY_VERSION < '1.9.3'
 
 # Initialize config settings from config.yml
 config = YAML.load_file('config.yml')
@@ -9,19 +12,10 @@ config = YAML.load_file('config.yml')
 # Add dynamically chosen config settings. These settings should
 # be suitable for any installation.
 
-# The APP_SECRET the application uses (with OMNIAUTH_APP_ID) to
-# authenticate itself to Omniauth. By default this is generated
-# randomly when the application is built; you can instead
-# substitute a hardcoded string.
-config['OMNIAUTH_APP_SECRET'] = rand(2**512).to_s(36)
-
-# The secret token in services/api/config/initializers/secret_token.rb.
-config['API_SECRET'] = rand(2**256).to_s(36)
-
-# Any _PW config settings represent a database password.  If it
-# is blank, choose a password randomly.
+# Any _PW/_SECRET config settings represent passwords/secrets. If they
+# are blank, choose a password randomly.
 config.each_key do |var|
-  if var.end_with?('_PW') and (config[var].nil? or config[var].empty?)
+  if (var.end_with?('_PW') || var.end_with?('_SECRET')) && (config[var].nil? || config[var].empty?)
     config[var] = rand(2**256).to_s(36)
   end
 end
@@ -29,15 +23,50 @@ end
 # ============================================================
 # For each *.in file in the docker directories, substitute any
 # @@variables@@ found in the file with the appropriate config
-# variable.
+# 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
+# the files can be added to the docker container with a single ADD.
+
+Dir.glob('*/generated/*') do |stale_file|
+  File.delete(stale_file)
+end
 
 Dir.glob('*/*.in') do |template_file|
-  output_path = template_file.sub(/\.in$/, '')
+  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|
-      output.write(line.gsub(/@@(.*?)@@/) { |var| config[$1] || var })
+
+      @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
+
+      output.write(line)
     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.key?('PUBLIC_KEY_PATH') &&
+    ! (config['PUBLIC_KEY_PATH'] == '') &&
+    File.readable?(config['PUBLIC_KEY_PATH'])
+  FileUtils.cp(config['PUBLIC_KEY_PATH'],
+               File.join(generated_dir, 'id_rsa.pub'))
+end