diff options
| author | Paul Buetow <paul@mimecast.com> | 2018-06-03 08:40:57 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@mimecast.com> | 2018-06-03 08:40:57 +0100 |
| commit | 39a7abf0f72921beee10974402bf599454ece233 (patch) | |
| tree | 985f350c23d7827d345a23d7531f1d53b6496301 | |
| parent | d7b3c055de742c0817407710eb6df869ae225414 (diff) | |
| parent | 03a3ec4f28bf494902d3046909474c7201542dad (diff) | |
resolve conflict
| -rwxr-xr-x | geheim.rb | 59 |
1 files changed, 52 insertions, 7 deletions
@@ -22,7 +22,6 @@ module Git dirname, basename = File.dirname(file), File.basename(file) Dir.chdir(dirname) puts %x{git add "#{basename}"} - #puts %x{git commit -m "Add #{file}"} if commit Dir.chdir(@wd) end @@ -30,7 +29,6 @@ module Git dirname, basename = File.dirname(file), File.basename(file) Dir.chdir(dirname) puts %x{git rm "#{basename}"} - #puts %x{git commit -m "Remove #{file}"} if commit Dir.chdir(@wd) end @@ -71,8 +69,12 @@ module Encryption super() if @@key.nil? @@key = File.read($key_file) - print "IV: " - input = STDIN.noecho(&:gets).chomp + if ENV['PIN'] + input = ENV['PIN'] + else + print "PIN: " + input = $stdin.gets.chomp + end iv = input * 2 + "Hello world" + input * 2 @@iv = iv[0..15] end @@ -238,7 +240,9 @@ class Geheim end end - def ls(search_term: nil, show: false, export: false) + def ls(search_term: nil, show: false, export: false, open: false) + export = true if open + indexes = Array.new walk_indexes(search_term: search_term) do |index| indexes << index @@ -248,7 +252,9 @@ class Geheim if show and !index.is_binary? print index.get_data elsif export - index.get_data.export(destination_file: File.basename(index.description)) + destination_file = File.basename(index.description) + index.get_data.export(destination_file: destination_file) + shred_file(file: open_exported(file: destination_file), delay: 3) if open end end end @@ -304,6 +310,40 @@ class Geheim end end + def shred_all_exported + puts "Shredding all exported files" + Dir.glob("#{$export_dir}/*").each do |file| + shred_file(file: file) + end + end + + private def shred_file(file:, delay: 0) + %x{which shred} + sleep(delay) + if $?.success? + run_command("shred -vu #{file}") + else + run_command("rm -Pfv #{file}") + end + end + + private def open_exported(file:) + file_path = "#{$export_dir}/#{file}" + case ENV['UNAME'] + when 'Darwin' + run_command("open #{file_path}") + when 'Microsoft' + run_command("winopen #{file_path}") + else + run_command("termux-open #{file_path}") + end + file_path + end + + private def run_command(cmd) + puts "#{cmd}: #{%x{#{cmd}}}" + end + private def walk_indexes(search_term:) Dir.glob("#{$data_dir}/**/*.index").each do |index_file| index = Index.new(index_file: index_file.sub($data_dir, "")) @@ -336,10 +376,11 @@ class CLI SEARCHTERM show SEARCHTERM add DESCRIPTION - import FILE + import|export|open FILE import_r DIRECTORY rm SEARCHTERM sync|status|commit|reset + shred help shell END @@ -356,6 +397,8 @@ class CLI geheim.ls(search_term: argv[1], show: true) when 'export' geheim.ls(search_term: argv[1], export: true) + when 'open' + geheim.ls(search_term: argv[1], open: true) when 'add' geheim.add(description: argv[1]) when 'import' @@ -380,6 +423,8 @@ class CLI git_reset when 'sync' git_sync + when 'shred' + geheim.shred_all_exported else geheim.ls(search_term: action) end |
