Created
July 29, 2016 08:11
-
-
Save hkparker/2e1b9cc128c9cb0b80e3ad8b26b5e32a to your computer and use it in GitHub Desktop.
encrypt file content and paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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