def sudo(*cmd)
# user can pass a single list in as an argument
# to allow usage like: sudo %w(apt-get install foo)
+ warn "You may need to enter your password here."
if cmd.length == 1 and cmd[0].class == Array
cmd = cmd[0]
end
# Returns 'true' if IP forwarding is enabled in the kernel
#
def ip_forwarding_enabled?
- %x(/sbin/sysctl --values net.ipv4.ip_forward) == "1\n"
+ %x(/sbin/sysctl -n net.ipv4.ip_forward) == "1\n"
end
-def find_ssh_key key_name
- # If the user already has a key loaded in their agent, use one of those
- agent_keys = `ssh-add -l`
- if agent_keys.empty?
- # Use a key named arvados_{key_name}_id_rsa, generating
- # a passphraseless key if necessary.
- ssh_key_file = "#{ENV['HOME']}/.ssh/arvados_#{key_name}_id_rsa"
- unless File.exists? ssh_key_file
- system 'ssh_keygen', '-f', ssh_key_file, '-P', ''
- end
- else
- # choose an agent key at random
- ssh_key_file = agent_keys.split("\n").first.split[2]
+def debootstrap_ok?
+ return system '/usr/sbin/debootstrap --version > /dev/null 2>&1'
+end
+
+def docker_ok?
+ return system 'docker images > /dev/null 2>&1'
+end
+
+# find_or_create_ssh_key arvados_name
+# Return the SSH public key appropriate for this Arvados instance,
+# generating one if necessary.
+#
+def find_or_create_ssh_key arvados_name
+ ssh_key_file = "#{ENV['HOME']}/.ssh/arvados_#{arvados_name}_id_rsa"
+ unless File.exists? ssh_key_file
+ system 'ssh-keygen',
+ '-f', ssh_key_file,
+ '-C', "arvados@#{arvados_name}",
+ '-P', ''
end
- return File.exists?("#{ssh_key_file}.pub") ? "#{ssh_key_file}.pub" : nil
+ return "#{ssh_key_file}.pub"
end
if not ip_forwarding_enabled?
warn "NOTE: IP forwarding must be enabled in the kernel."
- warn "Turning IP forwarding on. You may be asked to enter your password."
+ warn "Turning IP forwarding on now."
sudo %w(/sbin/sysctl net.ipv4.ip_forward=1)
end
warn "Installation instructions for a variety of platforms can be found at"
warn "http://docs.docker.io/en/latest/installation/"
exit
-elsif not system 'docker images > /dev/null 2>&1'
+elsif not docker_ok?
warn "WARNING: docker could not be run."
warn "Please make sure that:"
warn " * You have permission to read and write /var/run/docker.sock"
warn " * a 'cgroup' volume is mounted on your machine"
warn " * the docker daemon is running"
+ exit
+end
+
+# Check that debootstrap is installed.
+if not debootstrap_ok?
+ warn "Installing debootstrap."
+ sudo '/usr/bin/apt-get', 'install', 'debootstrap'
end
-# Generate a config.yml if it does not exist
-if not File.exists? 'config.yml'
+# Generate a config.yml if it does not exist or is empty
+if not File.size? 'config.yml'
print "Generating config.yml.\n"
print "Arvados needs to know the email address of the administrative user,\n"
print "so that when that user logs in they are automatically made an admin.\n"
config = YAML.load_file 'config.yml.example'
config['API_AUTO_ADMIN_USER'] = admin_email_address
config['API_HOSTNAME'] = generate_api_hostname
- config['PUBLIC_KEY_PATH'] = find_ssh_key(config['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)
# If all prerequisites are met, go ahead and build.
if ip_forwarding_enabled? and
- not docker_path.empty? and
+ docker_ok? and
+ debootstrap_ok? and
File.exists? 'config.yml'
warn "Building Arvados."
system '/usr/bin/make', *ARGV