getch 0.5.0 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +15 -0
- data/README.md +2 -1
- data/getch.gemspec +6 -4
- data/lib/cryptsetup.rb +2 -0
- data/lib/dracut/encrypt.rb +7 -1
- data/lib/dracut/root.rb +4 -5
- data/lib/fstab/encrypt.rb +4 -3
- data/lib/fstab/minimal.rb +1 -1
- data/lib/fstab/root.rb +7 -6
- data/lib/getch/assembly.rb +13 -12
- data/lib/getch/config/grub.rb +7 -2
- data/lib/getch/config.rb +2 -1
- data/lib/getch/filesystem/ext4/encrypt/config.rb +1 -1
- data/lib/getch/filesystem/ext4/encrypt/void.rb +2 -2
- data/lib/getch/gentoo/bootloader.rb +12 -8
- data/lib/getch/gentoo/sources.rb +18 -24
- data/lib/getch/gentoo/terraform.rb +1 -0
- data/lib/getch/gentoo/use_flag.rb +2 -2
- data/lib/getch/gentoo.rb +1 -0
- data/lib/getch/guard.rb +13 -1
- data/lib/getch/helpers.rb +5 -0
- data/lib/getch/log.rb +9 -9
- data/lib/getch/tree.rb +8 -7
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void/terraform.rb +6 -2
- data/lib/getch/void/update.rb +1 -1
- data/lib/getch/void.rb +1 -0
- data/lib/luks.rb +26 -24
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8949c8a35b78615d49e8a79daadbd70052adc9e84291bdc2832ecf58bbb185d
|
4
|
+
data.tar.gz: e44e2466636fa47f72be581818f4648e19a7291ccdf435358b97241b1b12c77b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4fd298a8d04ddabaf2e1bc53f27af50131479190a7df542840f2557ea227677b42bf7b2bfee25185d305e54b71a934c5723f36e4b0631b50eecba186b1b5e90
|
7
|
+
data.tar.gz: 31b0a7f44918791c981b8f4af725d3be13565098dec21fd4948619e3edfa4c66f61fd93e4d646921d5df7be315e77c5ac0d4aeb3fb5ea1b26a9deab900520f32
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## 0.7.3, release 2024-10
|
2
|
+
Add a Workflow to build gem on Github
|
3
|
+
|
4
|
+
### Fix
|
5
|
+
- Voidlinux, remove 'base-container-full' instead of 'base-voidstrap'.
|
6
|
+
- Gentoo, use and configure 'sys-kernel/installkernel', sys-kernel/installkernel-systemd was removed from portage.
|
7
|
+
|
8
|
+
## 0.7.0, release 2023-12
|
9
|
+
* Add support for ssd disk `/dev/nvme*` #5
|
10
|
+
* System with systemd may need `systemd-machine-id-setup && systemctl restart systemd-networkd` after the first boot to make the dhcp works.
|
11
|
+
* Install of systemd/encrypt for Gentoo use GRUB instead of bootctl.
|
12
|
+
* Luks key if `--encrypt` are created earlier.
|
13
|
+
* Remove `noauto` and update arguments of fstab, this make futur system updates more easy.
|
14
|
+
* Correct lvm `OPTIONS[:lvm]`instead of the old `OPTIONS[:fs] == 'lvm'`.
|
15
|
+
|
1
16
|
## 0.5.0, release 2023-12
|
2
17
|
* Update Voidlinux url https://repo-default.voidlinux.org.
|
3
18
|
* Add global use="modules-sign" for Gentoo.
|
data/README.md
CHANGED
@@ -49,7 +49,8 @@ You can also use your current `linux` host, just pay attention to the disk that
|
|
49
49
|
## Dependencies
|
50
50
|
Getch is build without external libs, so it only require `ruby >= 2.5`.
|
51
51
|
|
52
|
-
On a live image of Void, you need to install `xbps-install -S ruby xz gptfdisk
|
52
|
+
On a live image of Void, you need to install `xbps-install -S ruby xz gptfdisk
|
53
|
+
openssl`.
|
53
54
|
|
54
55
|
## Install
|
55
56
|
Getch is cryptographically signed, so add my public key (if you haven’t already) as a trusted certificate.
|
data/getch.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/getch/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = 'getch'
|
@@ -15,7 +17,7 @@ Gem::Specification.new do |s|
|
|
15
17
|
'wiki_uri' => 'https://github.com/szorfein/getch'
|
16
18
|
}
|
17
19
|
s.license = 'MIT'
|
18
|
-
s.required_ruby_version = '>= 2.
|
20
|
+
s.required_ruby_version = '>= 2.6'
|
19
21
|
|
20
22
|
s.files = Dir.glob('{assets,lib}/**/*', File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
|
21
23
|
|
@@ -26,6 +28,6 @@ Gem::Specification.new do |s|
|
|
26
28
|
s.executables << 'getch'
|
27
29
|
s.require_paths = ['lib']
|
28
30
|
|
29
|
-
s.cert_chain = ['certs/szorfein.pem']
|
30
|
-
s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
31
|
+
#s.cert_chain = ['certs/szorfein.pem']
|
32
|
+
#s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem')
|
31
33
|
end
|
data/lib/cryptsetup.rb
CHANGED
data/lib/dracut/encrypt.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Dracut
|
4
|
+
# configure dracut for encypted system
|
4
5
|
class Encrypt < Root
|
5
6
|
def initialize(devs, options)
|
6
7
|
@luks = options[:luks_name]
|
@@ -26,6 +27,11 @@ module Dracut
|
|
26
27
|
echo file, 'install_items+=" /boot/boot.key /boot/root.key /etc/crypttab "'
|
27
28
|
end
|
28
29
|
|
30
|
+
def others
|
31
|
+
file = "#{@mountpoint}/etc/dracut.conf.d/mods.conf"
|
32
|
+
echo file, 'add_dracutmodules+=" crypt "'
|
33
|
+
end
|
34
|
+
|
29
35
|
private
|
30
36
|
|
31
37
|
def get_dm_uuid(name)
|
data/lib/dracut/root.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'nito'
|
4
4
|
require_relative '../getch/log'
|
5
5
|
|
6
6
|
module Dracut
|
7
|
+
# base for other dracut child
|
7
8
|
class Root
|
8
9
|
include NiTo
|
9
10
|
|
@@ -37,10 +38,8 @@ module Dracut
|
|
37
38
|
echo file, "kernel_cmdline=\"#{line}\""
|
38
39
|
end
|
39
40
|
|
40
|
-
def get_line
|
41
|
-
end
|
41
|
+
def get_line; end
|
42
42
|
|
43
|
-
def others
|
44
|
-
end
|
43
|
+
def others; end
|
45
44
|
end
|
46
45
|
end
|
data/lib/fstab/encrypt.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Fstab
|
4
|
+
# configure fstab for encrypt
|
4
5
|
class Encrypt < Root
|
5
6
|
def initialize(devs, options)
|
6
7
|
super
|
@@ -12,7 +13,7 @@ module Fstab
|
|
12
13
|
|
13
14
|
dm = Getch::Helpers.get_dm "boot-#{@luks}"
|
14
15
|
uuid = gen_uuid dm
|
15
|
-
line = "UUID=#{uuid} /boot #{@fs}
|
16
|
+
line = "UUID=#{uuid} /boot #{@fs} defaults,nosuid,noexec,nodev 0 2"
|
16
17
|
echo_a @conf, line
|
17
18
|
end
|
18
19
|
|
@@ -28,7 +29,7 @@ module Fstab
|
|
28
29
|
|
29
30
|
dm = Getch::Helpers.get_dm "root-#{@luks}"
|
30
31
|
uuid = gen_uuid dm
|
31
|
-
line = "UUID=#{uuid} / #{@fs}
|
32
|
+
line = "UUID=#{uuid} / #{@fs} defaults 1 1"
|
32
33
|
echo_a @conf, line
|
33
34
|
end
|
34
35
|
|
@@ -37,7 +38,7 @@ module Fstab
|
|
37
38
|
|
38
39
|
dm = Getch::Helpers.get_dm "home-#{@luks}"
|
39
40
|
uuid = gen_uuid dm
|
40
|
-
line = "UUID=#{uuid} /home #{@fs}
|
41
|
+
line = "UUID=#{uuid} /home #{@fs} defaults,nosuid,nodev 0 2"
|
41
42
|
echo_a @conf, line
|
42
43
|
end
|
43
44
|
end
|
data/lib/fstab/minimal.rb
CHANGED
data/lib/fstab/root.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'nito'
|
4
4
|
require_relative '../getch/log'
|
5
5
|
|
6
6
|
module Fstab
|
7
|
+
# Generating /etc/fstab
|
7
8
|
class Root
|
8
9
|
include NiTo
|
9
10
|
|
@@ -36,7 +37,7 @@ module Fstab
|
|
36
37
|
@efi || return
|
37
38
|
|
38
39
|
uuid = gen_uuid @efi
|
39
|
-
line = "UUID=#{uuid} /efi vfat
|
40
|
+
line = "UUID=#{uuid} /efi vfat defaults,nosuid,nodev 0 0"
|
40
41
|
echo_a @conf, line
|
41
42
|
end
|
42
43
|
|
@@ -44,7 +45,7 @@ module Fstab
|
|
44
45
|
@boot || return
|
45
46
|
|
46
47
|
uuid = gen_uuid @boot
|
47
|
-
line = "UUID=#{uuid} /boot #{@fs}
|
48
|
+
line = "UUID=#{uuid} /boot #{@fs} defaults,nosuid,noexec,nodev 0 2"
|
48
49
|
echo_a @conf, line
|
49
50
|
end
|
50
51
|
|
@@ -60,7 +61,7 @@ module Fstab
|
|
60
61
|
@root || return
|
61
62
|
|
62
63
|
uuid = gen_uuid @root
|
63
|
-
line = "UUID=#{uuid} / #{@fs}
|
64
|
+
line = "UUID=#{uuid} / #{@fs} defaults 1 1"
|
64
65
|
echo_a @conf, line
|
65
66
|
end
|
66
67
|
|
@@ -68,14 +69,14 @@ module Fstab
|
|
68
69
|
@home || return
|
69
70
|
|
70
71
|
uuid = gen_uuid @home
|
71
|
-
line = "UUID=#{uuid} /home #{@fs}
|
72
|
+
line = "UUID=#{uuid} /home #{@fs} defaults,nosuid,nodev 0 2"
|
72
73
|
echo_a @conf, line
|
73
74
|
end
|
74
75
|
|
75
76
|
def write_tmp
|
76
77
|
Getch::Helpers.systemd? && return
|
77
78
|
|
78
|
-
line = 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0'
|
79
|
+
line = 'tmpfs /tmp tmpfs defaults,nosuid,noexec,nodev 0 0'
|
79
80
|
echo_a @conf, line
|
80
81
|
end
|
81
82
|
|
data/lib/getch/assembly.rb
CHANGED
@@ -5,6 +5,7 @@ require 'nito'
|
|
5
5
|
require 'cryptsetup'
|
6
6
|
|
7
7
|
module Getch
|
8
|
+
# define steps/order for getch
|
8
9
|
class Assembly
|
9
10
|
include NiTo
|
10
11
|
|
@@ -91,13 +92,24 @@ module Getch
|
|
91
92
|
@state.post_config
|
92
93
|
end
|
93
94
|
|
95
|
+
# Luks_keys
|
96
|
+
# Install external keys to avoid enter password multiple times
|
97
|
+
def luks_keys
|
98
|
+
return unless OPTIONS[:encrypt] && OPTIONS[:fs] != 'zfs'
|
99
|
+
|
100
|
+
return if STATES[:luks_keys]
|
101
|
+
|
102
|
+
CryptSetup.new(DEVS, OPTIONS).keys
|
103
|
+
@state.luks_keys
|
104
|
+
end
|
105
|
+
|
94
106
|
# terraform
|
95
107
|
# Install all the required packages
|
96
108
|
# Also add services
|
97
109
|
def terraform
|
98
110
|
return if STATES[:terraform]
|
99
111
|
|
100
|
-
|
112
|
+
# @fs::PreDeps.new
|
101
113
|
@os::Terraform.new
|
102
114
|
@fs::Deps.new
|
103
115
|
@state.terraform
|
@@ -110,17 +122,6 @@ module Getch
|
|
110
122
|
@state.services
|
111
123
|
end
|
112
124
|
|
113
|
-
# Luks_keys
|
114
|
-
# Install external keys to avoid enter password multiple times
|
115
|
-
def luks_keys
|
116
|
-
return if not OPTIONS[:encrypt] or OPTIONS[:fs] == 'zfs'
|
117
|
-
|
118
|
-
return if STATES[:luks_keys]
|
119
|
-
|
120
|
-
CryptSetup.new(DEVS, OPTIONS).keys
|
121
|
-
@state.luks_keys
|
122
|
-
end
|
123
|
-
|
124
125
|
# bootloader
|
125
126
|
# Install and configure Grub2 or Systemd-boot with Dracut
|
126
127
|
# Adding keys for Luks
|
data/lib/getch/config/grub.rb
CHANGED
@@ -4,7 +4,10 @@ require 'nito'
|
|
4
4
|
|
5
5
|
module Getch
|
6
6
|
module Config
|
7
|
+
# install grub
|
7
8
|
class Grub
|
9
|
+
include NiTo
|
10
|
+
|
8
11
|
def initialize
|
9
12
|
@log = Log.new
|
10
13
|
@disk = OPTIONS[:boot_disk] ||= OPTIONS[:disk]
|
@@ -14,10 +17,12 @@ module Getch
|
|
14
17
|
x
|
15
18
|
end
|
16
19
|
|
20
|
+
protected
|
21
|
+
|
17
22
|
def x
|
18
23
|
@log.info "Installing Grub on #{@disk}...\n"
|
19
24
|
Helpers.efi? ? grub_efi : grub_bios
|
20
|
-
end
|
25
|
+
end
|
21
26
|
|
22
27
|
private
|
23
28
|
|
@@ -35,7 +40,7 @@ module Getch
|
|
35
40
|
# In case where efivars is not mounted
|
36
41
|
# avoid error with grub
|
37
42
|
def mount_efivars
|
38
|
-
|
43
|
+
mount '-t efivarfs', 'efivarfs', '/sys/firmware/efi/efivars'
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
data/lib/getch/config.rb
CHANGED
@@ -21,7 +21,7 @@ module Getch
|
|
21
21
|
puts " => Creating a key for #{dev}, password required:"
|
22
22
|
chroot "cryptsetup luksAddKey #{dev} /boot/#{name}"
|
23
23
|
command "chmod 000 /boot/#{name}"
|
24
|
-
#command "chmod -R g-rwx,o-rwx /boot"
|
24
|
+
# command "chmod -R g-rwx,o-rwx /boot"
|
25
25
|
end
|
26
26
|
|
27
27
|
def crypttab
|
@@ -52,7 +52,7 @@ module Getch
|
|
52
52
|
conf = "#{MOUNTPOINT}/etc/crypttab"
|
53
53
|
device = s_uuid(dev)
|
54
54
|
raise "No partuuid for #{dev} #{device}" unless device
|
55
|
-
raise "Bad partuuid for #{dev} #{device}" if device.
|
55
|
+
raise "Bad partuuid for #{dev} #{device}" if device.is_a?(Array)
|
56
56
|
|
57
57
|
add_line(conf, "#{mapname} PARTUUID=#{device} #{point} #{rest}")
|
58
58
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Getch
|
4
4
|
module Gentoo
|
5
|
+
# install grub or bootctl
|
5
6
|
class Bootloader
|
6
7
|
def initialize
|
7
8
|
@esp = '/efi'
|
@@ -11,8 +12,7 @@ module Getch
|
|
11
12
|
|
12
13
|
# Dracut is used by sys-kernel/gentoo-kernel
|
13
14
|
def dependencies
|
14
|
-
|
15
|
-
if Helpers.systemd? and Helpers.efi?
|
15
|
+
if Helpers.systemd_minimal?
|
16
16
|
Log.new.info "Systemd-boot alrealy installed...\n"
|
17
17
|
else
|
18
18
|
ChrootOutput.new('emerge --update --newuse sys-boot/grub')
|
@@ -20,18 +20,22 @@ module Getch
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def install
|
23
|
-
Helpers.grub?
|
24
|
-
Config::Grub.new
|
23
|
+
if Helpers.grub?
|
24
|
+
Config::Grub.new
|
25
|
+
else
|
25
26
|
bootctl
|
27
|
+
end
|
26
28
|
|
27
|
-
#ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel')
|
28
|
-
ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel-bin')
|
29
|
+
# ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel')
|
30
|
+
ChrootOutput.new('emerge --config sys-kernel/gentoo-kernel-bin') # should also reload grub-mkconfig
|
29
31
|
end
|
30
32
|
|
31
33
|
def bootctl
|
32
|
-
@boot
|
33
|
-
with_boot
|
34
|
+
if @boot
|
35
|
+
with_boot
|
36
|
+
else
|
34
37
|
Chroot.new("bootctl --esp-path=#{@esp} install")
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
# We need to umount the encrypted /boot first
|
data/lib/getch/gentoo/sources.rb
CHANGED
@@ -22,6 +22,7 @@ module Getch
|
|
22
22
|
bask
|
23
23
|
gen_cmdline
|
24
24
|
grub_mkconfig
|
25
|
+
systemd_mkconfig
|
25
26
|
use_flags
|
26
27
|
make
|
27
28
|
end
|
@@ -43,14 +44,24 @@ module Getch
|
|
43
44
|
cmdline.main
|
44
45
|
end
|
45
46
|
|
47
|
+
# https://wiki.gentoo.org/wiki/Handbook:X86/Installation/Kernel#GRUB
|
46
48
|
def grub_mkconfig
|
47
|
-
return if Helpers.
|
49
|
+
return if Helpers.systemd_minimal?
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
# https://wiki.gentoo.org/wiki/Project:Distribution_Kernel
|
52
|
+
use = Getch::Gentoo::Use.new('sys-kernel/installkernel')
|
53
|
+
|
54
|
+
use.add(%w[grub dracut])
|
55
|
+
end
|
56
|
+
|
57
|
+
# https://wiki.gentoo.org/wiki/Handbook:X86/Installation/Kernel#systemd-boot
|
58
|
+
def systemd_mkconfig
|
59
|
+
return unless Helpers.systemd_minimal?
|
60
|
+
|
61
|
+
use = Getch::Gentoo::Use.new('sys-apps/systemd')
|
62
|
+
use.add('boot')
|
63
|
+
other_use = Getch::Gentoo::Use.new('sys-kernel/installkernel')
|
64
|
+
other_use.add(%w[systemd-boot dracut])
|
54
65
|
end
|
55
66
|
|
56
67
|
def use_flags
|
@@ -60,11 +71,7 @@ module Getch
|
|
60
71
|
|
61
72
|
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel#Alternative:_Using_distribution_kernels
|
62
73
|
def make
|
63
|
-
|
64
|
-
Install.new('sys-kernel/installkernel-systemd')
|
65
|
-
else
|
66
|
-
Install.new('sys-kernel/installkernel-gentoo')
|
67
|
-
end
|
74
|
+
Install.new('sys-kernel/installkernel')
|
68
75
|
|
69
76
|
# Install.new 'sys-kernel/gentoo-kernel'
|
70
77
|
Install.new 'sys-kernel/gentoo-kernel-bin'
|
@@ -109,19 +116,6 @@ module Getch
|
|
109
116
|
|
110
117
|
File.write(file, "#{name}\n", mode: 'a')
|
111
118
|
end
|
112
|
-
|
113
|
-
def grub_script
|
114
|
-
<<~SHELL
|
115
|
-
#!/usr/bin/env sh
|
116
|
-
set -o errexit
|
117
|
-
|
118
|
-
if ! hash grub-mkconfig ; then
|
119
|
-
exit 0
|
120
|
-
fi
|
121
|
-
|
122
|
-
grub-mkconfig -o /boot/grub/grub.cfg
|
123
|
-
SHELL
|
124
|
-
end
|
125
119
|
end
|
126
120
|
end
|
127
121
|
end
|
@@ -60,7 +60,7 @@ module Getch
|
|
60
60
|
use = Getch::Gentoo::Use.new('sys-boot/grub')
|
61
61
|
flags << '-grub_platforms_efi-64' unless Helpers.efi?
|
62
62
|
flags << 'libzfs' if OPTIONS[:fs] == 'zfs'
|
63
|
-
flags << 'device-mapper' if OPTIONS[:
|
63
|
+
flags << 'device-mapper' if OPTIONS[:lvm] || OPTIONS[:encrypt]
|
64
64
|
use.add(flags)
|
65
65
|
end
|
66
66
|
|
@@ -74,7 +74,7 @@ module Getch
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def lvm
|
77
|
-
return unless Getch::OPTIONS[:
|
77
|
+
return unless Getch::OPTIONS[:lvm]
|
78
78
|
|
79
79
|
use = Getch::Gentoo::Use.new
|
80
80
|
use.add_global('lvm', 'device-mapper')
|
data/lib/getch/gentoo.rb
CHANGED
data/lib/getch/guard.rb
CHANGED
@@ -12,11 +12,23 @@ end
|
|
12
12
|
class InvalidKeymap < StandardError
|
13
13
|
end
|
14
14
|
|
15
|
+
def valid_disk(name)
|
16
|
+
case name
|
17
|
+
when /^sd|^hd|^vd/
|
18
|
+
true
|
19
|
+
when /^nvm/
|
20
|
+
true
|
21
|
+
else
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
module Getch
|
27
|
+
# various guard
|
16
28
|
module Guard
|
17
29
|
def self.disk(name)
|
18
30
|
raise InvalidDisk, 'No disk.' unless name
|
19
|
-
raise InvalidDisk, "Bad device name #{name}." unless name
|
31
|
+
raise InvalidDisk, "Bad device name #{name}." unless valid_disk(name)
|
20
32
|
raise InvalidDisk, "Disk /dev/#{name} no found." unless File.exist? "/dev/#{name}"
|
21
33
|
|
22
34
|
name
|
data/lib/getch/helpers.rb
CHANGED
@@ -28,6 +28,11 @@ module Getch
|
|
28
28
|
File.exist? "#{OPTIONS[:mountpoint]}/etc/default/grub"
|
29
29
|
end
|
30
30
|
|
31
|
+
# if systemd without encryption
|
32
|
+
def self.systemd_minimal?
|
33
|
+
systemd? && efi? && !OPTIONS[:encrypt]
|
34
|
+
end
|
35
|
+
|
31
36
|
def self.get_file_online(url, dest)
|
32
37
|
URI.open(url) do |l|
|
33
38
|
File.open(dest, 'wb') { |f| f.write(l.read) }
|
data/lib/getch/log.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
5
|
module Getch
|
6
|
+
# Display message to stdout and write in a log file.
|
6
7
|
class Log
|
7
|
-
|
8
8
|
WHITE = "\033[37m"
|
9
9
|
CYAN = "\033[36m"
|
10
10
|
MAGENTA = "\033[35m"
|
@@ -16,13 +16,13 @@ module Getch
|
|
16
16
|
BOLD = "\033[1m"
|
17
17
|
CLEAR = "\033[0m"
|
18
18
|
|
19
|
-
def initialize(verbose
|
19
|
+
def initialize(verbose: false)
|
20
20
|
@log_file = '/tmp/log_install.txt'
|
21
21
|
@verbose = verbose
|
22
22
|
init
|
23
23
|
end
|
24
24
|
|
25
|
-
# TODO remove length
|
25
|
+
# TODO, remove length
|
26
26
|
def info(msg)
|
27
27
|
tab = msg.match("\n") ? '' : add_tab(msg)
|
28
28
|
l = msg.length
|
@@ -62,32 +62,32 @@ module Getch
|
|
62
62
|
|
63
63
|
def init_res
|
64
64
|
@result = Logger.new $stdout, level: 'INFO'
|
65
|
-
@result.formatter = proc do |
|
65
|
+
@result.formatter = proc do |_, _, _, msg| msg end
|
66
66
|
end
|
67
67
|
|
68
68
|
def init_debug
|
69
69
|
@debug = Logger.new $stdout
|
70
|
-
@debug.formatter = proc do |
|
70
|
+
@debug.formatter = proc do |severity, _, _, msg|
|
71
71
|
"\n#{BLUE}#{BOLD}#{severity[0]}#{CLEAR} [#{Process.pid}]#{CLEAR}#{msg}"
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
def init_error
|
76
76
|
@error = Logger.new $stdout
|
77
|
-
@error.formatter = proc do |
|
77
|
+
@error.formatter = proc do |severity, _, _, msg|
|
78
78
|
"#{RED}#{BOLD}#{severity[0]}#{CLEAR}#{msg}\t"
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
def init_fatal
|
83
83
|
@fatal = Logger.new $stdout
|
84
|
-
@fatal.formatter = proc do |
|
84
|
+
@fatal.formatter = proc do |severity, _, _, msg|
|
85
85
|
"\n#{YELLOW}#{BOLD}#{severity[0]}#{CLEAR}#{msg}"
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
def init_save
|
90
|
-
File.exist?
|
90
|
+
File.exist?(@log_file) || puts("Creating log at #{@log_file}")
|
91
91
|
@save = Logger.new(@log_file, 1)
|
92
92
|
@save.level = Logger::DEBUG
|
93
93
|
@save.formatter = proc { |severity, datetime, _, msg|
|
@@ -108,7 +108,7 @@ module Getch
|
|
108
108
|
|
109
109
|
def add_tab(text)
|
110
110
|
case text.length
|
111
|
-
when 39..
|
111
|
+
when 39..46 then "\t\t"
|
112
112
|
when 31..38 then "\t\t\t"
|
113
113
|
when 23..30 then "\t\t\t\t"
|
114
114
|
when 16..22 then "\t\t\t\t\t"
|
data/lib/getch/tree.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Getch
|
4
4
|
module Tree
|
5
|
+
# call class depend of the os choosen
|
5
6
|
class Os
|
6
|
-
|
7
7
|
OS_TREE = {
|
8
8
|
gentoo: Gentoo,
|
9
9
|
void: Void
|
@@ -18,26 +18,27 @@ module Getch
|
|
18
18
|
OS_TREE[@os.to_sym] || @log.fatal('OS no found')
|
19
19
|
end
|
20
20
|
end
|
21
|
-
class FS
|
22
21
|
|
22
|
+
# call class depend on filesystem choosen.
|
23
|
+
class FS
|
23
24
|
FS_TREE = {
|
24
25
|
true => { # + encrypt
|
25
26
|
true => { # + lvm
|
26
|
-
ext4: FileSystem::Ext4::Hybrid
|
27
|
+
ext4: FileSystem::Ext4::Hybrid
|
27
28
|
},
|
28
29
|
false => { # - lvm
|
29
30
|
ext4: FileSystem::Ext4::Encrypt,
|
30
31
|
zfs: FileSystem::Zfs::Encrypt
|
31
|
-
}
|
32
|
+
}
|
32
33
|
},
|
33
34
|
false => { # - encrypt
|
34
35
|
true => { # + lvm
|
35
|
-
ext4: FileSystem::Ext4::Lvm
|
36
|
+
ext4: FileSystem::Ext4::Lvm
|
36
37
|
},
|
37
38
|
false => { # - lvm
|
38
39
|
ext4: FileSystem::Ext4::Minimal,
|
39
|
-
zfs: FileSystem::Zfs::Minimal
|
40
|
-
}
|
40
|
+
zfs: FileSystem::Zfs::Minimal
|
41
|
+
}
|
41
42
|
}
|
42
43
|
}.freeze
|
43
44
|
|
data/lib/getch/version.rb
CHANGED
data/lib/getch/void/terraform.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Getch
|
2
4
|
module Void
|
5
|
+
# install dependencies packages
|
3
6
|
class Terraform
|
4
7
|
def initialize
|
8
|
+
@deps = 'sudo'
|
5
9
|
x
|
6
10
|
end
|
7
11
|
|
@@ -12,13 +16,13 @@ module Getch
|
|
12
16
|
end
|
13
17
|
|
14
18
|
def install_pkgs
|
15
|
-
@pkgs =
|
19
|
+
@pkgs = @deps.dup
|
16
20
|
@pkgs << ' vim'
|
17
21
|
@pkgs << ' iptables'
|
18
22
|
@pkgs << ' runit-iptables'
|
19
23
|
@pkgs << ' iwd'
|
20
24
|
@pkgs << ' dhcpcd'
|
21
|
-
@pkgs << ' lvm2' if OPTIONS[:
|
25
|
+
@pkgs << ' lvm2' if OPTIONS[:lvm]
|
22
26
|
@pkgs << ' zfs' if OPTIONS[:fs] == 'zfs'
|
23
27
|
@pkgs << ' cryptsetup' if OPTIONS[:encrypt]
|
24
28
|
Install.new(@pkgs)
|
data/lib/getch/void/update.rb
CHANGED
@@ -26,7 +26,7 @@ module Getch
|
|
26
26
|
def update
|
27
27
|
ChrootOutput.new '/usr/bin/xbps-install -uy'
|
28
28
|
ChrootOutput.new '/usr/bin/xbps-install', '-Sy', 'base-system'
|
29
|
-
ChrootOutput.new '/usr/bin/xbps-remove -y base-
|
29
|
+
ChrootOutput.new '/usr/bin/xbps-remove -y base-container-full'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/getch/void.rb
CHANGED
data/lib/luks.rb
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
require 'nito'
|
4
4
|
require 'getch/log'
|
5
5
|
require 'getch/command'
|
6
|
+
require 'English'
|
6
7
|
|
7
8
|
module Luks
|
9
|
+
# define luks name, path, etc...
|
8
10
|
class Main
|
9
11
|
include Luks
|
10
12
|
include NiTo
|
@@ -21,7 +23,7 @@ module Luks
|
|
21
23
|
@mount = nil
|
22
24
|
@bootloader = false
|
23
25
|
@log = Getch::Log.new
|
24
|
-
@bs =
|
26
|
+
@bs = sector_size
|
25
27
|
end
|
26
28
|
|
27
29
|
def encrypt
|
@@ -32,9 +34,11 @@ module Luks
|
|
32
34
|
|
33
35
|
def encrypt_with_key
|
34
36
|
make_key
|
35
|
-
args = @luks_type == 'luks2'
|
36
|
-
|
37
|
-
|
37
|
+
args = if @luks_type == 'luks2'
|
38
|
+
"#{@command_args} -q --sector-size #{@bs} -d #{@full_key_path}"
|
39
|
+
else
|
40
|
+
"#{@command_args} -q -d #{@full_key_path}"
|
41
|
+
end
|
38
42
|
@log.info "Encrypting #{@luks_name} with #{@full_key_path}...\n"
|
39
43
|
cmd_crypt 'cryptsetup', 'luksFormat', args, "/dev/#{@disk}"
|
40
44
|
end
|
@@ -44,9 +48,8 @@ module Luks
|
|
44
48
|
|
45
49
|
@log.info "Opening #{@luks_name} > #{@disk}...\n"
|
46
50
|
cmd_crypt 'cryptsetup', 'open', @command_args, "/dev/#{@disk}", @luks_name
|
47
|
-
|
48
|
-
|
49
|
-
end
|
51
|
+
|
52
|
+
raise "No dev /dev/mapper/#{@luks_name}, open it first..." unless File.exist? "/dev/mapper/#{@luks_name}"
|
50
53
|
end
|
51
54
|
|
52
55
|
def open_with_key(file = nil)
|
@@ -94,8 +97,7 @@ module Luks
|
|
94
97
|
cmd_crypt 'cryptsetup', 'close', @luks_name
|
95
98
|
end
|
96
99
|
|
97
|
-
def gen_datas
|
98
|
-
end
|
100
|
+
def gen_datas; end
|
99
101
|
|
100
102
|
protected
|
101
103
|
|
@@ -145,29 +147,28 @@ module Luks
|
|
145
147
|
end
|
146
148
|
|
147
149
|
def config_grub
|
148
|
-
return unless
|
150
|
+
# return unless Getch::Helpers.grub? && !Getch::Helpers.systemd_minimal?
|
151
|
+
return unless @bootloader && Getch::Helpers.grub?
|
149
152
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
@log.result_ok
|
155
|
-
end
|
153
|
+
@log.info ' * Writing to /etc/default/grub...'
|
154
|
+
line = 'GRUB_ENABLE_CRYPTODISK=y'
|
155
|
+
echo_a "#{@mountpoint}/etc/default/grub", line
|
156
|
+
@log.result_ok
|
156
157
|
end
|
157
158
|
|
158
159
|
def perm
|
159
160
|
@key_path = "#{@key_dir}/#{@key_name}"
|
160
161
|
@full_key_path = "#{@mountpoint}#{@key_path}"
|
161
162
|
@log.info "Enforcing permission on #{@full_key_path}..."
|
162
|
-
File.chmod
|
163
|
-
File.chmod
|
164
|
-
File.chown
|
163
|
+
File.chmod(0400, "#{@mountpoint}#{@key_dir}")
|
164
|
+
File.chmod(0000, @full_key_path)
|
165
|
+
File.chown(0, 0, @full_key_path)
|
165
166
|
@log.result_ok
|
166
167
|
end
|
167
168
|
|
168
169
|
private
|
169
170
|
|
170
|
-
def
|
171
|
+
def sector_size
|
171
172
|
@disk || @log.fatal("No disk for #{@luks_name}.")
|
172
173
|
|
173
174
|
sh 'blockdev', '--getpbsz', "/dev/#{@disk}"
|
@@ -175,16 +176,16 @@ module Luks
|
|
175
176
|
|
176
177
|
def cmd_crypt_raw(*args)
|
177
178
|
system args.join(' ')
|
178
|
-
return if
|
179
|
+
return if $CHILD_STATUS.success?
|
179
180
|
|
180
181
|
@log.dbg args.join(' ')
|
181
|
-
@log.dbg
|
182
|
+
@log.dbg $CHILD_STATUS.success
|
182
183
|
@log.fatal 'die'
|
183
184
|
end
|
184
185
|
|
185
186
|
def cmd_crypt(*args)
|
186
187
|
cmd_crypt_raw args
|
187
|
-
rescue => e
|
188
|
+
rescue StandardError => e
|
188
189
|
@log.fatal e
|
189
190
|
end
|
190
191
|
|
@@ -193,7 +194,7 @@ module Luks
|
|
193
194
|
end
|
194
195
|
end
|
195
196
|
|
196
|
-
# Boot can decrypt
|
197
|
+
# Boot can decrypt all other partitions.
|
197
198
|
class Boot < Main
|
198
199
|
def initialize(disk, options)
|
199
200
|
super
|
@@ -223,6 +224,7 @@ module Luks
|
|
223
224
|
end
|
224
225
|
end
|
225
226
|
|
227
|
+
# define home partition for luks
|
226
228
|
class Home < Main
|
227
229
|
def initialize(disk, options)
|
228
230
|
super
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: getch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- szorfein
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
urXgRIzALxd/xazPCnoLSXPzfJSI6Y77S1EBvhPd9RaSO8IyH9RhPDP9mnTvW2Kl
|
37
37
|
NAUnoL+txK5a
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2024-10-03 00:00:00.000000000 Z
|
40
40
|
dependencies: []
|
41
41
|
description:
|
42
42
|
email:
|
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
184
|
requirements:
|
185
185
|
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 2.
|
187
|
+
version: '2.6'
|
188
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
189
|
requirements:
|
190
190
|
- - ">="
|
metadata.gz.sig
CHANGED
Binary file
|