3414: rename replicator to pull_list
[arvados.git] / docker / build_tools / build.rb
index 1a914b58b354e4ce54cd3471edce03d119fd7a70..e7f2b7db1af625fff846f95ba93a5dd14b7ecced 100755 (executable)
@@ -14,7 +14,7 @@ def main options
   # Check that:
   #   * Docker is installed and can be found in the user's path
   #   * Docker can be run as a non-root user
-  #      - TODO: put the user is in the docker group if necessary
+  #      - TODO: put the user in the docker group if necessary
   #      - TODO: mount cgroup automatically
   #      - TODO: start the docker service if not started
 
@@ -64,15 +64,28 @@ def main options
       end
     end
 
+    print "Arvados needs to know the shell login name for the administrative user.\n"
+    print "This will also be used as the name for your git repository.\n"
+    print "\n"
+    user_name = ""
+    until is_valid_user_name? user_name
+      print "Enter a shell login name here: "
+      user_name = gets.strip
+      if not is_valid_user_name? user_name
+        print "That doesn't look like a valid shell login name. Please try again.\n"
+      end
+    end
+
     File.open 'config.yml', 'w' do |config_out|
+      config_out.write "# If a _PW or _SECRET variable is set to an empty string, a password\n"
+      config_out.write "# will be chosen randomly at build time. This is the\n"
+      config_out.write "# recommended setting.\n\n"
       config = YAML.load_file 'config.yml.example'
       config['API_AUTO_ADMIN_USER'] = admin_email_address
+      config['ARVADOS_USER_NAME'] = user_name
       config['API_HOSTNAME'] = generate_api_hostname
       config['PUBLIC_KEY_PATH'] = find_or_create_ssh_key(config['API_HOSTNAME'])
       config.each_key do |var|
-        if var.end_with?('_PW') or var.end_with?('_SECRET')
-          config[var] = rand(2**256).to_s(36)
-        end
         config_out.write "#{var}: #{config[var]}\n"
       end
     end
@@ -83,8 +96,9 @@ def main options
       docker_ok? docker_path and
       debootstrap_ok? and
       File.exists? 'config.yml'
-    warn "Building Arvados."
-    system '/usr/bin/make', '-f', options[:makefile], *ARGV
+    exit 0
+  else
+    exit 6
   end
 end
 
@@ -114,6 +128,15 @@ def is_valid_email? str
   str.match /^\S+@\S+\.\S+$/
 end
 
+# is_valid_user_name?
+#   Returns true if its arg looks like a valid unix username.
+#   This is a very very loose sanity check.
+#
+def is_valid_user_name? str
+  # borrowed from Debian's adduser (version 3.110)
+  str.match /^[_.A-Za-z0-9][-\@_.A-Za-z0-9]*\$?$/
+end
+
 # generate_api_hostname
 #   Generates a 5-character randomly chosen API hostname.
 #
@@ -221,6 +244,5 @@ if __FILE__ == $PROGRAM_NAME
       options[:makefile] = mk
     end
   end
-
   main options
 end