getch 0.1.0 → 0.1.6
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.tar.gz.sig +0 -0
- data/README.md +95 -22
- data/assets/network-stack.conf +63 -0
- data/bin/getch +12 -4
- data/lib/getch.rb +116 -66
- data/lib/getch/command.rb +19 -5
- data/lib/getch/config.rb +42 -0
- data/lib/getch/config/gentoo.rb +59 -0
- data/lib/getch/config/void.rb +49 -0
- data/lib/getch/filesystem.rb +5 -0
- data/lib/getch/filesystem/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/clean.rb +58 -0
- data/lib/getch/filesystem/device.rb +61 -0
- data/lib/getch/filesystem/ext4.rb +1 -0
- data/lib/getch/filesystem/ext4/config.rb +8 -9
- data/lib/getch/filesystem/ext4/device.rb +2 -7
- data/lib/getch/filesystem/ext4/encrypt.rb +1 -0
- data/lib/getch/filesystem/ext4/encrypt/config.rb +8 -9
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +3 -19
- data/lib/getch/filesystem/ext4/encrypt/device.rb +3 -8
- data/lib/getch/filesystem/ext4/encrypt/format.rb +3 -6
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +5 -43
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +29 -54
- data/lib/getch/filesystem/ext4/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/ext4/format.rb +4 -6
- data/lib/getch/filesystem/ext4/mount.rb +7 -46
- data/lib/getch/filesystem/ext4/partition.rb +16 -39
- data/lib/getch/filesystem/ext4/void.rb +43 -0
- data/lib/getch/filesystem/lvm.rb +1 -0
- data/lib/getch/filesystem/lvm/config.rb +11 -15
- data/lib/getch/filesystem/lvm/deps.rb +4 -19
- data/lib/getch/filesystem/lvm/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt.rb +1 -0
- data/lib/getch/filesystem/lvm/encrypt/config.rb +9 -12
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +4 -21
- data/lib/getch/filesystem/lvm/encrypt/device.rb +33 -9
- data/lib/getch/filesystem/lvm/encrypt/format.rb +3 -4
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +7 -47
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +30 -38
- data/lib/getch/filesystem/lvm/encrypt/void.rb +100 -0
- data/lib/getch/filesystem/lvm/format.rb +12 -8
- data/lib/getch/filesystem/lvm/mount.rb +7 -46
- data/lib/getch/filesystem/lvm/partition.rb +19 -31
- data/lib/getch/filesystem/lvm/void.rb +45 -0
- data/lib/getch/filesystem/mount.rb +56 -0
- data/lib/getch/filesystem/partition.rb +77 -0
- data/lib/getch/filesystem/zfs.rb +1 -0
- data/lib/getch/filesystem/zfs/config.rb +7 -8
- data/lib/getch/filesystem/zfs/deps.rb +24 -12
- data/lib/getch/filesystem/zfs/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt.rb +1 -0
- data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/zfs/encrypt/config.rb +11 -11
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +24 -14
- data/lib/getch/filesystem/zfs/encrypt/device.rb +54 -9
- data/lib/getch/filesystem/zfs/encrypt/format.rb +84 -3
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +8 -28
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +26 -109
- data/lib/getch/filesystem/zfs/encrypt/void.rb +96 -0
- data/lib/getch/filesystem/zfs/format.rb +97 -4
- data/lib/getch/filesystem/zfs/mount.rb +10 -32
- data/lib/getch/filesystem/zfs/partition.rb +25 -106
- data/lib/getch/filesystem/zfs/void.rb +81 -0
- data/lib/getch/gentoo.rb +20 -16
- data/lib/getch/gentoo/boot.rb +24 -16
- data/lib/getch/gentoo/chroot.rb +16 -25
- data/lib/getch/gentoo/config.rb +67 -15
- data/lib/getch/gentoo/sources.rb +55 -13
- data/lib/getch/gentoo/stage.rb +0 -1
- data/lib/getch/gentoo/use.rb +43 -0
- data/lib/getch/gentoo/use_flag.rb +63 -0
- data/lib/getch/guard.rb +64 -0
- data/lib/getch/helpers.rb +133 -0
- data/lib/getch/log.rb +3 -2
- data/lib/getch/options.rb +46 -24
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void.rb +59 -0
- data/lib/getch/void/boot.rb +80 -0
- data/lib/getch/void/chroot.rb +55 -0
- data/lib/getch/void/config.rb +87 -0
- data/lib/getch/void/stage.rb +70 -0
- metadata +46 -25
- metadata.gz.sig +0 -0
- data/.gitignore +0 -2
- data/CHANGELOG.md +0 -60
- data/Rakefile +0 -21
- data/bin/setup.sh +0 -90
- data/getch.gemspec +0 -25
data/lib/getch/gentoo/sources.rb
CHANGED
|
@@ -3,31 +3,37 @@ module Getch
|
|
|
3
3
|
class Sources
|
|
4
4
|
def initialize
|
|
5
5
|
@lsmod = `lsmod`.chomp
|
|
6
|
-
@
|
|
6
|
+
@class_fs = Getch::select_fs
|
|
7
|
+
@filesystem = @class_fs::Deps.new
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
def build_others
|
|
11
|
+
cryptsetup
|
|
10
12
|
virtualbox_guest
|
|
11
13
|
qemu_guest
|
|
12
14
|
install_wifi
|
|
13
15
|
install_audio
|
|
16
|
+
flash_mod
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def build_kspp
|
|
17
20
|
puts "Adding KSPP to the kernel source"
|
|
18
|
-
|
|
21
|
+
bask("-b -a systemd")
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
def make
|
|
22
|
-
if
|
|
25
|
+
if Getch::OPTIONS[:fs] == 'lvm' ||
|
|
26
|
+
Getch::OPTIONS[:fs] == 'zfs' ||
|
|
27
|
+
Getch::OPTIONS[:encrypt]
|
|
23
28
|
@filesystem.make
|
|
24
29
|
else
|
|
25
30
|
make_kernel
|
|
26
31
|
end
|
|
27
32
|
end
|
|
28
33
|
|
|
29
|
-
def
|
|
30
|
-
|
|
34
|
+
def firewall
|
|
35
|
+
bask("-a iptables")
|
|
36
|
+
Getch::Emerge.new("net-firewall/iptables").pkg!
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
private
|
|
@@ -40,40 +46,76 @@ module Getch
|
|
|
40
46
|
raise "No kernel installed, compiling source fail..." if is_kernel == []
|
|
41
47
|
end
|
|
42
48
|
|
|
49
|
+
def cryptsetup
|
|
50
|
+
return unless Getch::OPTIONS[:encrypt]
|
|
51
|
+
make_conf = "#{MOUNTPOINT}/etc/portage/make.conf"
|
|
52
|
+
|
|
53
|
+
puts "Adding support for cryptsetup."
|
|
54
|
+
bask("-a cryptsetup")
|
|
55
|
+
Getch::Chroot.new("euse -E cryptsetup").run! unless Helpers::grep?(make_conf, /cryptsetup/)
|
|
56
|
+
Getch::Emerge.new("sys-fs/cryptsetup").pkg!
|
|
57
|
+
end
|
|
58
|
+
|
|
43
59
|
def virtualbox_guest
|
|
44
60
|
systemd=`systemd-detect-virt`.chomp
|
|
45
61
|
return if ! ismatch?('vmwgfx') || systemd.match(/none/)
|
|
46
|
-
|
|
62
|
+
bask("-a virtualbox-guest")
|
|
47
63
|
Getch::Emerge.new("app-emulation/virtualbox-guest-additions").pkg!
|
|
48
64
|
end
|
|
49
65
|
|
|
50
66
|
def qemu_guest
|
|
51
|
-
|
|
52
|
-
|
|
67
|
+
bask("-a kvm-host") if ismatch?('kvm')
|
|
68
|
+
bask("-a kvm-guest") if ismatch?('virtio')
|
|
53
69
|
end
|
|
54
70
|
|
|
55
71
|
def ismatch?(arg)
|
|
56
72
|
@lsmod.match?(/#{arg}/)
|
|
57
73
|
end
|
|
58
74
|
|
|
59
|
-
def
|
|
60
|
-
Getch::
|
|
75
|
+
def bask(cmd)
|
|
76
|
+
Getch::Bask.new(cmd).run!
|
|
61
77
|
end
|
|
62
78
|
|
|
63
79
|
def install_wifi
|
|
64
80
|
return if ! ismatch?('cfg80211')
|
|
65
|
-
|
|
81
|
+
bask("-a wifi")
|
|
66
82
|
wifi_drivers
|
|
67
83
|
Getch::Emerge.new("net-wireless/iw wpa_supplicant net-wireless/iwd").pkg!
|
|
68
84
|
end
|
|
69
85
|
|
|
70
86
|
def install_audio
|
|
71
87
|
return if ! ismatch?('snd_pcm')
|
|
72
|
-
|
|
88
|
+
bask("-a sound")
|
|
73
89
|
end
|
|
74
90
|
|
|
75
91
|
def wifi_drivers
|
|
76
|
-
|
|
92
|
+
conf = "#{MOUNTPOINT}/etc/modules-load.d/wifi.conf"
|
|
93
|
+
File.delete(conf) if File.exists? conf
|
|
94
|
+
|
|
95
|
+
if ismatch?('ath9k')
|
|
96
|
+
bask("-a ath9k-driver")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
module_load("iwlmvm", conf)
|
|
100
|
+
module_load("ath9k", conf)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def flash_mod
|
|
104
|
+
conf = "#{MOUNTPOINT}/etc/modules-load.d/usb.conf"
|
|
105
|
+
File.delete(conf) if File.exists? conf
|
|
106
|
+
|
|
107
|
+
module_load("ehci_pci", conf)
|
|
108
|
+
module_load("rtsx_pci_sdmmc", conf)
|
|
109
|
+
module_load("sdhci_pci", conf)
|
|
110
|
+
module_load("uas", conf)
|
|
111
|
+
module_load("uhci_hcd", conf)
|
|
112
|
+
module_load("xhci_pci", conf)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def module_load(name, file)
|
|
116
|
+
return unless name
|
|
117
|
+
return unless ismatch?(name)
|
|
118
|
+
File.write(file, "#{name}\n", mode: 'a')
|
|
77
119
|
end
|
|
78
120
|
end
|
|
79
121
|
end
|
data/lib/getch/gentoo/stage.rb
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Getch
|
|
2
|
+
module Gentoo
|
|
3
|
+
class Use
|
|
4
|
+
def initialize(pkg = nil)
|
|
5
|
+
@use_dir = "#{MOUNTPOINT}/etc/portage/package.use"
|
|
6
|
+
@pkg = pkg
|
|
7
|
+
@file = @pkg ? @pkg.match(/[\w]+$/) : nil
|
|
8
|
+
@make = "#{MOUNTPOINT}/etc/portage/make.conf"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def add(*flags)
|
|
12
|
+
@flags = flags.join(' ')
|
|
13
|
+
write
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_global(*flags)
|
|
17
|
+
@flags = flags
|
|
18
|
+
write_global
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def write
|
|
24
|
+
content = "#{@pkg} #{@flags}\n"
|
|
25
|
+
File.write("#{@use_dir}/#{@file}", content, mode: 'w')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def write_global
|
|
29
|
+
list = []
|
|
30
|
+
|
|
31
|
+
@flags.each { |f|
|
|
32
|
+
unless Helpers::grep?(@make, /#{f}/)
|
|
33
|
+
list << f
|
|
34
|
+
end
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
use = list.join(' ')
|
|
38
|
+
line = "USE=\"${USE} #{use}\"\n"
|
|
39
|
+
File.write(@make, line, mode: 'a')
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# lib/use_flag.rb
|
|
2
|
+
|
|
3
|
+
module Getch::Gentoo
|
|
4
|
+
class UseFlag
|
|
5
|
+
def initialize
|
|
6
|
+
@efi = Helpers::efi?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def apply
|
|
10
|
+
systemd
|
|
11
|
+
kmod
|
|
12
|
+
grub
|
|
13
|
+
zfs
|
|
14
|
+
lvm
|
|
15
|
+
cryptsetup
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def systemd
|
|
21
|
+
flags = []
|
|
22
|
+
use = Getch::Gentoo::Use.new('sys-apps/systemd')
|
|
23
|
+
flags << 'dns-over-tls'
|
|
24
|
+
flags << 'gnuefi' if @efi
|
|
25
|
+
use.add(flags)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def kmod
|
|
29
|
+
use = Getch::Gentoo::Use.new('sys-apps/kmod')
|
|
30
|
+
use.add('zstd', 'lzma')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def grub
|
|
34
|
+
return if @efi
|
|
35
|
+
flags = []
|
|
36
|
+
use = Getch::Gentoo::Use.new('sys-boot/grub')
|
|
37
|
+
flags << '-grub_platforms_efi-64'
|
|
38
|
+
flags << 'libzfs' if Getch::OPTIONS[:fs] == 'zfs'
|
|
39
|
+
flags << 'device-mapper' if Getch::OPTIONS[:fs] == 'lvm'
|
|
40
|
+
use.add(flags)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def zfs
|
|
44
|
+
return unless Getch::OPTIONS[:fs] == 'zfs'
|
|
45
|
+
use = Getch::Gentoo::Use.new('sys-fs/zfs-kmod')
|
|
46
|
+
use.add('rootfs')
|
|
47
|
+
use = Getch::Gentoo::Use.new('sys-fs/zfs')
|
|
48
|
+
use.add('rootfs')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def lvm
|
|
52
|
+
return unless Getch::OPTIONS[:fs] == 'lvm'
|
|
53
|
+
use = Getch::Gentoo::Use.new
|
|
54
|
+
use.add_global('lvm', 'device-mapper')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def cryptsetup
|
|
58
|
+
return unless Getch::OPTIONS[:encrypt]
|
|
59
|
+
use = Getch::Gentoo::Use.new
|
|
60
|
+
use.add_global('cryptsetup')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
data/lib/getch/guard.rb
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
class InvalidDisk < StandardError
|
|
2
|
+
end
|
|
3
|
+
|
|
4
|
+
class InvalidFormat < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class InvalidZone < StandardError
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class InvalidKeymap < StandardError
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Getch::Guard
|
|
14
|
+
def self.disk(name)
|
|
15
|
+
raise InvalidDisk, "No disk." unless name
|
|
16
|
+
raise InvalidDisk, "Bad device name #{name}." unless name.match(/^sd[a-z]{1}$/)
|
|
17
|
+
raise InvalidDisk, "Disk /dev/#{name} no found." unless File.exist? "/dev/#{name}"
|
|
18
|
+
name
|
|
19
|
+
rescue InvalidDisk => e
|
|
20
|
+
puts "#{e.class} => #{e}"
|
|
21
|
+
exit 1
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.format(name)
|
|
25
|
+
raise InvalidFormat, "No format specified." unless name
|
|
26
|
+
raise InvalidFormat, "Format #{name} not yet available." if name.match(/btrfs/)
|
|
27
|
+
raise InvalidFormat, "Format #{name} not supported." unless name.match(/zfs|lvm|ext4/)
|
|
28
|
+
name
|
|
29
|
+
rescue InvalidFormat => e
|
|
30
|
+
puts "#{e.class} => #{e}"
|
|
31
|
+
exit 1
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.zone(name)
|
|
35
|
+
raise InvalidZone, "No zoneinfo specified." unless name
|
|
36
|
+
raise InvalidZone, "Directory /usr/share/zoneinfo/ no found on this system..." unless Dir.exist? "/usr/share/zoneinfo/"
|
|
37
|
+
raise InvalidZone, "Zoneinfo #{name} is no found in /usr/share/zoneinfo/." unless File.exist? "/usr/share/zoneinfo/#{name}"
|
|
38
|
+
name
|
|
39
|
+
rescue InvalidZone => e
|
|
40
|
+
puts "#{e.class} => #{e}"
|
|
41
|
+
exit 1
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.keymap(name)
|
|
45
|
+
raise InvalidKeymap, "No keymap specified." unless name
|
|
46
|
+
key = []
|
|
47
|
+
|
|
48
|
+
if Dir.exist? '/usr/share/keymaps'
|
|
49
|
+
key = Dir.glob("/usr/share/keymaps/**/#{name}.map.gz")
|
|
50
|
+
elsif Dir.exist? '/usr/share/kbd/keymaps'
|
|
51
|
+
key = Dir.glob("/usr/share/kbd/keymaps/**/#{name}.map.gz")
|
|
52
|
+
else
|
|
53
|
+
raise InvalidKeymap, "No directory found for keymap."
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if key == []
|
|
57
|
+
raise InvalidKeymap, "Keymap #{name} no found."
|
|
58
|
+
end
|
|
59
|
+
name
|
|
60
|
+
rescue InvalidKeymap => e
|
|
61
|
+
puts "#{e.class} => #{e}"
|
|
62
|
+
exit 1
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/getch/helpers.rb
CHANGED
|
@@ -38,6 +38,11 @@ module Helpers
|
|
|
38
38
|
File.write file, '' if ! File.exist? file
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
def self.cp(src, dest)
|
|
42
|
+
raise "Src file #{src} no found" unless File.exist? src
|
|
43
|
+
FileUtils.cp(src, dest)
|
|
44
|
+
end
|
|
45
|
+
|
|
41
46
|
def self.grep?(file, regex)
|
|
42
47
|
is_found = false
|
|
43
48
|
return is_found if ! File.exist? file
|
|
@@ -55,4 +60,132 @@ module Helpers
|
|
|
55
60
|
raise "Error with #{cmd}"
|
|
56
61
|
end
|
|
57
62
|
end
|
|
63
|
+
|
|
64
|
+
def self.partuuid(dev)
|
|
65
|
+
`lsblk -o PARTUUID #{dev}`.match(/[\w]+-[\w]+-[\w]+-[\w]+-[\w]+/)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.uuid(dev)
|
|
69
|
+
Dir.glob("/dev/disk/by-uuid/*").each { |f|
|
|
70
|
+
if File.readlink(f).match(/#{dev}/)
|
|
71
|
+
return f.delete_prefix("/dev/disk/by-uuid/")
|
|
72
|
+
end
|
|
73
|
+
}
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Used with ZFS for the pool name
|
|
77
|
+
def self.pool_id(dev)
|
|
78
|
+
if dev.match(/[0-9]/)
|
|
79
|
+
sleep 1
|
|
80
|
+
`lsblk -o PARTUUID #{dev}`.delete("\n").delete("PARTUUID").match(/[\w]{5}/)
|
|
81
|
+
else
|
|
82
|
+
puts "Please, enter a pool name"
|
|
83
|
+
while true
|
|
84
|
+
print "\n> "
|
|
85
|
+
value = gets
|
|
86
|
+
if value.match(/[a-z]{4,20}/)
|
|
87
|
+
return value
|
|
88
|
+
end
|
|
89
|
+
puts "Bad name, you enter: #{value}"
|
|
90
|
+
puts "Valid pool name use character only, between 4-20."
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
module Void
|
|
96
|
+
def command(args)
|
|
97
|
+
print " => Exec: #{args}..."
|
|
98
|
+
cmd = "chroot #{Getch::MOUNTPOINT} /bin/bash -c \"#{args}\""
|
|
99
|
+
_, stderr, status = Open3.capture3(cmd)
|
|
100
|
+
if status.success? then
|
|
101
|
+
puts "\s[OK]"
|
|
102
|
+
return
|
|
103
|
+
end
|
|
104
|
+
raise "\n[-] Fail cmd #{args} - #{stderr}."
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def command_output(args)
|
|
108
|
+
print " => Exec: #{args}..."
|
|
109
|
+
cmd = "chroot #{Getch::MOUNTPOINT} /bin/bash -c \"#{args}\""
|
|
110
|
+
Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
|
|
111
|
+
puts
|
|
112
|
+
while line = stdout_err.gets
|
|
113
|
+
puts line
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
exit_status = wait_thr.value
|
|
117
|
+
unless exit_status.success?
|
|
118
|
+
raise "\n[-] Fail cmd #{args} - #{stdout_err}."
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def add_line(file, line)
|
|
124
|
+
raise "No file #{file} found !" unless File.exist? file
|
|
125
|
+
File.write(file, "#{line}\n", mode: 'a')
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def search(file, text)
|
|
129
|
+
File.open(file).each { |line|
|
|
130
|
+
return true if line.match(/#{text}/)
|
|
131
|
+
}
|
|
132
|
+
return false
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Used only when need password
|
|
136
|
+
def chroot(cmd)
|
|
137
|
+
if !system("chroot", Getch::MOUNTPOINT, "/bin/bash", "-c", cmd)
|
|
138
|
+
raise "[-] Error with: #{cmd}"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def s_uuid(dev)
|
|
143
|
+
device = dev.delete_prefix("/dev/")
|
|
144
|
+
Dir.glob("/dev/disk/by-partuuid/*").each { |f|
|
|
145
|
+
link = File.readlink(f)
|
|
146
|
+
return f.delete_prefix("/dev/disk/by-partuuid/") if link.match(/#{device}$/)
|
|
147
|
+
}
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def line_fstab(dev, rest)
|
|
151
|
+
conf = "#{Getch::MOUNTPOINT}/etc/fstab"
|
|
152
|
+
device = s_uuid(dev)
|
|
153
|
+
raise "No partuuid for #{dev} #{device}" if !device
|
|
154
|
+
raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array
|
|
155
|
+
add_line(conf, "PARTUUID=#{device} #{rest}")
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def grub_cmdline(*args)
|
|
159
|
+
conf = "#{Getch::MOUNTPOINT}/etc/default/grub"
|
|
160
|
+
list = args.join(" ")
|
|
161
|
+
secs = "GRUB_CMDLINE_LINUX=\"#{list} init_on_alloc=1 init_on_free=1"
|
|
162
|
+
secs += " slab_nomerge pti=on slub_debug=ZF vsyscall=none\""
|
|
163
|
+
raise "No default/grub found" unless File.exist? conf
|
|
164
|
+
unless search(conf, "GRUB_CMDLINE_LINUX=")
|
|
165
|
+
File.write(conf, "#{secs}\n", mode: 'a')
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
module Cryptsetup
|
|
171
|
+
def encrypt(dev)
|
|
172
|
+
raise "No device #{dev}" unless File.exist? dev
|
|
173
|
+
puts " => Encrypting device #{dev}..."
|
|
174
|
+
if Helpers::efi? && Getch::OPTIONS[:os] == 'gentoo'
|
|
175
|
+
Helpers::sys("cryptsetup luksFormat --type luks #{dev}")
|
|
176
|
+
else
|
|
177
|
+
Helpers::sys("cryptsetup luksFormat --type luks1 #{dev}")
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def open_crypt(dev, map_name)
|
|
182
|
+
raise "No device #{dev}" unless File.exist? dev
|
|
183
|
+
puts " => Opening encrypted device #{dev}..."
|
|
184
|
+
if Helpers::efi? && Getch::OPTIONS[:os] == 'gentoo'
|
|
185
|
+
Helpers::sys("cryptsetup open --type luks #{dev} #{map_name}")
|
|
186
|
+
else
|
|
187
|
+
Helpers::sys("cryptsetup open --type luks1 #{dev} #{map_name}")
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
58
191
|
end
|