Top Level Namespace

Defined Under Namespace

Modules: Bitferry

Constant Summary collapse

Endpoint =
%{
  The endpoint may be one of:
  * directory -- absolute or relative local directory (/data, ../source, c:\\data)
  * local:directory, :directory -- absolute local directory (:/data, local:c:\\data)
  * :tag:directory -- path relative to the intact volume matched by (partial) tag (:fa2c:source/data)

  The former case resolves specified directory againt an intact volume to make it volume-relative.
  It is an error if there is no intact volume that encompasses specified directory.
  The local: directory is left as is (not resolved against volumes).
  The :tag: directory is bound to the specified volume.
}
Encryption =
%{
  The encryption mode is controlled by --encrypt or --decrypt options.
  The mandatory password will be read from the standard input channel (pipe or keyboard).
}

Instance Method Summary collapse

Instance Method Details

#bitferry(&code) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/bitferry/cli.rb', line 62

def bitferry(&code)
  begin
    Bitferry.restore
    result = yield
    exit(Bitferry.commit && result ? 0 : 1)
  rescue => e
    Bitferry.log.fatal(e.message)
    exit(1)
  end
end

#create_rclone_task(task, *args, **opts) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/bitferry/cli.rb', line 53

def create_rclone_task(task, *args, **opts)
  task.new(*args,
    process: $process,
    encryption: $encryption&.new(obtain_password, process: $extended ? :extended : $profile),
    **opts
  )
end

#obtain_passwordObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/bitferry/cli.rb', line 74

def obtain_password
  if $stdin.tty?
    p1 = IO.console.getpass 'Enter password:'
    p2 = IO.console.getpass 'Repeat password:'
    raise 'passwords do not match' unless p1 == p2
    p1
  else
    $stdin.readline.strip!
  end
end

#setup_rclone_task(x) ⇒ Object



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
# File 'lib/bitferry/cli.rb', line 25

def setup_rclone_task(x)
  x.parameter 'SOURCE', 'Source endpoint specifier'
  x.parameter 'DESTINATION', 'Destination endpoint specifier'
  x.option '-e', :flag, 'Encrypt files in destination using default profile (alias for -E default)', attribute_name: :e do
    $encryption = Bitferry::Rclone::Encrypt
    $profile = :default
  end
  x.option '-d', :flag, 'Decrypt source files using default profile (alias for -D default)', attribute_name: :d do
    $encryption = Bitferry::Rclone::Decrypt
    $profile = :default
  end
  x.option '-x', :flag, 'Use extended encryption profile options (applies to -e, -d)', attribute_name: :x do
    $extended = true
  end
  x.option ['--process', '-X'], 'OPTIONS', 'Extra task processing profile/options' do |opts|
    $process = opts
  end
  x.option ['--encrypt', '-E'], 'OPTIONS', 'Encrypt files in destination using specified profile/options' do |opts|
    $encryption = Bitferry::Rclone::Encrypt
    $profile = opts
  end
  x.option ['--decrypt', '-D'], 'OPTIONS', 'Decrypt source files using specified profile/options' do |opts|
    $encryption = Bitferry::Rclone::Decrypt
    $profile = opts
  end
end