Top Level Namespace

Defined Under Namespace

Modules: Chake

Instance Method Summary collapse

Instance Method Details

#encrypted_for(node) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/chake.rb', line 83

def encrypted_for(node)
  encrypted_files = Dir.glob("**/files/{default,host-#{node}}/*.{asc,gpg}") + Dir.glob("**/files/*.{asc,gpg}")
  encrypted_files.inject({}) do |hash, key|
    hash[key] = key.sub(/\.(asc|gpg)$/, '')
    hash
  end
end

#if_files_changed(node, group_name, files) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/chake.rb', line 91

def if_files_changed(node, group_name, files)
  if files.empty?
    return
  end
  hash_io = IO.popen(['xargs', 'sha1sum'], 'w+')
  files.sort.each { |f| hash_io.puts(f) }
  hash_io.close_write
  current_hash = hash_io.read

  hash_file = File.join(Chake.tmpdir, node + '.' + group_name + '.sha1sum')
  hash_on_disk = nil
  if File.exists?(hash_file)
    hash_on_disk = File.read(hash_file)
  end

  if current_hash != hash_on_disk
    yield
  end
  FileUtils.mkdir_p(File.dirname(hash_file))
  File.open(hash_file, 'w') do |f|
    f.write(current_hash)
  end
end

#write_json_file(file, data) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/chake.rb', line 116

def write_json_file(file, data)
  File.chmod(0600, file) if File.exists?(file)
  File.open(file, 'w', 0600) do |f|
    f.write(JSON.pretty_generate(data))
    f.write("\n")
  end
end