Module: Capistrano::Cluster::Files::DSL

Defined in:
lib/capistrano/cluster/files.rb

Instance Method Summary collapse

Instance Method Details

#item(identifier) ⇒ Object



41
42
43
44
45
46
# File 'lib/capistrano/cluster/files.rb', line 41

def item(identifier)
  consume = false
  xml = File.read(caller.first.split(":").first).lines.select { |l| consume ||= l =~/^__END__$/ || consume}[1..-1].join()
  doc = Nokogiri::HTML(xml)
  doc.css("##{identifier}").inner_html
end

#remote_file(url, file, checksum: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/capistrano/cluster/files.rb', line 7

def remote_file(url, file, checksum: nil)
  file = File.expand_path(file)

  if test "[ -f '#{file}' ]"
    if checksum
      return if checksum == capture("sha256sum '#{file}' | awk '{ print $1}'")
      execute :rm, "-f", file
    else
      return
    end
  end
  execute :mkdir, "-p", File.dirname(file)
  execute :wget, "-q", "-o", "/dev/null" , "-O", file, url
end

#upload_as(user, file, remote_file, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/capistrano/cluster/files.rb', line 22

def upload_as(user, file, remote_file, options={})
  group = options.fetch(:group, user)

  tmp_name = "/tmp/#{SecureRandom.uuid}"
  upload! file, tmp_name

  sudo :mv, tmp_name, remote_file

  unless test "[[ -d #{File.dirname(remote_file)} ]]"
    sudo :mkdir, "-p", File.dirname(remote_file)
    sudo :chown, "-R", "#{user}:#{group}", File.dirname(remote_file)

  end

  sudo :chown, "#{user}:#{group}", remote_file
  sudo :chmod, options.fetch(:mode, 644), remote_file

end