freydis 0.0.3 → 0.1.1
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 +32 -0
- data/LICENSE +10 -0
- data/README.md +40 -33
- data/bin/freydis +2 -5
- data/freydis.gemspec +45 -0
- data/lib/freydis/config.rb +44 -0
- data/lib/freydis/cryptsetup.rb +40 -45
- data/lib/freydis/disk.rb +22 -53
- data/lib/freydis/disk_luks.rb +18 -22
- data/lib/freydis/error.rb +6 -7
- data/lib/freydis/guard.rb +48 -26
- data/lib/freydis/options.rb +47 -36
- data/lib/freydis/rsync.rb +34 -40
- data/lib/freydis/secrets/archive.rb +73 -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 +10 -77
- data/lib/mods/exec.rb +29 -0
- data/lib/mods/msg.rb +16 -0
- data.tar.gz.sig +0 -0
- metadata +45 -38
- metadata.gz.sig +0 -0
- data/lib/freydis/.options.rb.swp +0 -0
- data/lib/freydis/data.rb +0 -43
- data/lib/freydis/init.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aca3e518674824172a35fc8e79f45d1ccb5d435376aa46ca53e1886096640c5d
|
4
|
+
data.tar.gz: ca393f18dabf26e8e8204014f1d04b1db74e467653c8c056ab7618410bfeb60d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d939115ae6697645af7f6e3adf044d25e6303a09c1791fa2d082924613f38791c072eb31252e3c85e42577984494669d29acd5714cde2084f28fe56f9a968ca5
|
7
|
+
data.tar.gz: d9c305c92139b2c47eb9f6ac3aa31b99de511df6d40fabac5dde40e8cc425331b302d1bca3d7fbf50d30fbec5878f8a1e31b4cfe2e5b6f8873c20a7dfbf279a5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
## 0.1.1, release 2022/10/8
|
2
|
+
* Restore archive with sudo if permission are insufficient.
|
3
|
+
|
4
|
+
## 0.1.0, release 2022/09/20
|
5
|
+
* New dependencies for `Freydis::Secrets`: `bsdtar`, `shred` and `gnupg`.
|
6
|
+
* Option store a new field `gpg_recipient`.
|
7
|
+
* Can store and resttore GPG keys and matching directory of the [pass](https://www.passwordstore.org/) utility.
|
8
|
+
* Use only `/dev/disk/by-id` in the config file, the value does not change from one system to another.
|
9
|
+
* Rewrite code.
|
10
|
+
|
11
|
+
## 0.0.3, release 2021/07/04
|
12
|
+
* Add an option to `rsync` -R | --relative.
|
13
|
+
* Simplify config file, use only disk: [sdX].
|
14
|
+
* New option `--path-add`, `--path-del`, `--path-list`, `--save`.
|
15
|
+
* Adding basic test with minitest.
|
16
|
+
* Customize errors message.
|
17
|
+
* Control args `-d | --disk DISK`
|
18
|
+
* Control device with `cryptsetup isLuks` before proceed
|
19
|
+
* Enhance logic code for `bin/freydis`
|
20
|
+
|
21
|
+
## 0.0.2, release 2021/05/18
|
22
|
+
* New options `--open` and `--close`.
|
23
|
+
* Encrypt/Decrypt with `cryptsetup`.
|
24
|
+
* Add Rsync for backup and restore.
|
25
|
+
* Can add/remove paths with the `--cli`.
|
26
|
+
* Can (u)mount the encrypted device at the default `/mnt/freydis`.
|
27
|
+
* Checking all ID (partuuid, uuid, id) from a given device.
|
28
|
+
* YAML config file in ~/.config/freydis/freydis.yaml.
|
29
|
+
|
30
|
+
## 0.0.1, release 2021/05/04
|
31
|
+
* Initial push, code freeying !
|
32
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 szorfein
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
|
+
|
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 with `rsync`, 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,12 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
config_file = "#{ENV['HOME']}/.config/freydis/freydis.yaml"
|
3
|
+
require 'freydis'
|
6
4
|
|
7
5
|
freydis = Freydis::Main.new(
|
8
|
-
:
|
9
|
-
:config => config_file
|
6
|
+
:argv => ARGV
|
10
7
|
)
|
11
8
|
|
12
9
|
freydis.start
|
data/freydis.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/lib/freydis/version"
|
4
|
+
|
5
|
+
# https://guides.rubygems.org/specification-reference/
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'freydis'
|
8
|
+
s.summary = 'Backup and Restore data from encrypted device.'
|
9
|
+
s.version = Freydis::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
|
12
|
+
s.description = <<~DESC
|
13
|
+
Freydis is a CLI tool to encrypt a disk device, backup and restore easyly. Freydis use `cryptsetup` and `rsync` mainly.
|
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
|
+
|
21
|
+
s.metadata = {
|
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',
|
26
|
+
}
|
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'
|
44
|
+
end
|
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,76 +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
|
-
if File.exists? f
|
21
|
-
exec "cryptsetup -v --type luks2 --verify-passphrase luksFormat #{f}"
|
22
|
-
break if $?.success?
|
23
|
-
end
|
24
|
-
}
|
20
|
+
info "Encrypting disk #{@disk}..."
|
21
|
+
x "cryptsetup -v --type luks2 --verify-passphrase luksFormat #{@disk}"
|
25
22
|
end
|
26
23
|
|
27
24
|
def open
|
28
|
-
|
29
|
-
@
|
30
|
-
if File.exist? f
|
31
|
-
exec "cryptsetup -v open #{f} #{@mapper_name}"
|
32
|
-
break if $?.success?
|
33
|
-
end
|
34
|
-
}
|
25
|
+
info "Opening disk #{@mapper_name}..."
|
26
|
+
x "cryptsetup -v open #{@disk} #{@mapper_name}"
|
35
27
|
end
|
36
28
|
|
37
29
|
def close
|
38
30
|
umount
|
39
|
-
|
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
|
40
36
|
end
|
41
37
|
|
42
38
|
def format
|
43
|
-
|
39
|
+
info "Formatting #{@mapper_name}..."
|
40
|
+
x "mkfs.ext4 /dev/mapper/#{@mapper_name}"
|
44
41
|
end
|
45
42
|
|
46
43
|
def mount
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
mkdir @mountpoint
|
45
|
+
info "Mounting disk at #{@mountpoint}"
|
46
|
+
x "mount -t ext4 /dev/mapper/#{@mapper_name} #{@mountpoint}"
|
50
47
|
end
|
51
48
|
|
52
|
-
|
49
|
+
protected
|
53
50
|
|
54
|
-
def
|
55
|
-
if
|
56
|
-
|
51
|
+
def umount
|
52
|
+
if mounted?
|
53
|
+
x "umount #{@mountpoint}"
|
54
|
+
success "Umounting disk #{@disk}..."
|
57
55
|
else
|
58
|
-
|
56
|
+
info "Disk #{@disk} is no mounted."
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
|
-
|
63
|
-
dir_length = Dir.glob("#{@mountpoint}/*").length
|
64
|
-
if dir_length >= 1 # should contain lost+found if mount
|
65
|
-
exec "umount #{@mountpoint}"
|
66
|
-
end
|
67
|
-
end
|
60
|
+
private
|
68
61
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
62
|
+
def mounted?
|
63
|
+
File.open('/proc/mounts') do |f|
|
64
|
+
f.each do |line|
|
65
|
+
return true if line.match?(/#{@mountpoint}/)
|
66
|
+
end
|
73
67
|
end
|
68
|
+
false
|
74
69
|
end
|
75
70
|
end
|
76
71
|
end
|
data/lib/freydis/disk.rb
CHANGED
@@ -1,69 +1,38 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Freydis
|
4
4
|
class Disk
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
5
|
+
def initialize(disk_path)
|
6
|
+
raise ArgumentError, "#{disk_path} no valid" unless disk_path.match?(/^\/dev\//)
|
7
|
+
|
8
|
+
@disk = disk_path
|
8
9
|
end
|
9
10
|
|
10
11
|
def size
|
11
|
-
`lsblk -dno SIZE #{@
|
12
|
+
`lsblk -dno SIZE #{@disk}`.chomp
|
12
13
|
end
|
13
14
|
|
14
15
|
def complete_info
|
15
|
-
`lsblk -dno "NAME,LABEL,FSTYPE,SIZE" #{@
|
16
|
-
end
|
17
|
-
|
18
|
-
def populate_data(data)
|
19
|
-
puts "Checking IDs on #{@disk}..."
|
20
|
-
data.options[:disk_uuid] = search_uuid
|
21
|
-
data.options[:disk_id] = search_id
|
22
|
-
data.options[:disk_partuuid] = search_partuuid
|
23
|
-
end
|
24
|
-
|
25
|
-
def encrypt(data)
|
26
|
-
search_id(data)
|
27
|
-
puts "id -> #{data.options[:disk_id]}"
|
28
|
-
data.save
|
29
|
-
|
30
|
-
cryptsetup = Freydis::Cryptsetup.new(data)
|
31
|
-
cryptsetup.close
|
32
|
-
|
33
|
-
cryptsetup.encrypt
|
34
|
-
cryptsetup.open
|
35
|
-
cryptsetup.format
|
36
|
-
|
37
|
-
populate_data(data)
|
38
|
-
puts "uuid -> #{data.options[:disk_uuid]}"
|
39
|
-
puts "partuuid -> #{data.options[:disk_partuuid]}"
|
40
|
-
data.save
|
41
|
-
|
42
|
-
cryptsetup.close
|
43
|
-
end
|
44
|
-
|
45
|
-
def search_partuuid
|
46
|
-
Dir.glob("/dev/disk/by-partuuid/*").each { |f|
|
47
|
-
if File.readlink(f).match(/#{@disk}/)
|
48
|
-
return f.delete_prefix("/dev/disk/by-partuuid/")
|
49
|
-
end
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
def search_uuid
|
54
|
-
Dir.glob("/dev/disk/by-uuid/*").each { |f|
|
55
|
-
if File.readlink(f).match(/#{@disk}/)
|
56
|
-
return f.delete_prefix("/dev/disk/by-uuid/")
|
57
|
-
end
|
58
|
-
}
|
16
|
+
`lsblk -dno "NAME,LABEL,FSTYPE,SIZE" #{@disk}`.chomp
|
59
17
|
end
|
60
18
|
|
61
19
|
def search_id
|
62
|
-
|
63
|
-
|
64
|
-
|
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}."
|
26
|
+
end
|
27
|
+
|
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('../../')
|
65
33
|
end
|
66
|
-
|
34
|
+
end
|
35
|
+
raise ArgumentError, "Unable to find the disk sdX of #{@disk}."
|
67
36
|
end
|
68
37
|
end
|
69
38
|
end
|
data/lib/freydis/disk_luks.rb
CHANGED
@@ -1,37 +1,33 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mods/msg'
|
2
4
|
|
3
5
|
module Freydis
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
puts "#{@disk} value is not supported yet"
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
else
|
20
|
-
puts "No disk."
|
21
|
-
exit 1
|
22
|
-
end
|
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."
|
23
17
|
end
|
24
18
|
|
25
19
|
def open
|
26
|
-
cryptsetup = Freydis::Cryptsetup.new
|
20
|
+
cryptsetup = Freydis::Cryptsetup.new
|
27
21
|
cryptsetup.close
|
28
22
|
cryptsetup.open
|
29
23
|
cryptsetup.mount
|
24
|
+
success "Disk #{CONFIG.disk} opened."
|
30
25
|
end
|
31
26
|
|
32
27
|
def close
|
33
|
-
cryptsetup = Freydis::Cryptsetup.new
|
28
|
+
cryptsetup = Freydis::Cryptsetup.new
|
34
29
|
cryptsetup.close
|
30
|
+
success "Disk #{CONFIG.disk} closed."
|
35
31
|
end
|
36
32
|
end
|
37
33
|
end
|
data/lib/freydis/error.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Freydis
|
4
|
-
class InvalidDisk < StandardError
|
5
|
-
end
|
6
|
-
class InvalidLuksDev < StandardError
|
7
|
-
end
|
8
|
-
class
|
9
|
-
end
|
4
|
+
class InvalidDisk < StandardError; end
|
5
|
+
class DiskId < StandardError; end
|
6
|
+
class InvalidLuksDev < StandardError; end
|
7
|
+
class InvalidPath < StandardError; end
|
8
|
+
class GPG < StandardError; end
|
10
9
|
end
|
data/lib/freydis/guard.rb
CHANGED
@@ -1,31 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
raise Freydis::InvalidDisk, "No disk /dev/#{name} available." unless File.exist? "/dev/#{name}"
|
7
|
-
name
|
8
|
-
rescue Freydis::InvalidDisk => e
|
9
|
-
puts "#{e.class} => #{e}"
|
10
|
-
exit 1
|
11
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Freydis
|
4
|
+
module Guard
|
5
|
+
module_function
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
raise Freydis::
|
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
|
19
24
|
end
|
20
|
-
rescue Freydis::InvalidLuksDev => e
|
21
|
-
puts "#{e.class} => #{e}"
|
22
|
-
exit 1
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
51
|
+
end
|
30
52
|
end
|
31
53
|
end
|