Class: Freydis::Cryptsetup

Inherits:
Object
  • Object
show all
Includes:
Exec, Msg
Defined in:
lib/freydis/cryptsetup.rb

Overview

Interact with cryptsetup from unix.

Instance Method Summary collapse

Methods included from Msg

#error, #info, #success

Methods included from Exec

#bsdtar, #mkdir, #shred, #x

Constructor Details

#initialize(disk) ⇒ Cryptsetup

Returns a new instance of Cryptsetup.



12
13
14
15
16
# File 'lib/freydis/cryptsetup.rb', line 12

def initialize(disk)
  @disk = Guard.disk(disk)
  @mapper_name = 'freydis-encrypt'
  @mountpoint = '/mnt/freydis'
end

Instance Method Details

#closeObject



28
29
30
31
32
33
34
# File 'lib/freydis/cryptsetup.rb', line 28

def close
  if File.exist? "/dev/mapper/#{@mapper_name}"
    x "cryptsetup -v close #{@mapper_name}"
  else
    info "#{@mapper_name} is not open."
  end
end

#encryptObject



18
19
20
21
# File 'lib/freydis/cryptsetup.rb', line 18

def encrypt
  info "Encrypting disk #{@disk}..."
  x "cryptsetup -v --type luks2 --verify-passphrase luksFormat #{@disk}"
end

#formatObject



36
37
38
39
# File 'lib/freydis/cryptsetup.rb', line 36

def format
  info "Formatting #{@mapper_name}..."
  x "mkfs.ext4 /dev/mapper/#{@mapper_name}"
end

#mountObject



41
42
43
44
45
# File 'lib/freydis/cryptsetup.rb', line 41

def mount
  mkdir @mountpoint
  info "Mounting disk at #{@mountpoint}"
  x "mount -t ext4 /dev/mapper/#{@mapper_name} #{@mountpoint}"
end

#openObject



23
24
25
26
# File 'lib/freydis/cryptsetup.rb', line 23

def open
  info "Opening disk #{@mapper_name}..."
  x "cryptsetup -v open #{@disk} #{@mapper_name}"
end

#umountObject



47
48
49
50
51
52
53
54
# File 'lib/freydis/cryptsetup.rb', line 47

def umount
  if mounted?
    x "umount #{@mountpoint}"
    success "Umounting disk #{@disk}..."
  else
    info "Disk #{@disk} is no mounted."
  end
end