def call(env)
return @app.call(env) unless @machine.provider_config.setup?
return @app.call(env) unless @machine.config.ssh.username
user = @machine.config.ssh.username
@machine.config.ssh.username = 'root'
env[:ui].info I18n.t('vagrant_digital_ocean.info.creating_user', {
:user => user
})
@machine.communicate.execute(<<-BASH)
if ! (grep ^#{user}: /etc/passwd); then
useradd -m -s /bin/bash #{user};
fi
BASH
@machine.communicate.execute(<<-BASH)
if ! (grep #{user} /etc/sudoers); then
echo "#{user} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers;
else
sed -i -e "/#{user}/ s/=.*/=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers;
fi
BASH
@machine.communicate.execute("su #{user} -c 'mkdir -p ~/.ssh'")
path = @machine.config.ssh.private_key_path
path = path[0] if path.is_a?(Array)
path = File.expand_path(path, @machine.env.root_path)
pub_key = DigitalOcean.public_key(path)
@machine.communicate.execute(<<-BASH)
if ! grep '#{pub_key}' /home/#{user}/.ssh/authorized_keys; then
echo '#{pub_key}' >> /home/#{user}/.ssh/authorized_keys;
fi
chown -R #{user} /home/#{user}/.ssh;
BASH
@machine.config.ssh.username = user
@app.call(env)
end