getch 0.1.6 → 0.1.9
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 +17 -26
- data/assets/system.conf +38 -0
- data/lib/cmdline.rb +128 -0
- data/lib/getch/command.rb +31 -21
- data/lib/getch/config/gentoo.rb +22 -23
- data/lib/getch/config/void.rb +8 -10
- data/lib/getch/config.rb +5 -2
- data/lib/getch/filesystem/clean.rb +15 -15
- data/lib/getch/filesystem/device.rb +3 -1
- data/lib/getch/filesystem/ext4/config.rb +8 -4
- data/lib/getch/filesystem/ext4/deps.rb +3 -1
- data/lib/getch/filesystem/ext4/device.rb +2 -3
- data/lib/getch/filesystem/ext4/encrypt/config.rb +12 -7
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +4 -2
- data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
- data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -1
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -2
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +21 -21
- data/lib/getch/filesystem/ext4/encrypt/void.rb +22 -21
- data/lib/getch/filesystem/ext4/encrypt.rb +2 -0
- data/lib/getch/filesystem/ext4/format.rb +3 -0
- data/lib/getch/filesystem/ext4/mount.rb +3 -0
- data/lib/getch/filesystem/ext4/partition.rb +9 -6
- data/lib/getch/filesystem/ext4/void.rb +8 -7
- data/lib/getch/filesystem/ext4.rb +2 -0
- data/lib/getch/filesystem/lvm/config.rb +7 -22
- data/lib/getch/filesystem/lvm/deps.rb +6 -4
- data/lib/getch/filesystem/lvm/device.rb +2 -0
- data/lib/getch/filesystem/lvm/encrypt/config.rb +12 -9
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +6 -3
- data/lib/getch/filesystem/lvm/encrypt/device.rb +4 -2
- data/lib/getch/filesystem/lvm/encrypt/format.rb +4 -0
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +3 -0
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +7 -7
- data/lib/getch/filesystem/lvm/encrypt/void.rb +20 -19
- data/lib/getch/filesystem/lvm/encrypt.rb +2 -0
- data/lib/getch/filesystem/lvm/format.rb +3 -0
- data/lib/getch/filesystem/lvm/mount.rb +3 -0
- data/lib/getch/filesystem/lvm/partition.rb +8 -5
- data/lib/getch/filesystem/lvm/void.rb +7 -6
- data/lib/getch/filesystem/lvm.rb +2 -0
- data/lib/getch/filesystem/mount.rb +19 -12
- data/lib/getch/filesystem/partition.rb +16 -8
- data/lib/getch/filesystem/zfs/config.rb +9 -23
- data/lib/getch/filesystem/zfs/deps.rb +22 -57
- data/lib/getch/filesystem/zfs/device.rb +3 -1
- data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -26
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +25 -60
- data/lib/getch/filesystem/zfs/encrypt/device.rb +3 -1
- data/lib/getch/filesystem/zfs/encrypt/format.rb +12 -8
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +13 -8
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +18 -15
- data/lib/getch/filesystem/zfs/encrypt/void.rb +23 -22
- data/lib/getch/filesystem/zfs/encrypt.rb +2 -0
- data/lib/getch/filesystem/zfs/format.rb +9 -5
- data/lib/getch/filesystem/zfs/mount.rb +9 -7
- data/lib/getch/filesystem/zfs/partition.rb +15 -12
- data/lib/getch/filesystem/zfs/void.rb +20 -20
- data/lib/getch/filesystem/zfs.rb +2 -0
- data/lib/getch/filesystem.rb +2 -0
- data/lib/getch/gentoo/boot.rb +21 -72
- data/lib/getch/gentoo/bootloader.rb +68 -0
- data/lib/getch/gentoo/chroot.rb +26 -33
- data/lib/getch/gentoo/config.rb +30 -26
- data/lib/getch/gentoo/sources.rb +55 -66
- data/lib/getch/gentoo/stage.rb +12 -12
- data/lib/getch/gentoo/use.rb +3 -7
- data/lib/getch/gentoo/use_flag.rb +77 -51
- data/lib/getch/gentoo.rb +22 -8
- data/lib/getch/guard.rb +50 -43
- data/lib/getch/helpers.rb +155 -143
- data/lib/getch/log.rb +7 -5
- data/lib/getch/options.rb +16 -14
- data/lib/getch/states.rb +10 -3
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void/boot.rb +18 -14
- data/lib/getch/void/chroot.rb +20 -19
- data/lib/getch/void/config.rb +20 -17
- data/lib/getch/void/stage.rb +13 -14
- data/lib/getch/void.rb +7 -1
- data/lib/getch.rb +13 -5
- data.tar.gz.sig +0 -0
- metadata +6 -5
- metadata.gz.sig +0 -0
- data/lib/getch/filesystem/.mount.rb.swp +0 -0
- data/lib/getch/filesystem/zfs/encrypt/.mount.rb.swp +0 -0
data/lib/getch/helpers.rb
CHANGED
|
@@ -1,190 +1,202 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'open-uri'
|
|
2
4
|
require 'open3'
|
|
3
5
|
require 'fileutils'
|
|
4
6
|
|
|
5
|
-
module
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
module Getch
|
|
8
|
+
module Helpers
|
|
9
|
+
def self.efi?
|
|
10
|
+
Dir.exist? '/sys/firmware/efi/efivars'
|
|
11
|
+
end
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
f.write(l.read)
|
|
13
|
+
def self.get_file_online(url, dest)
|
|
14
|
+
URI.open(url) do |l|
|
|
15
|
+
File.open(dest, "wb") { |f| f.write(l.read) }
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
|
-
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
def self.exec_or_die(cmd)
|
|
20
|
+
_, stderr, status = Open3.capture3(cmd)
|
|
21
|
+
unless status.success?
|
|
22
|
+
raise "Problem running #{cmd}, stderr was:\n#{stderr}"
|
|
23
|
+
end
|
|
22
24
|
end
|
|
23
|
-
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def self.add_file(path, content = '')
|
|
30
|
-
File.write path, content if ! File.exist? path
|
|
31
|
-
end
|
|
26
|
+
def self.create_dir(path, perm = 0755)
|
|
27
|
+
FileUtils.mkdir_p path, mode: perm unless Dir.exist? path
|
|
28
|
+
end
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
def self.add_file(path, content = '')
|
|
31
|
+
File.write path, content unless File.exist? path
|
|
32
|
+
end
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
def self.mkdir(dir)
|
|
35
|
+
FileUtils.mkdir_p dir unless Dir.exist? dir
|
|
36
|
+
end
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
end
|
|
38
|
+
def self.touch(file)
|
|
39
|
+
File.write file, '' unless File.exist? file
|
|
40
|
+
end
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return is_found if ! File.exist? file
|
|
49
|
-
File.open(file) do |f|
|
|
50
|
-
f.each do |line|
|
|
51
|
-
is_found = true if line.match(regex)
|
|
52
|
-
end
|
|
42
|
+
def self.echo(src, content = '')
|
|
43
|
+
File.write(src, "#{content}\n", mode: 'w')
|
|
53
44
|
end
|
|
54
|
-
is_found
|
|
55
|
-
end
|
|
56
45
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
def self.echo_a(src, content = '')
|
|
47
|
+
raise "No file #{src} found !" unless File.exist? src
|
|
48
|
+
|
|
49
|
+
File.write(src, "#{content}\n", mode: 'a') unless self.grep?(src, content)
|
|
61
50
|
end
|
|
62
|
-
end
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
end
|
|
52
|
+
def self.cp(src, dest)
|
|
53
|
+
raise "Src file #{src} no found" unless File.exist? src
|
|
67
54
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
FileUtils.cp(src, dest)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.grep?(file, regex)
|
|
59
|
+
is_found = false
|
|
60
|
+
return is_found unless File.exist? file
|
|
61
|
+
File.open(file) do |f|
|
|
62
|
+
f.each { |l| is_found = true if l.match(regex) }
|
|
72
63
|
end
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
is_found
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.sys(cmd)
|
|
68
|
+
system(cmd)
|
|
69
|
+
raise "Error with #{cmd}" unless $?.success?
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.partuuid(dev)
|
|
73
|
+
`lsblk -o PARTUUID #{dev}`.match(/\w+-\w+-\w+-\w+-\w+/)
|
|
74
|
+
end
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
76
|
+
def self.uuid(dev)
|
|
77
|
+
Dir.glob('/dev/disk/by-uuid/*').each do |f|
|
|
78
|
+
if File.readlink(f).match(/#{dev}/)
|
|
79
|
+
return f.delete_prefix('/dev/disk/by-uuid/')
|
|
88
80
|
end
|
|
89
|
-
puts "Bad name, you enter: #{value}"
|
|
90
|
-
puts "Valid pool name use character only, between 4-20."
|
|
91
81
|
end
|
|
92
82
|
end
|
|
93
|
-
end
|
|
94
83
|
|
|
95
|
-
|
|
96
|
-
def
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
puts
|
|
102
|
-
|
|
84
|
+
# Used with ZFS for the pool name
|
|
85
|
+
def self.pool_id(dev)
|
|
86
|
+
if dev.match(/[0-9]/)
|
|
87
|
+
sleep 1
|
|
88
|
+
`lsblk -o PARTUUID #{dev}`.delete("\n").delete('PARTUUID').match(/\w{5}/)
|
|
89
|
+
else
|
|
90
|
+
puts 'Please, enter a pool name'
|
|
91
|
+
while true
|
|
92
|
+
print "\n> "
|
|
93
|
+
value = gets
|
|
94
|
+
if value.match(/[a-z]{4,20}/)
|
|
95
|
+
return value
|
|
96
|
+
end
|
|
97
|
+
puts "Bad name, you enter: #{value}"
|
|
98
|
+
puts 'Valid pool name use character only, between 4-20.'
|
|
99
|
+
end
|
|
103
100
|
end
|
|
104
|
-
raise "\n[-] Fail cmd #{args} - #{stderr}."
|
|
105
101
|
end
|
|
106
102
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
puts
|
|
103
|
+
module Void
|
|
104
|
+
def command(args)
|
|
105
|
+
print " => Exec: #{args}..."
|
|
106
|
+
cmd = "chroot #{Getch::MOUNTPOINT} /bin/bash -c \"#{args}\""
|
|
107
|
+
_, stderr, status = Open3.capture3(cmd)
|
|
108
|
+
if status.success?
|
|
109
|
+
puts "\s[OK]"
|
|
110
|
+
return
|
|
114
111
|
end
|
|
112
|
+
raise "\n[-] Fail cmd #{args} - #{stderr}."
|
|
113
|
+
end
|
|
115
114
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
def command_output(args)
|
|
116
|
+
print " => Exec: #{args}..."
|
|
117
|
+
cmd = "chroot #{Getch::MOUNTPOINT} /bin/bash -c \"#{args}\""
|
|
118
|
+
Open3.popen2e(cmd) do |_, stdout_err, wait_thr|
|
|
119
|
+
puts
|
|
120
|
+
stdout_err.each { |l| puts l }
|
|
121
|
+
|
|
122
|
+
exit_status = wait_thr.value
|
|
123
|
+
unless exit_status.success?
|
|
124
|
+
raise "\n[-] Fail cmd #{args} - #{stdout_err}."
|
|
125
|
+
end
|
|
119
126
|
end
|
|
120
127
|
end
|
|
121
|
-
end
|
|
122
128
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
File.write(file, "#{line}\n", mode: 'a')
|
|
126
|
-
end
|
|
129
|
+
def add_line(file, line)
|
|
130
|
+
raise "No file #{file} found !" unless File.exist? file
|
|
127
131
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return true if line.match(/#{text}/)
|
|
131
|
-
}
|
|
132
|
-
return false
|
|
133
|
-
end
|
|
132
|
+
File.write(file, "#{line}\n", mode: 'a')
|
|
133
|
+
end
|
|
134
134
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
def search(file, text)
|
|
136
|
+
File.open(file).each do |line|
|
|
137
|
+
return true if line.match(/#{text}/)
|
|
138
|
+
end
|
|
139
|
+
false
|
|
139
140
|
end
|
|
140
|
-
end
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
end
|
|
142
|
+
# Used only when need password
|
|
143
|
+
def chroot(cmd)
|
|
144
|
+
unless system('chroot', Getch::MOUNTPOINT, '/bin/bash', '-c', cmd)
|
|
145
|
+
raise "[-] Error with: #{cmd}"
|
|
146
|
+
end
|
|
147
|
+
end
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
149
|
+
def s_uuid(dev)
|
|
150
|
+
device = dev.delete_prefix('/dev/')
|
|
151
|
+
Dir.glob('/dev/disk/by-partuuid/*').each do |f|
|
|
152
|
+
link = File.readlink(f)
|
|
153
|
+
return f.delete_prefix('/dev/disk/by-partuuid/') if link.match(/#{device}$/)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
157
156
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
File.write(conf, "#{secs}\n", mode: 'a')
|
|
157
|
+
def line_fstab(dev, rest)
|
|
158
|
+
conf = "#{Getch::MOUNTPOINT}/etc/fstab"
|
|
159
|
+
device = s_uuid(dev)
|
|
160
|
+
raise "No partuuid for #{dev} #{device}" unless device
|
|
161
|
+
raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array
|
|
162
|
+
|
|
163
|
+
add_line(conf, "PARTUUID=#{device} #{rest}")
|
|
166
164
|
end
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
165
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
166
|
+
def grub_cmdline(*args)
|
|
167
|
+
conf = "#{Getch::MOUNTPOINT}/etc/default/grub"
|
|
168
|
+
list = args.join(' ')
|
|
169
|
+
secs = "GRUB_CMDLINE_LINUX=\"#{list} init_on_alloc=1 init_on_free=1"
|
|
170
|
+
secs += ' slab_nomerge pti=on slub_debug=ZF vsyscall=none"'
|
|
171
|
+
raise 'No default/grub found' unless File.exist? conf
|
|
172
|
+
|
|
173
|
+
unless search(conf, 'GRUB_CMDLINE_LINUX=')
|
|
174
|
+
File.write(conf, "#{secs}\n", mode: 'a')
|
|
175
|
+
end
|
|
178
176
|
end
|
|
179
177
|
end
|
|
180
178
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
179
|
+
module Cryptsetup
|
|
180
|
+
def encrypt(dev)
|
|
181
|
+
raise "No device #{dev}" unless File.exist? dev
|
|
182
|
+
|
|
183
|
+
puts " => Encrypting device #{dev}..."
|
|
184
|
+
if Helpers.efi? && Getch::OPTIONS[:os] == 'gentoo'
|
|
185
|
+
Helpers.sys("cryptsetup luksFormat --type luks #{dev}")
|
|
186
|
+
else
|
|
187
|
+
Helpers.sys("cryptsetup luksFormat --type luks1 #{dev}")
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def open_crypt(dev, map_name)
|
|
192
|
+
raise "No device #{dev}" unless File.exist? dev
|
|
193
|
+
|
|
194
|
+
puts " => Opening encrypted device #{dev}..."
|
|
195
|
+
if Helpers.efi? && Getch::OPTIONS[:os] == 'gentoo'
|
|
196
|
+
Helpers.sys("cryptsetup open --type luks #{dev} #{map_name}")
|
|
197
|
+
else
|
|
198
|
+
Helpers.sys("cryptsetup open --type luks1 #{dev} #{map_name}")
|
|
199
|
+
end
|
|
188
200
|
end
|
|
189
201
|
end
|
|
190
202
|
end
|
data/lib/getch/log.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'logger'
|
|
2
4
|
|
|
3
5
|
module Getch
|
|
@@ -33,21 +35,21 @@ module Getch
|
|
|
33
35
|
private
|
|
34
36
|
|
|
35
37
|
def check_file
|
|
36
|
-
puts "Creating log at #{@log_file}"
|
|
38
|
+
puts "Creating log at #{@log_file}" unless File.exist? @log_file
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def init_log
|
|
40
|
-
@logger = Logger.new(
|
|
42
|
+
@logger = Logger.new($stdout)
|
|
41
43
|
@logger.level = @verbose ? Logger::DEBUG : Logger::INFO
|
|
42
|
-
@logger.formatter = proc { |severity,
|
|
43
|
-
"#{severity}, #{msg}\n"
|
|
44
|
+
@logger.formatter = proc { |severity, _, _, msg|
|
|
45
|
+
"#{severity}, #{msg}\n"
|
|
44
46
|
}
|
|
45
47
|
end
|
|
46
48
|
|
|
47
49
|
def init_log_text
|
|
48
50
|
@logger_text = Logger.new(@log_file, 1)
|
|
49
51
|
@logger_text.level = Logger::DEBUG
|
|
50
|
-
@logger_text.formatter = proc { |severity, datetime,
|
|
52
|
+
@logger_text.formatter = proc { |severity, datetime, _, msg|
|
|
51
53
|
"#{severity}, #{datetime}, #{msg}\n"
|
|
52
54
|
}
|
|
53
55
|
end
|
data/lib/getch/options.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'optparse'
|
|
2
4
|
|
|
3
5
|
module Getch
|
|
@@ -12,55 +14,55 @@ module Getch
|
|
|
12
14
|
OptionParser.new do |opts|
|
|
13
15
|
opts.version = VERSION
|
|
14
16
|
|
|
15
|
-
opts.on(
|
|
17
|
+
opts.on('-l', '--language LANG', 'Default is en_US') do |lang|
|
|
16
18
|
OPTIONS[:language] = lang
|
|
17
19
|
end
|
|
18
20
|
|
|
19
|
-
opts.on(
|
|
21
|
+
opts.on('-z', '--zoneinfo ZONE', 'Default is US/Eastern') do |zone|
|
|
20
22
|
OPTIONS[:zoneinfo] = Getch::Guard.zone(zone)
|
|
21
23
|
end
|
|
22
24
|
|
|
23
|
-
opts.on(
|
|
25
|
+
opts.on('-k', '--keymap KEY', 'Default is us') do |key|
|
|
24
26
|
OPTIONS[:keymap] = Getch::Guard.keymap(key)
|
|
25
27
|
end
|
|
26
28
|
|
|
27
|
-
opts.on(
|
|
29
|
+
opts.on('-d', '--disk DISK', 'Root Disk where install the system (sda,sdb)') do |disk|
|
|
28
30
|
OPTIONS[:disk] = Getch::Guard.disk(disk)
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
opts.on(
|
|
33
|
+
opts.on('-f', '--format FS', 'Can be ext4, lvm or zfs. Default use ext4') do |fs|
|
|
32
34
|
OPTIONS[:fs] = Getch::Guard.format(fs)
|
|
33
35
|
end
|
|
34
36
|
|
|
35
|
-
opts.on(
|
|
37
|
+
opts.on('-u', '--username USERNAME', 'Create a new user /home/USERNAME with password.') do |user|
|
|
36
38
|
OPTIONS[:username] = user
|
|
37
39
|
end
|
|
38
40
|
|
|
39
|
-
opts.on(
|
|
41
|
+
opts.on('-o', '--os NAME', /gentoo|void/, 'Install distro NAME, can be gentoo or void.') do |name|
|
|
40
42
|
OPTIONS[:os] = name
|
|
41
43
|
end
|
|
42
44
|
|
|
43
|
-
opts.on(
|
|
45
|
+
opts.on('--separate-boot DISK', 'Use a different DISK for the /boot or /efi partition.') do |boot|
|
|
44
46
|
OPTIONS[:boot_disk] = Getch::Guard.disk(boot)
|
|
45
47
|
end
|
|
46
48
|
|
|
47
|
-
opts.on(
|
|
49
|
+
opts.on('--separate-cache DISK', 'Use a different DISK for the swap partition, add ZIL/L2ARC for ZFS when set.') do |swap|
|
|
48
50
|
OPTIONS[:cache_disk] = Getch::Guard.disk(swap)
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
opts.on(
|
|
53
|
+
opts.on('--separate-home DISK', 'Use a different DISK for the /home partition.') do |home|
|
|
52
54
|
OPTIONS[:home_disk] = Getch::Guard.disk(home)
|
|
53
55
|
end
|
|
54
56
|
|
|
55
|
-
opts.on(
|
|
57
|
+
opts.on('--encrypt', 'Encrypt your system, use LUKS or native encryption for ZFS.') do
|
|
56
58
|
OPTIONS[:encrypt] = true
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
opts.on(
|
|
61
|
+
opts.on('--verbose', 'Write more messages to the standard output.') do
|
|
60
62
|
OPTIONS[:verbose] = true
|
|
61
63
|
end
|
|
62
64
|
|
|
63
|
-
opts.on(
|
|
65
|
+
opts.on('-h', '--help', 'Display this') do
|
|
64
66
|
puts opts
|
|
65
67
|
exit
|
|
66
68
|
end
|
|
@@ -68,7 +70,7 @@ module Getch
|
|
|
68
70
|
begin
|
|
69
71
|
opts.parse!(argv)
|
|
70
72
|
rescue OptionParser::ParseError => e
|
|
71
|
-
|
|
73
|
+
warn e.message, "\n", opts
|
|
72
74
|
exit 1
|
|
73
75
|
end
|
|
74
76
|
end
|
data/lib/getch/states.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'yaml'
|
|
2
4
|
|
|
3
5
|
module Getch
|
|
@@ -37,6 +39,11 @@ module Getch
|
|
|
37
39
|
save
|
|
38
40
|
end
|
|
39
41
|
|
|
42
|
+
def bootloader
|
|
43
|
+
STATES[:gentoo_bootloader] = true
|
|
44
|
+
save
|
|
45
|
+
end
|
|
46
|
+
|
|
40
47
|
def kernel
|
|
41
48
|
STATES[:gentoo_kernel] = true
|
|
42
49
|
save
|
|
@@ -45,16 +52,16 @@ module Getch
|
|
|
45
52
|
private
|
|
46
53
|
|
|
47
54
|
def save
|
|
48
|
-
File.open(@file, 'w') { |f| YAML
|
|
55
|
+
File.open(@file, 'w') { |f| YAML.dump(STATES, f) }
|
|
49
56
|
end
|
|
50
57
|
|
|
51
|
-
def load_state
|
|
58
|
+
def load_state
|
|
52
59
|
if File.exist? @file
|
|
53
60
|
state_file = YAML.load_file(@file)
|
|
54
61
|
STATES.merge!(state_file)
|
|
55
62
|
else
|
|
56
63
|
save
|
|
57
|
-
|
|
64
|
+
warn 'Initialize states'
|
|
58
65
|
end
|
|
59
66
|
end
|
|
60
67
|
end
|
data/lib/getch/version.rb
CHANGED
data/lib/getch/void/boot.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'fileutils'
|
|
2
|
-
require_relative '../helpers'
|
|
3
4
|
|
|
4
5
|
module Getch
|
|
5
6
|
module Void
|
|
@@ -7,7 +8,7 @@ module Getch
|
|
|
7
8
|
include Helpers::Void
|
|
8
9
|
|
|
9
10
|
def initialize
|
|
10
|
-
@efi = Helpers
|
|
11
|
+
@efi = Helpers.efi?
|
|
11
12
|
@class_fs = Getch::select_fs
|
|
12
13
|
@fs = @class_fs::Void.new
|
|
13
14
|
@user = OPTIONS[:username]
|
|
@@ -15,10 +16,11 @@ module Getch
|
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def new_user
|
|
18
|
-
puts
|
|
19
|
-
chroot
|
|
19
|
+
puts ' => Add a password for root.'
|
|
20
|
+
chroot 'passwd'
|
|
20
21
|
puts
|
|
21
22
|
return unless @user
|
|
23
|
+
|
|
22
24
|
print " => Creating a new user #{@user}..."
|
|
23
25
|
puts "\s[OK]"
|
|
24
26
|
command "useradd -m -G users,wheel,audio,video #{@user}"
|
|
@@ -28,7 +30,7 @@ module Getch
|
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
def fstab
|
|
31
|
-
print
|
|
33
|
+
print ' => Configuring fstab...'
|
|
32
34
|
@fs.fstab
|
|
33
35
|
puts "\s[OK]"
|
|
34
36
|
@fs.crypttab if @class_fs::Void.method_defined? :crypttab
|
|
@@ -37,7 +39,7 @@ module Getch
|
|
|
37
39
|
# Test dracut in chroot (version in /lib/modules/5.1.7-1):
|
|
38
40
|
# dracut -H -f --kver 5.1.7-1
|
|
39
41
|
def dracut
|
|
40
|
-
print
|
|
42
|
+
print ' => Configuring Dracut...'
|
|
41
43
|
@fs.config_dracut
|
|
42
44
|
@fs.kernel_cmdline_dracut
|
|
43
45
|
puts "\s[OK]"
|
|
@@ -45,26 +47,28 @@ module Getch
|
|
|
45
47
|
|
|
46
48
|
def grub
|
|
47
49
|
disk = OPTIONS[:boot_disk] ||= OPTIONS[:disk]
|
|
50
|
+
# https://wiki.archlinux.org/title/Install_Arch_Linux_on_ZFS
|
|
51
|
+
prefix = OPTIONS[:fs] == 'zfs' ? 'ZPOOL_VDEV_NAME_PATH=1' : ''
|
|
48
52
|
print " => Installing Grub on #{disk}..."
|
|
49
53
|
if @efi
|
|
50
|
-
command_output
|
|
54
|
+
command_output 'xbps-install -y grub-x86_64-efi'
|
|
51
55
|
@fs.config_grub if @class_fs::Void.method_defined? :config_grub
|
|
52
|
-
command_output "grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=\"Void\""
|
|
56
|
+
command_output "#{prefix} grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=\"Void\""
|
|
53
57
|
else
|
|
54
|
-
command_output
|
|
58
|
+
command_output 'xbps-install -y grub'
|
|
55
59
|
@fs.config_grub if @class_fs::Void.method_defined? :config_grub
|
|
56
|
-
command_output "grub-install /dev/#{disk}"
|
|
60
|
+
command_output "#{prefix} grub-install /dev/#{disk}"
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
63
|
|
|
60
64
|
def initramfs
|
|
61
|
-
puts
|
|
62
|
-
command_output
|
|
65
|
+
puts ' => Generating an initramfs...'
|
|
66
|
+
command_output 'xbps-reconfigure -fa' # this command also start grub-mkconfig
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
def finish
|
|
66
70
|
puts
|
|
67
|
-
puts
|
|
71
|
+
puts '[*!*] Install finished [*!*]'
|
|
68
72
|
puts
|
|
69
73
|
@fs.finish
|
|
70
74
|
puts
|
|
@@ -73,7 +77,7 @@ module Getch
|
|
|
73
77
|
private
|
|
74
78
|
|
|
75
79
|
def chroot(cmd)
|
|
76
|
-
system(
|
|
80
|
+
system('chroot', MOUNTPOINT, '/bin/bash', '-c', cmd)
|
|
77
81
|
end
|
|
78
82
|
end
|
|
79
83
|
end
|