Sha256: 9ff72bb09253935f0ac4606d4a4ad23bb6a994aa831226ae5a23dd9c48036917

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# encoding: UTF-8
require 'fileutils'

class Boxafe::Encfs

  def initialize options = {}
    @options = options
  end

  def command
    [
      encfs_config,
      Shellwords.escape(@options[:encfs]),
      Shellwords.escape(absolute_root_dir),
      Shellwords.escape(absolute_mount_dir),
      extpass,
      '--',
      volname
    ].compact.join ' '
  end

  private

  def absolute_root_dir
    # TODO: remove Dir.pwd once fakefs is fixed (multiple occurrences in this file)
    File.expand_path @options[:root], Dir.pwd
  end

  def absolute_mount_dir
    File.expand_path @options[:mount], Dir.pwd
  end

  def volname
    %/-ovolname=#{Shellwords.escape @options[:volume]}/
  end

  def extpass
    if @options[:password_file]
      %|--extpass="head -n 1 #{Shellwords.escape File.expand_path(@options[:password_file], Dir.pwd)}"|
    elsif @options[:keychain]
      %*--extpass="security 2>&1 >/dev/null find-generic-password -gl '#{@options[:keychain]}' |grep password|cut -d \\\\\\" -f 2"*
    else
      nil
    end
  end

  def encfs_config
    @options[:encfs_config] ? %/ENCFS6_CONFIG=#{Shellwords.escape File.expand_path(@options[:encfs_config], Dir.pwd)}/ : nil
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
boxafe-0.1.9 lib/boxafe/encfs.rb
boxafe-0.1.7 lib/boxafe/encfs.rb
boxafe-0.1.6 lib/boxafe/encfs.rb