freydis 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +17 -0
- data/README.md +40 -33
- data/bin/freydis +6 -49
- data/freydis.gemspec +35 -23
- data/lib/freydis/config.rb +44 -0
- data/lib/freydis/cryptsetup.rb +40 -43
- data/lib/freydis/disk.rb +21 -64
- data/lib/freydis/disk_luks.rb +33 -0
- data/lib/freydis/error.rb +9 -0
- data/lib/freydis/guard.rb +48 -4
- data/lib/freydis/options.rb +57 -29
- data/lib/freydis/rsync.rb +34 -40
- data/lib/freydis/secrets/archive.rb +63 -0
- data/lib/freydis/secrets/gpg.rb +63 -0
- data/lib/freydis/secrets.rb +29 -0
- data/lib/freydis/version.rb +3 -1
- data/lib/freydis.rb +24 -3
- data/lib/mods/exec.rb +27 -0
- data/lib/mods/msg.rb +16 -0
- data.tar.gz.sig +0 -0
- metadata +47 -15
- metadata.gz.sig +0 -0
- data/Rakefile +0 -21
- data/lib/freydis/data.rb +0 -39
- data/lib/freydis/init.rb +0 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8963ba3af539bf5e5893778cf4e19164cca071b4aa33f42c7bfed8b184016604
|
4
|
+
data.tar.gz: 235dba3157fda782be2927b08094970065511aaa36f5b0898499cc1fd421f3fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ce910c91f09a88ca6e3fb9a47e5b64f5f76b0a5ac5d78c44baa79b81d29a60c2fe7566f631962792b7192a435ce537258469e5d3f84f1471816d10f0bad8902
|
7
|
+
data.tar.gz: 8098c0c471bb5f6dbb9a71f5553244a496bfe7d29cd37ad848b95b4fd312c48ffe4c7c5c5f305d551db1a45feec5dec935a615dd1fc0a946126de9ddbbe48248
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
## 0.1.0, release 2022/09/20
|
2
|
+
* New dependencies for `Freydis::Secrets`: `bsdtar`, `shred` and `gnupg`.
|
3
|
+
* Option store a new field `gpg_recipient`.
|
4
|
+
* Can store and resttore GPG keys and matching directory of the [pass](https://www.passwordstore.org/) utility.
|
5
|
+
* Use only `/dev/disk/by-id` in the config file, the value does not change from one system to another.
|
6
|
+
* Rewrite code.
|
7
|
+
|
8
|
+
## 0.0.3, release 2021/07/04
|
9
|
+
* Add an option to `rsync` -R | --relative.
|
10
|
+
* Simplify config file, use only disk: [sdX].
|
11
|
+
* New option `--path-add`, `--path-del`, `--path-list`, `--save`.
|
12
|
+
* Adding basic test with minitest.
|
13
|
+
* Customize errors message.
|
14
|
+
* Control args `-d | --disk DISK`
|
15
|
+
* Control device with `cryptsetup isLuks` before proceed
|
16
|
+
* Enhance logic code for `bin/freydis`
|
17
|
+
|
1
18
|
## 0.0.2, release 2021/05/18
|
2
19
|
* New options `--open` and `--close`.
|
3
20
|
* Encrypt/Decrypt with `cryptsetup`.
|
data/README.md
CHANGED
@@ -1,59 +1,66 @@
|
|
1
1
|
# Freydis
|
2
|
-
Backup and restore data on encrypted device.
|
3
2
|
|
4
|
-
|
5
|
-
Freydis use `rsync` and `cryptsetup`.
|
3
|
+
<div align="center">
|
6
4
|
|
7
|
-
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/freydis.svg)](https://badge.fury.io/rb/freydis)
|
6
|
+
![Gem](https://img.shields.io/gem/dtv/freydis?color=red)
|
7
|
+
![GitHub last commit (branch)](https://img.shields.io/github/last-commit/szorfein/freydis/develop?color=blue)
|
8
|
+
![GitHub](https://img.shields.io/github/license/szorfein/freydis?color=cyan)
|
8
9
|
|
9
|
-
|
10
|
+
</div>
|
11
|
+
|
12
|
+
Backup and restore data on encrypted device.
|
13
|
+
|
14
|
+
## Requirements
|
15
|
+
Freydis use `rsync` and `cryptsetup` and optionnal `bsdtar`, `shred`, `gnupg`.
|
10
16
|
|
11
17
|
## Install freydis locally
|
12
18
|
|
13
|
-
gem install
|
19
|
+
$ gem install --user-install freydis
|
14
20
|
|
15
21
|
## Usage
|
16
22
|
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
$ freydis -h
|
24
|
+
|
25
|
+
## Examples
|
20
26
|
|
21
|
-
|
27
|
+
#### 0x01 - Initialisation
|
28
|
+
First, you need a config file and a disk encrypted.
|
29
|
+
|
30
|
+
$ freydis --disk sdc --encrypt --save
|
31
|
+
|
32
|
+
The config file will be created at `~/.config/freydis/freydis.yaml`.
|
22
33
|
|
23
34
|
```yaml
|
24
35
|
---
|
25
|
-
:disk:
|
26
|
-
:
|
27
|
-
:disk_uuid: 10f531df-51dc-x19e-9bd1-bbd6659f0c3f
|
28
|
-
:disk_partuuid: ''
|
29
|
-
:paths:
|
30
|
-
- "/home/daggoth/labs"
|
31
|
-
- "/home/daggoth/musics"
|
32
|
-
- "/home/daggoth/.password-store"
|
33
|
-
- "/home/daggoth/documents"
|
36
|
+
:disk: /dev/disk/by-id/usb-SABRENT_SABRENT_DB9876543214E-0:0
|
37
|
+
:paths: []
|
34
38
|
```
|
35
39
|
|
36
|
-
|
37
|
-
+
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
+ paths -> Contain a list of absolute paths on each line.
|
40
|
+
+ disk: save the full path `by-id` for `sdc` here.
|
41
|
+
+ paths -> An Array which contain a list of absolute paths for backup.
|
42
|
+
|
43
|
+
#### 0x02 - First backup
|
44
|
+
Freydis will use `rsync`, all paths must be separated by a comma:
|
42
45
|
|
43
|
-
|
44
|
-
Freydis will use `cryptsetup` with `luks2` and format the disk with `ext4`:
|
46
|
+
$ freydis --backup --paths-add "/home,/etc" --save
|
45
47
|
|
46
|
-
|
48
|
+
#### 0x03 - Restore
|
49
|
+
With `--disk` and `--paths-add` saved in the config file, you only need to write:
|
47
50
|
|
48
|
-
|
49
|
-
Make an incremental backup, will copy all `paths` include in the config file:
|
51
|
+
$ freydis --restore
|
50
52
|
|
51
|
-
|
53
|
+
Freydis will restore all files in `/`.
|
52
54
|
|
53
|
-
|
55
|
+
#### 0x04 - Secrets
|
56
|
+
Freydis can store secrets ([GPG Key](https://www.gnupg.org/) and [pass](https://www.passwordstore.org/) directory for now) and restore them if need:
|
54
57
|
|
55
|
-
$ freydis --
|
58
|
+
$ freydis --gpg-recipient szorfein@protonmail.com --secrets-backup
|
59
|
+
$ freydis --gpg-recipient szorfein@protonmail.com --secrets-restore
|
60
|
+
|
61
|
+
The option `--secrets-restore` use `gpg --import` if the key is no found on your system.
|
56
62
|
|
63
|
+
### Tips
|
57
64
|
If you lost the config file, `freydis` has made a copy on your device when you're done your first `--backup`:
|
58
65
|
|
59
66
|
$ freydis --open --disk sdc
|
data/bin/freydis
CHANGED
@@ -1,53 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require "freydis"
|
3
2
|
|
4
|
-
|
3
|
+
require 'freydis'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
freydis = Freydis::Main.new(
|
6
|
+
:argv => ARGV
|
7
|
+
)
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
if cli.init
|
15
|
-
Freydis::Init.run(data.options)
|
16
|
-
data.save
|
17
|
-
exit 0
|
18
|
-
end
|
19
|
-
|
20
|
-
if !cli.backup && !cli.restore && !cli.encrypt &&
|
21
|
-
!cli.open && !cli.close
|
22
|
-
puts "Ok... glad to see you too."
|
23
|
-
exit 1
|
24
|
-
end
|
25
|
-
|
26
|
-
if cli.encrypt
|
27
|
-
puts "Encrypting disk #{data.options[:disk]}..."
|
28
|
-
disk = Freydis::Disk.new(data.options[:disk])
|
29
|
-
disk.encrypt(data)
|
30
|
-
data.save
|
31
|
-
elsif cli.backup
|
32
|
-
puts "Saving..."
|
33
|
-
disk = Freydis::Disk.new(data.options[:disk])
|
34
|
-
disk.open(data)
|
35
|
-
rsync = Freydis::Rsync.new(data)
|
36
|
-
rsync.backup
|
37
|
-
disk.close(data)
|
38
|
-
elsif cli.restore
|
39
|
-
puts "Restoring..."
|
40
|
-
disk = Freydis::Disk.new(data.options[:disk])
|
41
|
-
disk.open(data)
|
42
|
-
rsync = Freydis::Rsync.new(data)
|
43
|
-
rsync.restore
|
44
|
-
disk.close(data)
|
45
|
-
elsif cli.open
|
46
|
-
puts "Opening disk #{data.options[:disk]}."
|
47
|
-
disk = Freydis::Disk.new(data.options[:disk])
|
48
|
-
disk.open(data)
|
49
|
-
elsif cli.close
|
50
|
-
puts "Closing disk #{data.options[:disk]}."
|
51
|
-
disk = Freydis::Disk.new(data.options[:disk])
|
52
|
-
disk.close(data)
|
53
|
-
end
|
9
|
+
freydis.start
|
10
|
+
freydis.bye
|
data/freydis.gemspec
CHANGED
@@ -1,33 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.dirname(__FILE__) + "/lib/freydis/version"
|
2
4
|
|
3
5
|
# https://guides.rubygems.org/specification-reference/
|
4
6
|
Gem::Specification.new do |s|
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.name = "freydis"
|
8
|
-
s.summary = "Backup and Restore data from encrypted device."
|
7
|
+
s.name = 'freydis'
|
8
|
+
s.summary = 'Backup and Restore data from encrypted device.'
|
9
9
|
s.version = Freydis::VERSION
|
10
|
-
s.
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
|
12
|
+
s.description = <<~DESC
|
11
13
|
Freydis is a CLI tool to encrypt a disk device, backup and restore easyly. Freydis use `cryptsetup` and `rsync` mainly.
|
12
|
-
|
13
|
-
|
14
|
-
s.
|
15
|
-
s.
|
14
|
+
DESC
|
15
|
+
|
16
|
+
s.email = 'szorfein@protonmail.com'
|
17
|
+
s.homepage = 'https://github.com/szorfein/freydis'
|
18
|
+
s.license = 'MIT'
|
19
|
+
s.author = 'szorfein'
|
20
|
+
|
16
21
|
s.metadata = {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
"funding_uri" => "https://patreon.com/szorfein",
|
22
|
+
'bug_tracker_uri' => 'https://github.com/szorfein/freydis/issues',
|
23
|
+
'changelog_uri' => 'https://github.com/szorfein/freydis/blob/main/CHANGELOG.md',
|
24
|
+
'source_code_uri' => 'https://github.com/szorfein/freydis',
|
25
|
+
'funding_uri' => 'https://patreon.com/szorfein',
|
22
26
|
}
|
23
|
-
|
24
|
-
s.
|
25
|
-
|
26
|
-
|
27
|
-
s.
|
28
|
-
s.
|
29
|
-
|
30
|
-
s.
|
31
|
-
s.
|
27
|
+
|
28
|
+
s.files = Dir.glob('{lib,bin}/**/*', File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
|
29
|
+
|
30
|
+
# Include the CHANGELOG.md, LICENSE.md, README.md manually
|
31
|
+
s.files += %w[CHANGELOG.md LICENSE README.md]
|
32
|
+
s.files += %w[freydis.gemspec]
|
33
|
+
|
34
|
+
s.bindir = 'bin'
|
35
|
+
s.executables << 'freydis'
|
36
|
+
s.require_paths = ['lib']
|
37
|
+
|
38
|
+
s.cert_chain = ['certs/szorfein.pem']
|
39
|
+
s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
40
|
+
|
41
|
+
s.required_ruby_version = '>= 2.6'
|
42
|
+
s.requirements << 'cryptsetup'
|
43
|
+
s.requirements << 'rsync'
|
32
44
|
end
|
33
45
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'pathname'
|
6
|
+
require 'mods/msg'
|
7
|
+
|
8
|
+
module Freydis
|
9
|
+
class Config
|
10
|
+
include Msg
|
11
|
+
|
12
|
+
attr_accessor :gpg_recipient, :disk, :paths
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@cpath = "#{ENV['HOME']}/.config/freydis/freydis.yaml"
|
16
|
+
@disk = nil
|
17
|
+
@gpg_recipient = nil
|
18
|
+
@paths = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def load
|
22
|
+
if File.exist? @cpath
|
23
|
+
info 'Loading config...'
|
24
|
+
data_load = YAML.load_file @cpath
|
25
|
+
@disk = data_load[:disk]
|
26
|
+
@gpg_recipient = data_load[:gpg_recipient]
|
27
|
+
@paths = data_load[:paths]
|
28
|
+
else
|
29
|
+
info "Creating config file #{@cpath}..."
|
30
|
+
save
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def save
|
35
|
+
FileUtils.mkdir_p Pathname.new(@cpath).parent.to_s
|
36
|
+
File.write @cpath, YAML::dump({
|
37
|
+
disk: @disk,
|
38
|
+
gpg_recipient: @gpg_recipient,
|
39
|
+
paths: @paths.uniq
|
40
|
+
})
|
41
|
+
success "Saving options to #{@cpath}..."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/freydis/cryptsetup.rb
CHANGED
@@ -1,74 +1,71 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mods/exec'
|
4
|
+
require 'mods/msg'
|
2
5
|
|
3
6
|
module Freydis
|
4
7
|
class Cryptsetup
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
@mountpoint ="/mnt/freydis"
|
8
|
+
include Exec
|
9
|
+
include Msg
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
Guard.disk_id(CONFIG.disk)
|
13
|
+
|
14
|
+
@disk = Disk.new(CONFIG.disk).search_sdx
|
15
|
+
@mapper_name = 'freydis-encrypt'
|
16
|
+
@mountpoint = '/mnt/freydis'
|
15
17
|
end
|
16
18
|
|
17
19
|
def encrypt
|
18
|
-
|
19
|
-
|
20
|
-
exec "cryptsetup -v --type luks2 --verify-passphrase luksFormat #{f}"
|
21
|
-
break if $?.success?
|
22
|
-
end
|
23
|
-
}
|
20
|
+
info "Encrypting disk #{@disk}..."
|
21
|
+
x "cryptsetup -v --type luks2 --verify-passphrase luksFormat #{@disk}"
|
24
22
|
end
|
25
23
|
|
26
24
|
def open
|
27
|
-
|
28
|
-
|
29
|
-
exec "cryptsetup -v open #{f} #{@mapper_name}"
|
30
|
-
break if $?.success?
|
31
|
-
end
|
32
|
-
}
|
25
|
+
info "Opening disk #{@mapper_name}..."
|
26
|
+
x "cryptsetup -v open #{@disk} #{@mapper_name}"
|
33
27
|
end
|
34
28
|
|
35
29
|
def close
|
36
30
|
umount
|
37
|
-
|
31
|
+
if File.exist? "/dev/mapper/#{@mapper_name}"
|
32
|
+
x "cryptsetup -v close #{@mapper_name}"
|
33
|
+
else
|
34
|
+
info "#{@mapper_name} is not open."
|
35
|
+
end
|
38
36
|
end
|
39
37
|
|
40
38
|
def format
|
41
|
-
|
39
|
+
info "Formatting #{@mapper_name}..."
|
40
|
+
x "mkfs.ext4 /dev/mapper/#{@mapper_name}"
|
42
41
|
end
|
43
42
|
|
44
43
|
def mount
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
mkdir @mountpoint
|
45
|
+
info "Mounting disk at #{@mountpoint}"
|
46
|
+
x "mount -t ext4 /dev/mapper/#{@mapper_name} #{@mountpoint}"
|
48
47
|
end
|
49
48
|
|
50
|
-
|
49
|
+
protected
|
51
50
|
|
52
|
-
def
|
53
|
-
if
|
54
|
-
|
51
|
+
def umount
|
52
|
+
if mounted?
|
53
|
+
x "umount #{@mountpoint}"
|
54
|
+
success "Umounting disk #{@disk}..."
|
55
55
|
else
|
56
|
-
|
56
|
+
info "Disk #{@disk} is no mounted."
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
|
61
|
-
dir_length = Dir.glob("#{@mountpoint}/*").length
|
62
|
-
if dir_length >= 1 # should contain lost+found if mount
|
63
|
-
exec "umount #{@mountpoint}"
|
64
|
-
end
|
65
|
-
end
|
60
|
+
private
|
66
61
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
def mounted?
|
63
|
+
File.open('/proc/mounts') do |f|
|
64
|
+
f.each do |line|
|
65
|
+
return true if line.match?(/#{@mountpoint}/)
|
66
|
+
end
|
71
67
|
end
|
68
|
+
false
|
72
69
|
end
|
73
70
|
end
|
74
71
|
end
|
data/lib/freydis/disk.rb
CHANGED
@@ -1,81 +1,38 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Freydis
|
4
4
|
class Disk
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
8
|
-
@
|
5
|
+
def initialize(disk_path)
|
6
|
+
raise ArgumentError, "#{disk_path} no valid" unless disk_path.match?(/^\/dev\//)
|
7
|
+
|
8
|
+
@disk = disk_path
|
9
9
|
end
|
10
10
|
|
11
11
|
def size
|
12
|
-
`lsblk -dno SIZE #{@
|
12
|
+
`lsblk -dno SIZE #{@disk}`.chomp
|
13
13
|
end
|
14
14
|
|
15
15
|
def complete_info
|
16
|
-
`lsblk -dno "NAME,LABEL,FSTYPE,SIZE" #{@
|
17
|
-
end
|
18
|
-
|
19
|
-
def populate_data(data)
|
20
|
-
puts "Checking IDs on #{@disk}..."
|
21
|
-
search_uuid(data)
|
22
|
-
search_id(data)
|
23
|
-
search_partuuid(data)
|
16
|
+
`lsblk -dno "NAME,LABEL,FSTYPE,SIZE" #{@disk}`.chomp
|
24
17
|
end
|
25
18
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
cryptsetup = Freydis::Cryptsetup.new(data)
|
34
|
-
cryptsetup.close
|
35
|
-
|
36
|
-
cryptsetup.encrypt
|
37
|
-
cryptsetup.open
|
38
|
-
cryptsetup.format
|
39
|
-
|
40
|
-
cryptsetup.close
|
41
|
-
end
|
42
|
-
|
43
|
-
def open(data)
|
44
|
-
cryptsetup = Freydis::Cryptsetup.new(data)
|
45
|
-
cryptsetup.close
|
46
|
-
cryptsetup.open
|
47
|
-
cryptsetup.mount
|
48
|
-
end
|
49
|
-
|
50
|
-
def close(data)
|
51
|
-
cryptsetup = Freydis::Cryptsetup.new(data)
|
52
|
-
cryptsetup.close
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def search_uuid(data)
|
58
|
-
Dir.glob("/dev/disk/by-uuid/*").each { |f|
|
59
|
-
if File.readlink(f).match(/#{@disk}/)
|
60
|
-
data.options[:disk_uuid] = f.delete_prefix("/dev/disk/by-uuid/")
|
61
|
-
end
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
def search_id(data)
|
66
|
-
Dir.glob("/dev/disk/by-id/*").each { |f|
|
67
|
-
if File.readlink(f).match(/#{@disk}/)
|
68
|
-
data.options[:disk_id] = f.delete_prefix("/dev/disk/by-id/")
|
69
|
-
end
|
70
|
-
}
|
19
|
+
def search_id
|
20
|
+
dev_split = @disk.delete_prefix('/dev/')
|
21
|
+
Dir.glob("/dev/disk/by-id/*").each do |f|
|
22
|
+
return f if File.readlink(f).match?(/#{dev_split}/)
|
23
|
+
#return f.delete_prefix("/dev/disk/by-id/")
|
24
|
+
end
|
25
|
+
raise ArgumentError, "Unable to find the disk id of #{@disk}."
|
71
26
|
end
|
72
27
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
28
|
+
# return /dev/sdX from a disk_id if value match with @disk
|
29
|
+
def search_sdx
|
30
|
+
Dir.glob('/dev/disk/by-id/*').each do |f|
|
31
|
+
if f.match?(/#{@disk}$/) # need a space
|
32
|
+
return '/dev/' + File.readlink(f).delete_prefix('../../')
|
77
33
|
end
|
78
|
-
|
34
|
+
end
|
35
|
+
raise ArgumentError, "Unable to find the disk sdX of #{@disk}."
|
79
36
|
end
|
80
37
|
end
|
81
38
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mods/msg'
|
4
|
+
|
5
|
+
module Freydis
|
6
|
+
module DiskLuks
|
7
|
+
extend Msg
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def encrypt
|
11
|
+
cryptsetup = Freydis::Cryptsetup.new
|
12
|
+
cryptsetup.encrypt
|
13
|
+
cryptsetup.open
|
14
|
+
cryptsetup.format
|
15
|
+
cryptsetup.close
|
16
|
+
success "Disk #{CONFIG.disk} fully encrypted."
|
17
|
+
end
|
18
|
+
|
19
|
+
def open
|
20
|
+
cryptsetup = Freydis::Cryptsetup.new
|
21
|
+
cryptsetup.close
|
22
|
+
cryptsetup.open
|
23
|
+
cryptsetup.mount
|
24
|
+
success "Disk #{CONFIG.disk} opened."
|
25
|
+
end
|
26
|
+
|
27
|
+
def close
|
28
|
+
cryptsetup = Freydis::Cryptsetup.new
|
29
|
+
cryptsetup.close
|
30
|
+
success "Disk #{CONFIG.disk} closed."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/freydis/guard.rb
CHANGED
@@ -1,9 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Freydis
|
2
4
|
module Guard
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def disk(name)
|
8
|
+
full_path = "/dev/#{name}"
|
9
|
+
raise Freydis::InvalidDisk, 'No disk, use with -d DISK.' unless name
|
10
|
+
raise Freydis::InvalidDisk, 'No disk, use with -d DISK.' if name == ''
|
11
|
+
raise Freydis::InvalidDisk, 'Bad name #{name}, should match with sd[a-z]' unless name.match(/^sd[a-z]{1}$/)
|
12
|
+
raise Freydis::InvalidDisk, "No disk #{full_path} available." unless File.exist? full_path
|
13
|
+
Freydis::Disk.new(full_path).search_id # return disk(name) by-id
|
14
|
+
rescue Freydis::InvalidDisk => e
|
15
|
+
puts "#{e.class} => #{e}"
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
def disk_id(name)
|
20
|
+
raise DiskId, "No disk #{name} found." unless File.exist? name
|
21
|
+
rescue Freydis::DiskId => e
|
22
|
+
puts "#{e.class} => #{e}"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def isLuks(disk)
|
27
|
+
raise Freydis::InvalidLuksDev, "No disk." unless disk
|
28
|
+
raise Freydis::InvalidLuksDev, "#{disk} does not exist." unless File.exist? disk
|
29
|
+
sudo = Process.uid != 0 ? 'sudo' : ''
|
30
|
+
if !system(sudo, 'cryptsetup', 'isLuks', disk)
|
31
|
+
raise Freydis::InvalidLuksDev, "#{disk} is not valid Luks device."
|
32
|
+
end
|
33
|
+
rescue Freydis::InvalidLuksDev => e
|
34
|
+
puts "#{e.class} => #{e}"
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
|
38
|
+
def path?(p)
|
39
|
+
raise Freydis::InvalidPath, "#{p} does not exist." unless File.exist? p
|
40
|
+
rescue Freydis::InvalidPath => e
|
41
|
+
puts "#{e.class} => #{e}"
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
def gpg(recipient)
|
46
|
+
raise Freydis::GPG, "No recipient, use --gpg-recipient NAME" unless recipient
|
47
|
+
recipient
|
48
|
+
rescue Freydis::GPG => e
|
49
|
+
puts "#{e.class} => #{e}"
|
50
|
+
exit 1
|
7
51
|
end
|
8
52
|
end
|
9
53
|
end
|