Skip to content

Instantly share code, notes, and snippets.

@hkparker
Created July 29, 2016 08:11
Show Gist options
  • Save hkparker/2e1b9cc128c9cb0b80e3ad8b26b5e32a to your computer and use it in GitHub Desktop.
Save hkparker/2e1b9cc128c9cb0b80e3ad8b26b5e32a to your computer and use it in GitHub Desktop.
encrypt file content and paths
require 'json'
require 'shellwords'
present = []
names = {}
["hayden", "xobackups"].each do |dir|
Dir["#{dir}/**/*"].each do |path|
next if !File.file?(path)
newname = `echo "#{path}" | sha256sum | cut -d ' ' -f 1`.strip
present << "exported/#{newname}"
names[newname] = path
if !File.file?("exported/#{newname}") || File.mtime("exported/#{newname}") < File.mtime(path)
puts "openssl aes-256-cbc -a -salt -in #{Shellwords.shellescape path} -out 'exported/#{newname}' -k PASSWORD"
`openssl aes-256-cbc -a -salt -in #{Shellwords.shellescape path} -out 'exported/#{newname}' -k #{ENV.fetch('OFFSITEKEY')}`
end
end
end
Dir["exported/**/*"].each do |exported|
if !present.include? exported
File.delete exported
end
end
File.open("file_names", 'w') do |file|
file.write JSON.dump(names)
end
puts "openssl aes-256-cbc -a -salt -in file_names -out 'exported/file_names' -k PASSWORD"
`openssl aes-256-cbc -a -salt -in file_names -out 'exported/file_names' -k #{ENV.fetch('OFFSITEKEY')}`
File.delete("file_names")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment