Class: Vagabund::Settler::Sources::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/vagabund/settler/sources/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



5
6
7
# File 'lib/vagabund/settler/sources/url.rb', line 5

def origin
  @origin
end

Instance Method Details

#download(machine, target_path) ⇒ Object Also known as: pull



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vagabund/settler/sources/url.rb', line 7

def download(machine, target_path)
  machine.ui.detail "Downloading #{origin} to #{target_path}..."
  unless machine.communicate.test "[ -d #{File.dirname(target_path)} ]"
    machine.communicate.sudo "mkdir -p #{File.dirname(target_path)}"
    machine.communicate.sudo "chown -R #{machine.ssh_info[:username]} #{File.dirname(target_path)}"
    machine.communicate.sudo "chgrp -R #{machine.ssh_info[:username]} #{File.dirname(target_path)}"
  end
  machine.communicate.execute "curl -L -o #{target_path} #{origin}" do |type,data|
    color = type == :stderr ? :red : :green
    options = {
      color: color,
      new_line: false,
      prefix: false
    }

    machine.ui.detail(data, options)
  end
  target_path
end