Class: LEncApp

Inherits:
Object
  • Object
show all
Includes:
LEnc
Defined in:
lib/lenc/lencrypt.rb

Constant Summary

Constants included from LEnc

LEnc::KEY_LEN_MAX, LEnc::KEY_LEN_MIN

Instance Method Summary collapse

Instance Method Details

#run(argv = ARGV) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lenc/lencrypt.rb', line 6

def run(argv = ARGV) 
    
  req 'trollop'
  p = Trollop::Parser.new do
      opt :init, "create new encryption repository: ENCDIR ", :type => :string
      opt :key, "encryption key", :type => :string  
      opt :orignames, "(with --init) leave filenames unencrypted"
      opt :update, "update encrypted repository (default operation)"  
      opt :recover, "recover files from an encrypted repository: ENCDIR RECDIR", :type => :strings
      opt :where, "specify source directory (default = current directory)", :type => :string
      opt :verbose,"verbose operation"
      opt :quiet, "quiet operation"
      opt :dryrun, "show which files will be modified, but make no changes"
  end
  
  options = Trollop::with_standard_exception_handling p do
    p.parse argv
  end
  
  # Not sure how to determine if there were leftover arguments;
  # trollop seems to include path information ('.')
  #p.die("Unrecognized argument: #{p.leftovers[0]}",nil) if p.leftovers.size
  
  v = 0
  v = -1 if options[:quiet]
  v = 1  if options[:verbose]
  
  nOpt = 0
  nOpt += 1 if options[:init]
  nOpt += 1 if options[:update]
  nOpt += 1 if options[:recover]
          
  #pr("trollop opts = %s\n",d2(options))
    
  p.die("Only one operation can be performed at a time.",nil) if nOpt > 1

  r = Repo.new(:dryrun => options[:dryrun],
    :verbosity => v)
  
  begin

    if (a = options[:init])
      encDir = a  
      r.create(options[:where], options[:key], encDir, options[:orignames])
    elsif (a = options[:recover])
      p.die("Expecting: ENCDIR RECDIR",nil) if a.size != 2
      r.perform_recovery(options[:key],a[0],a[1])
    else
      r.open(options[:where],options[:key])
      r.perform_encrypt()
    end

    r.close()
  rescue Exception =>e
    puts("\nProblem encountered: #{e.message}")
    puts e.backtrace
  end

end