getch 0.1.9 → 0.3.0
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/README.md +35 -29
- data/bin/getch +8 -6
- data/lib/clean.rb +149 -0
- data/lib/cryptsetup.rb +132 -0
- data/lib/devs.rb +199 -0
- data/lib/dracut/encrypt.rb +36 -0
- data/lib/dracut/hybrid.rb +15 -0
- data/lib/dracut/lvm.rb +14 -0
- data/lib/dracut/minimal.rb +11 -0
- data/lib/dracut/root.rb +45 -0
- data/lib/dracut/zfs.rb +35 -0
- data/lib/dracut.rb +11 -0
- data/lib/fstab/encrypt.rb +44 -0
- data/lib/fstab/hybrid.rb +34 -0
- data/lib/fstab/lvm.rb +25 -0
- data/lib/fstab/minimal.rb +6 -0
- data/lib/fstab/root.rb +93 -0
- data/lib/fstab/zfs.rb +23 -0
- data/lib/fstab.rb +11 -0
- data/lib/getch/assembly.rb +150 -0
- data/lib/getch/command.rb +88 -128
- data/lib/getch/config/account.rb +39 -0
- data/lib/getch/config/dhcp.rb +104 -0
- data/lib/getch/config/grub.rb +42 -0
- data/lib/getch/config/iwd.rb +60 -0
- data/lib/getch/config/keymap.rb +78 -0
- data/lib/getch/config/locale.rb +96 -0
- data/lib/getch/config/portage.rb +90 -0
- data/lib/getch/config/pre_network.rb +37 -0
- data/lib/getch/config/timezone.rb +52 -0
- data/lib/getch/config/void.rb +0 -36
- data/lib/getch/config.rb +16 -37
- data/lib/getch/device.rb +67 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +9 -71
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +15 -25
- data/lib/getch/filesystem/ext4/encrypt/device.rb +11 -5
- data/lib/getch/filesystem/ext4/encrypt/format.rb +6 -15
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +7 -11
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -76
- data/lib/getch/filesystem/ext4/encrypt/void.rb +0 -38
- data/lib/getch/filesystem/ext4/encrypt.rb +2 -1
- data/lib/getch/filesystem/ext4/hybrid/config.rb +27 -0
- data/lib/getch/filesystem/ext4/hybrid/deps.rb +55 -0
- data/lib/getch/filesystem/ext4/hybrid/device.rb +24 -0
- data/lib/getch/filesystem/ext4/hybrid/format.rb +23 -0
- data/lib/getch/filesystem/ext4/hybrid/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/hybrid/partition.rb +27 -0
- data/lib/getch/filesystem/{lvm/encrypt → ext4/hybrid}/void.rb +0 -39
- data/lib/getch/filesystem/ext4/hybrid.rb +19 -0
- data/lib/getch/filesystem/ext4/lvm/config.rb +25 -0
- data/lib/getch/filesystem/ext4/lvm/deps.rb +56 -0
- data/lib/getch/filesystem/ext4/lvm/device.rb +28 -0
- data/lib/getch/filesystem/ext4/lvm/format.rb +21 -0
- data/lib/getch/filesystem/ext4/lvm/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/lvm/partition.rb +28 -0
- data/lib/getch/filesystem/{lvm.rb → ext4/lvm.rb} +6 -4
- data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
- data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +3 -1
- data/lib/getch/filesystem/ext4/minimal/device.rb +22 -0
- data/lib/getch/filesystem/ext4/minimal/format.rb +23 -0
- data/lib/getch/filesystem/ext4/minimal/mount.rb +21 -0
- data/lib/getch/filesystem/ext4/minimal/partition.rb +28 -0
- data/lib/getch/filesystem/ext4/minimal.rb +19 -0
- data/lib/getch/filesystem/ext4.rb +7 -7
- data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -39
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +4 -55
- data/lib/getch/filesystem/zfs/encrypt/device.rb +7 -51
- data/lib/getch/filesystem/zfs/encrypt/format.rb +6 -90
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -35
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +6 -54
- data/lib/getch/filesystem/zfs/encrypt.rb +2 -1
- data/lib/getch/filesystem/zfs/minimal/config.rb +37 -0
- data/lib/getch/filesystem/zfs/minimal/deps.rb +126 -0
- data/lib/getch/filesystem/zfs/minimal/device.rb +24 -0
- data/lib/getch/filesystem/zfs/minimal/format.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal/mount.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal/partition.rb +23 -0
- data/lib/getch/filesystem/zfs/minimal.rb +19 -0
- data/lib/getch/filesystem/zfs.rb +1 -7
- data/lib/getch/filesystem.rb +0 -6
- data/lib/getch/gentoo/bootloader.rb +23 -44
- data/lib/getch/gentoo/finalize.rb +25 -0
- data/lib/getch/gentoo/post_config.rb +75 -0
- data/lib/getch/gentoo/pre_config.rb +37 -0
- data/lib/getch/gentoo/services.rb +18 -0
- data/lib/getch/gentoo/sources.rb +39 -33
- data/lib/getch/gentoo/tarball.rb +91 -0
- data/lib/getch/gentoo/terraform.rb +34 -0
- data/lib/getch/gentoo/update.rb +54 -0
- data/lib/getch/gentoo/use.rb +9 -6
- data/lib/getch/gentoo/use_flag.rb +17 -20
- data/lib/getch/gentoo.rb +9 -75
- data/lib/getch/guard.rb +2 -2
- data/lib/getch/helpers.rb +63 -115
- data/lib/getch/log.rb +87 -25
- data/lib/getch/options.rb +41 -11
- data/lib/getch/states.rb +28 -8
- data/lib/getch/tree.rb +56 -0
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void/bootloader.rb +18 -0
- data/lib/getch/void/finalize.rb +31 -0
- data/lib/getch/void/post_config.rb +19 -0
- data/lib/getch/void/pre_config.rb +18 -0
- data/lib/getch/void/services.rb +18 -0
- data/lib/getch/void/{stage.rb → tarball.rb} +34 -14
- data/lib/getch/void/terraform.rb +28 -0
- data/lib/getch/void/update.rb +33 -0
- data/lib/getch/void.rb +9 -59
- data/lib/getch.rb +58 -90
- data/lib/luks.rb +239 -0
- data/lib/lvm2.rb +112 -0
- data/lib/mkfs/zfs.rb +167 -0
- data/lib/mkfs.rb +140 -0
- data/lib/mountfs.rb +154 -0
- data/lib/nito.rb +131 -0
- data/lib/sgdisk.rb +160 -0
- data.tar.gz.sig +0 -0
- metadata +83 -47
- metadata.gz.sig +0 -0
- data/lib/getch/config/gentoo.rb +0 -58
- data/lib/getch/filesystem/clean.rb +0 -58
- data/lib/getch/filesystem/device.rb +0 -63
- data/lib/getch/filesystem/ext4/config.rb +0 -62
- data/lib/getch/filesystem/ext4/deps.rb +0 -24
- data/lib/getch/filesystem/ext4/format.rb +0 -31
- data/lib/getch/filesystem/ext4/mount.rb +0 -26
- data/lib/getch/filesystem/ext4/partition.rb +0 -55
- data/lib/getch/filesystem/ext4/void.rb +0 -44
- data/lib/getch/filesystem/lvm/config.rb +0 -44
- data/lib/getch/filesystem/lvm/deps.rb +0 -44
- data/lib/getch/filesystem/lvm/device.rb +0 -45
- data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -74
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -49
- data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -48
- data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -35
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -27
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -84
- data/lib/getch/filesystem/lvm/encrypt.rb +0 -18
- data/lib/getch/filesystem/lvm/format.rb +0 -32
- data/lib/getch/filesystem/lvm/mount.rb +0 -26
- data/lib/getch/filesystem/lvm/partition.rb +0 -72
- data/lib/getch/filesystem/lvm/void.rb +0 -46
- data/lib/getch/filesystem/mount.rb +0 -63
- data/lib/getch/filesystem/partition.rb +0 -85
- data/lib/getch/filesystem/zfs/config.rb +0 -43
- data/lib/getch/filesystem/zfs/deps.rb +0 -67
- data/lib/getch/filesystem/zfs/device.rb +0 -66
- data/lib/getch/filesystem/zfs/encrypt/void.rb +0 -97
- data/lib/getch/filesystem/zfs/format.rb +0 -117
- data/lib/getch/filesystem/zfs/mount.rb +0 -47
- data/lib/getch/filesystem/zfs/partition.rb +0 -69
- data/lib/getch/filesystem/zfs/void.rb +0 -81
- data/lib/getch/gentoo/boot.rb +0 -64
- data/lib/getch/gentoo/chroot.rb +0 -75
- data/lib/getch/gentoo/config.rb +0 -167
- data/lib/getch/gentoo/stage.rb +0 -73
- data/lib/getch/void/boot.rb +0 -84
- data/lib/getch/void/chroot.rb +0 -56
- data/lib/getch/void/config.rb +0 -90
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'nito'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
|
|
4
|
+
module Getch
|
|
5
|
+
module Config
|
|
6
|
+
class Portage
|
|
7
|
+
include NiTo
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@log = Log.new
|
|
11
|
+
@dest = "#{OPTIONS[:mountpoint]}/etc/portage"
|
|
12
|
+
@usr_s = "#{OPTIONS[:mountpoint]}/usr/share/portage"
|
|
13
|
+
x
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def x
|
|
17
|
+
@log.info "Configuring Portage...\n"
|
|
18
|
+
portage_dir
|
|
19
|
+
gentoo_repo
|
|
20
|
+
cpu_conf
|
|
21
|
+
make_conf
|
|
22
|
+
https_mirror
|
|
23
|
+
license
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
protected
|
|
27
|
+
|
|
28
|
+
def portage_dir
|
|
29
|
+
mkdir "#{@dest}/package.use", 0744
|
|
30
|
+
mkdir "#{@dest}/package.accept_keywords", 0744
|
|
31
|
+
mkdir "#{@dest}/package.unmask", 0744
|
|
32
|
+
mkdir "#{@dest}/package.license", 0744
|
|
33
|
+
|
|
34
|
+
touch "#{@dest}/package.use/zzz_via_autounmask"
|
|
35
|
+
touch "#{@dest}/package.accept_keywords/zzz_via_autounmask"
|
|
36
|
+
touch "#{@dest}/package.unmask/zzz_via_autounmask"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Recreate a gentoo.conf from /usr/share/portage/config/repos.conf
|
|
40
|
+
def gentoo_repo
|
|
41
|
+
mkdir "#{@dest}/repos.conf", 0644
|
|
42
|
+
cp "#{@usr_s}/config/repos.conf", "#{@dest}/repos.conf/gentoo.conf"
|
|
43
|
+
sed "#{@dest}/repos.conf/gentoo.conf", /^sync-type/, 'sync-type = webrsync'
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# -fomit-frame-pointer reduce code compiled
|
|
47
|
+
# but have repercussions on the debugging of applications
|
|
48
|
+
def cpu_conf
|
|
49
|
+
change = 'COMMON_FLAGS="-march=native -O2 -pipe -fomit-frame-pointer"'
|
|
50
|
+
sed "#{@dest}/make.conf", /^COMMON_FLAGS/, change
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#MAKEOPTS
|
|
54
|
+
def make_conf
|
|
55
|
+
mem = get_memory
|
|
56
|
+
makeopts = mem[0].to_i / 2
|
|
57
|
+
|
|
58
|
+
echo_a "#{@dest}/make.conf", 'ACCEPT_KEYWORDS="amd64"'
|
|
59
|
+
echo_a "#{@dest}/make.conf", 'INPUT_DEVICES="libinput"'
|
|
60
|
+
echo_a "#{@dest}/make.conf", "MAKEOPTS=\"-j#{makeopts}\""
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# https://www.gentoo.org/downloads/mirrors/
|
|
64
|
+
def https_mirror
|
|
65
|
+
list = 'https://gentoo.osuosl.org'
|
|
66
|
+
list << ' https://mirrors.rit.edu/gentoo'
|
|
67
|
+
list << ' https://ftp.belnet.be/pub/rsync.gentoo.org/gentoo'
|
|
68
|
+
list << ' https://mirror.init7.net/gentoo'
|
|
69
|
+
echo_a "#{@dest}/make.conf", "GENTOO_MIRRORS=\"#{list}\""
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def license
|
|
73
|
+
conf = "#{@dest}/package.license/kernel"
|
|
74
|
+
echo conf, 'sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE'
|
|
75
|
+
echo_a conf, 'sys-firmware/intel-microcode intel-ucode'
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def get_memory
|
|
81
|
+
mem = '2048'
|
|
82
|
+
File.open('/proc/meminfo').each do |l|
|
|
83
|
+
t = l.split(' ') if l =~ /memtotal/i
|
|
84
|
+
t && mem = t[1]
|
|
85
|
+
end
|
|
86
|
+
mem
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'nito'
|
|
2
|
+
|
|
3
|
+
module Getch
|
|
4
|
+
module Config
|
|
5
|
+
class PreNetwork
|
|
6
|
+
include NiTo
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@log = Log.new
|
|
10
|
+
x
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
protected
|
|
14
|
+
|
|
15
|
+
def x
|
|
16
|
+
@log.info "Configuring pre-network...\n"
|
|
17
|
+
hostname
|
|
18
|
+
copy_dns
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def hostname
|
|
24
|
+
@log.info 'Writing /etc/hostname...'
|
|
25
|
+
echo "#{OPTIONS[:mountpoint]}/etc/hostname", 'host'
|
|
26
|
+
@log.result_ok
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def copy_dns
|
|
30
|
+
@log.info 'Copying DNS from current host...'
|
|
31
|
+
cp '/etc/resolv.conf', "#{OPTIONS[:mountpoint]}/etc/resolv.conf"
|
|
32
|
+
echo_a "#{OPTIONS[:mountpoint]}/etc/resolv.conf", 'nameserver 127.0.0.1'
|
|
33
|
+
@log.result_ok
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'nito'
|
|
4
|
+
|
|
5
|
+
module Getch
|
|
6
|
+
module Config
|
|
7
|
+
class TimeZone
|
|
8
|
+
include NiTo
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@log = Log.new
|
|
12
|
+
@etc_timezone = "#{OPTIONS[:mountpoint]}/etc/timezone"
|
|
13
|
+
@rc_conf = "#{OPTIONS[:mountpoint]}/etc/rc.conf"
|
|
14
|
+
@openrc = "#{OPTIONS[:mountpoint]}/etc/conf.d/keymaps"
|
|
15
|
+
@timezone = OPTIONS[:timezone]
|
|
16
|
+
x
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
protected
|
|
20
|
+
|
|
21
|
+
def x
|
|
22
|
+
@log.info "Configuring timezone to #{@timezone}...\n"
|
|
23
|
+
for_runit
|
|
24
|
+
for_openrc
|
|
25
|
+
for_systemd
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def for_runit
|
|
31
|
+
return unless Helpers.runit?
|
|
32
|
+
|
|
33
|
+
echo_a @rc_conf, "TIMEZONE=\"#{@timezone}\""
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def for_openrc
|
|
37
|
+
return unless Helpers.openrc?
|
|
38
|
+
|
|
39
|
+
echo_a @etc_timezone, OPTIONS[:timezone]
|
|
40
|
+
Getch::Chroot.new('emerge --config sys-libs/timezone-data')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def for_systemd
|
|
44
|
+
return unless Helpers.systemd?
|
|
45
|
+
|
|
46
|
+
src = "/usr/share/zoneinfo/#{OPTIONS[:timezone]}"
|
|
47
|
+
dest = "/etc/localtime"
|
|
48
|
+
Getch::Chroot.new('ln', '-sf', src, dest)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/getch/config/void.rb
CHANGED
|
@@ -3,42 +3,6 @@
|
|
|
3
3
|
module Getch
|
|
4
4
|
module Config
|
|
5
5
|
class Void
|
|
6
|
-
include Helpers::Void
|
|
7
|
-
|
|
8
|
-
def initialize
|
|
9
|
-
@service_dir = '/etc/runit/runsvdir/default/'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Enable dhcpcd service
|
|
13
|
-
def ethernet
|
|
14
|
-
command "ln -fs /etc/sv/dhcpcd #{@service_dir}"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# with Quad9
|
|
18
|
-
# https://www.dnsknowledge.com/tutorials/how-to-setup-quad9-dns-on-a-linux/
|
|
19
|
-
def dns
|
|
20
|
-
conf = "#{MOUNTPOINT}/etc/resolv.conf"
|
|
21
|
-
content = [
|
|
22
|
-
'nameserver 9.9.9.9',
|
|
23
|
-
'nameserver 2620:fe::fe',
|
|
24
|
-
'options rotate',
|
|
25
|
-
]
|
|
26
|
-
File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# https://docs.voidlinux.org/config/network/iwd.html
|
|
30
|
-
def wifi
|
|
31
|
-
conf = "#{MOUNTPOINT}/etc/iwd/main.conf"
|
|
32
|
-
content = [
|
|
33
|
-
'[General]',
|
|
34
|
-
'UseDefaultInterface=true',
|
|
35
|
-
]
|
|
36
|
-
File.write(conf, content.join("\n"), mode: 'a', chmod: 0644)
|
|
37
|
-
# Enabling dbus and iwd
|
|
38
|
-
command "ln -fs /etc/sv/dbus #{@service_dir}"
|
|
39
|
-
command "ln -fs /etc/sv/iwd #{@service_dir}"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
6
|
def shell
|
|
43
7
|
command 'chsh -s /bin/bash'
|
|
44
8
|
end
|
data/lib/getch/config.rb
CHANGED
|
@@ -1,45 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'config/gentoo'
|
|
4
|
-
require_relative 'config/void'
|
|
5
|
-
|
|
6
|
-
CONFIG_LOAD = {
|
|
7
|
-
gentoo: Getch::Config::Gentoo,
|
|
8
|
-
void: Getch::Config::Void
|
|
9
|
-
}.freeze
|
|
10
|
-
|
|
11
3
|
module Getch
|
|
12
4
|
module Config
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@load = CONFIG_LOAD[os].new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def ethernet
|
|
20
|
-
@load.ethernet
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def dns
|
|
24
|
-
@load.dns
|
|
25
|
-
end
|
|
5
|
+
def sysctl
|
|
6
|
+
pwd = File.expand_path(File.dirname(__FILE__))
|
|
7
|
+
dest = "#{Getch::MOUNTPOINT}/etc/sysctl.d/"
|
|
26
8
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def sysctl
|
|
32
|
-
pwd = File.expand_path(File.dirname(__FILE__))
|
|
33
|
-
dest = "#{Getch::MOUNTPOINT}/etc/sysctl.d/"
|
|
34
|
-
|
|
35
|
-
Helpers.mkdir dest
|
|
36
|
-
Helpers.cp("#{pwd}/../../assets/network-stack.conf", dest)
|
|
37
|
-
Helpers.cp("#{pwd}/../../assets/system.conf", dest)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def shell
|
|
41
|
-
@load.shell
|
|
42
|
-
end
|
|
9
|
+
mkdir dest
|
|
10
|
+
Helpers.cp("#{pwd}/../../assets/network-stack.conf", dest)
|
|
11
|
+
Helpers.cp("#{pwd}/../../assets/system.conf", dest)
|
|
43
12
|
end
|
|
44
13
|
end
|
|
45
14
|
end
|
|
15
|
+
|
|
16
|
+
require_relative 'config/portage'
|
|
17
|
+
require_relative 'config/locale'
|
|
18
|
+
require_relative 'config/pre_network'
|
|
19
|
+
require_relative 'config/keymap'
|
|
20
|
+
require_relative 'config/timezone'
|
|
21
|
+
require_relative 'config/grub'
|
|
22
|
+
require_relative 'config/account'
|
|
23
|
+
require_relative 'config/iwd'
|
|
24
|
+
require_relative 'config/dhcp'
|
data/lib/getch/device.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module Getch
|
|
6
|
+
class Device
|
|
7
|
+
def initialize
|
|
8
|
+
@file = File.join('/tmp/getch_devs.yaml')
|
|
9
|
+
load_devs
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def gpt(dev)
|
|
13
|
+
DEVS[:gpt] = dev
|
|
14
|
+
save
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def efi(dev)
|
|
18
|
+
DEVS[:efi] = dev
|
|
19
|
+
save
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def boot(dev)
|
|
23
|
+
DEVS[:boot] = dev
|
|
24
|
+
save
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def swap(dev)
|
|
28
|
+
DEVS[:swap] = dev
|
|
29
|
+
save
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def root(dev)
|
|
33
|
+
DEVS[:root] = dev
|
|
34
|
+
save
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def home(dev)
|
|
38
|
+
DEVS[:home] = dev
|
|
39
|
+
save
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def zlog(dev)
|
|
43
|
+
DEVS[:zlog] = dev
|
|
44
|
+
save
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def zcache(dev)
|
|
48
|
+
DEVS[:zcache] = dev
|
|
49
|
+
save
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def load_devs
|
|
55
|
+
if File.exist? @file
|
|
56
|
+
DEVS.merge! YAML.load_file @file
|
|
57
|
+
else
|
|
58
|
+
save
|
|
59
|
+
warn "Init devs at #{@file}"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def save
|
|
64
|
+
File.open(@file, 'w') { |f| YAML.dump(DEVS, f) }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -1,86 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
3
|
+
require 'fstab'
|
|
4
|
+
require 'dracut'
|
|
5
|
+
require 'cryptsetup'
|
|
4
6
|
|
|
5
7
|
module Getch
|
|
6
8
|
module FileSystem
|
|
7
9
|
module Ext4
|
|
8
10
|
module Encrypt
|
|
9
|
-
class Config
|
|
11
|
+
class Config
|
|
10
12
|
def initialize
|
|
11
|
-
|
|
12
|
-
gen_uuid
|
|
13
|
-
@root_dir = MOUNTPOINT
|
|
14
|
-
@init = '/usr/lib/systemd/systemd'
|
|
15
|
-
move_secret_keys
|
|
16
|
-
crypttab
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def fstab
|
|
20
|
-
file = "#{@root_dir}/etc/fstab"
|
|
21
|
-
datas = data_fstab
|
|
22
|
-
File.write(file, datas.join("\n"))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def systemd_boot
|
|
26
|
-
return unless Helpers.efi?
|
|
27
|
-
|
|
28
|
-
esp = '/efi'
|
|
29
|
-
dir = "#{@root_dir}/#{esp}/loader/entries/"
|
|
30
|
-
datas_gentoo = [
|
|
31
|
-
'title Gentoo Linux',
|
|
32
|
-
'linux /vmlinuz',
|
|
33
|
-
'initrd /initramfs',
|
|
34
|
-
"options crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/root init=#{@init} keymap=#{Getch::OPTIONS[:keymap]} rw"
|
|
35
|
-
]
|
|
36
|
-
File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def crypttab
|
|
40
|
-
home = @home_disk ? "crypthome UUID=#{@uuid_home} /root/secretkeys/crypto_keyfile.bin luks" : ''
|
|
41
|
-
datas = [
|
|
42
|
-
"cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=512",
|
|
43
|
-
home
|
|
44
|
-
]
|
|
45
|
-
File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def grub
|
|
49
|
-
return if Helpers.efi?
|
|
50
|
-
|
|
51
|
-
file = "#{@root_dir}/etc/default/grub"
|
|
52
|
-
cmdline = [
|
|
53
|
-
"GRUB_CMDLINE_LINUX=\"crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/root init=#{@init} rw slub_debug=P page_poison=1 slab_nomerge pti=on vsyscall=none spectre_v2=on spec_store_bypass_disable=seccomp iommu=force keymap=#{Getch::OPTIONS[:keymap]}\"",
|
|
54
|
-
"GRUB_ENABLE_CRYPTODISK=y"
|
|
55
|
-
]
|
|
56
|
-
File.write(file, cmdline.join("\n"), mode: 'a')
|
|
13
|
+
x
|
|
57
14
|
end
|
|
58
15
|
|
|
59
16
|
private
|
|
60
17
|
|
|
61
|
-
def
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@uuid_root = `lsblk -d -o "UUID" #{@luks_root} | tail -1`.chomp() if @dev_root
|
|
66
|
-
@uuid_home = `lsblk -d -o "UUID" #{@dev_home} | tail -1`.chomp() if @luks_home
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def data_fstab
|
|
70
|
-
boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
|
|
71
|
-
swap = @dev_swap ? "#{@luks_swap} none swap discard 0 0 " : ''
|
|
72
|
-
root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
|
|
73
|
-
home = @dev_home ? "#{@luks_home} /home/#{@user} ext4 defaults 0 2" : ''
|
|
74
|
-
|
|
75
|
-
[ boot_efi, swap, root, home ]
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def move_secret_keys
|
|
79
|
-
return unless @luks_home
|
|
80
|
-
|
|
81
|
-
puts 'Moving secret keys'
|
|
82
|
-
keys_path = "#{@root_dir}/root/secretkeys"
|
|
83
|
-
FileUtils.mv('/root/secretkeys', keys_path) unless Dir.exist? keys_path
|
|
18
|
+
def x
|
|
19
|
+
Fstab::Encrypt.new(DEVS, OPTIONS).generate
|
|
20
|
+
Dracut::Encrypt.new(DEVS, OPTIONS).generate
|
|
21
|
+
CryptSetup.new(DEVS, OPTIONS).configs
|
|
84
22
|
end
|
|
85
23
|
end
|
|
86
24
|
end
|
|
@@ -5,38 +5,28 @@ module Getch
|
|
|
5
5
|
module Ext4
|
|
6
6
|
module Encrypt
|
|
7
7
|
class Deps
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Getch::Make.new('genkernel --kernel-config=/usr/src/linux/.config all').run!
|
|
8
|
+
def initialize
|
|
9
|
+
install
|
|
10
|
+
service
|
|
12
11
|
end
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
protected
|
|
15
14
|
|
|
16
|
-
def
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'INSTALL="yes"',
|
|
22
|
-
'MENUCONFIG="no"',
|
|
23
|
-
'CLEAN="yes"',
|
|
24
|
-
'KEYMAP="yes"',
|
|
25
|
-
'SAVE_CONFIG="yes"',
|
|
26
|
-
'MOUNTBOOT="yes"',
|
|
27
|
-
'MRPROPER="no"',
|
|
28
|
-
'LUKS="yes"',
|
|
29
|
-
]
|
|
30
|
-
file = "#{MOUNTPOINT}/etc/genkernel.conf"
|
|
31
|
-
File.write(file, datas.join("\n"), mode: 'a')
|
|
15
|
+
def install
|
|
16
|
+
case OPTIONS[:os]
|
|
17
|
+
when 'gentoo' then Install.new('sys-fs/cryptsetup')
|
|
18
|
+
when 'void' then Install.new('cryptsetup')
|
|
19
|
+
end
|
|
32
20
|
end
|
|
33
21
|
|
|
34
|
-
def
|
|
35
|
-
|
|
22
|
+
def service
|
|
23
|
+
openrc
|
|
36
24
|
end
|
|
37
25
|
|
|
38
|
-
def
|
|
39
|
-
|
|
26
|
+
def openrc
|
|
27
|
+
Helpers.openrc? || return
|
|
28
|
+
|
|
29
|
+
Chroot.new('rc-update add dmcrypt boot')
|
|
40
30
|
end
|
|
41
31
|
end
|
|
42
32
|
end
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'devs'
|
|
4
|
+
|
|
3
5
|
module Getch
|
|
4
6
|
module FileSystem
|
|
5
7
|
module Ext4
|
|
6
8
|
module Encrypt
|
|
7
|
-
class Device
|
|
9
|
+
class Device
|
|
8
10
|
def initialize
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
@args = { start: true, boot: true, swap: true, root: true }
|
|
12
|
+
x
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def x
|
|
18
|
+
Devs::Settings.new(@args, OPTIONS)
|
|
13
19
|
end
|
|
14
20
|
end
|
|
15
21
|
end
|
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'mkfs'
|
|
4
|
+
|
|
3
5
|
module Getch
|
|
4
6
|
module FileSystem
|
|
5
7
|
module Ext4
|
|
6
8
|
module Encrypt
|
|
7
|
-
class Format
|
|
9
|
+
class Format
|
|
8
10
|
def initialize
|
|
9
|
-
|
|
10
|
-
@state = Getch::States.new
|
|
11
|
-
format
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def format
|
|
15
|
-
return if STATES[:format]
|
|
16
|
-
|
|
17
|
-
exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
|
|
18
|
-
exec("mkfs.ext4 -F #{@luks_root}")
|
|
19
|
-
exec("mkfs.ext4 -F #{@luks_home}") if @dev_home
|
|
20
|
-
@state.format
|
|
11
|
+
x
|
|
21
12
|
end
|
|
22
13
|
|
|
23
14
|
private
|
|
24
15
|
|
|
25
|
-
def
|
|
26
|
-
|
|
16
|
+
def x
|
|
17
|
+
Mkfs::Encrypt.new(DEVS, OPTIONS)
|
|
27
18
|
end
|
|
28
19
|
end
|
|
29
20
|
end
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'mountfs'
|
|
4
|
+
|
|
3
5
|
module Getch
|
|
4
6
|
module FileSystem
|
|
5
7
|
module Ext4
|
|
6
8
|
module Encrypt
|
|
7
|
-
class Mount
|
|
9
|
+
class Mount
|
|
8
10
|
def initialize
|
|
9
|
-
|
|
10
|
-
@mount = Getch::FileSystem::Mount.new
|
|
11
|
-
@state = Getch::States.new
|
|
11
|
+
x
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
return if STATES[:mount]
|
|
14
|
+
private
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@mount.esp(@dev_esp)
|
|
20
|
-
@mount.home(@luks_home)
|
|
21
|
-
@state.mount
|
|
16
|
+
def x
|
|
17
|
+
MountFs::Encrypt.new(DEVS, OPTIONS)
|
|
22
18
|
end
|
|
23
19
|
end
|
|
24
20
|
end
|