getch 0.1.2 → 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 +66 -32
- data/assets/network-stack.conf +63 -0
- data/assets/system.conf +38 -0
- data/bin/getch +12 -4
- data/lib/cmdline.rb +128 -0
- data/lib/getch/command.rb +32 -22
- data/lib/getch/config/gentoo.rb +58 -0
- data/lib/getch/config/void.rb +47 -0
- data/lib/getch/config.rb +45 -0
- data/lib/getch/filesystem/clean.rb +22 -15
- data/lib/getch/filesystem/device.rb +8 -6
- 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 +15 -11
- data/lib/getch/filesystem/ext4/encrypt/deps.rb +5 -10
- data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
- data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -2
- data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -3
- data/lib/getch/filesystem/ext4/encrypt/partition.rb +29 -35
- data/lib/getch/filesystem/ext4/encrypt/void.rb +101 -0
- data/lib/getch/filesystem/ext4/encrypt.rb +3 -0
- data/lib/getch/filesystem/ext4/format.rb +4 -1
- data/lib/getch/filesystem/ext4/mount.rb +3 -0
- data/lib/getch/filesystem/ext4/partition.rb +11 -8
- data/lib/getch/filesystem/ext4/void.rb +44 -0
- data/lib/getch/filesystem/ext4.rb +3 -0
- data/lib/getch/filesystem/lvm/config.rb +10 -29
- data/lib/getch/filesystem/lvm/deps.rb +7 -11
- data/lib/getch/filesystem/lvm/device.rb +5 -3
- data/lib/getch/filesystem/lvm/encrypt/config.rb +17 -17
- data/lib/getch/filesystem/lvm/encrypt/deps.rb +8 -12
- data/lib/getch/filesystem/lvm/encrypt/device.rb +7 -5
- data/lib/getch/filesystem/lvm/encrypt/format.rb +5 -2
- data/lib/getch/filesystem/lvm/encrypt/mount.rb +4 -2
- data/lib/getch/filesystem/lvm/encrypt/partition.rb +17 -13
- data/lib/getch/filesystem/lvm/encrypt/void.rb +101 -0
- data/lib/getch/filesystem/lvm/encrypt.rb +3 -0
- data/lib/getch/filesystem/lvm/format.rb +4 -1
- data/lib/getch/filesystem/lvm/mount.rb +3 -0
- data/lib/getch/filesystem/lvm/partition.rb +10 -7
- data/lib/getch/filesystem/lvm/void.rb +46 -0
- data/lib/getch/filesystem/lvm.rb +3 -0
- data/lib/getch/filesystem/mount.rb +19 -12
- data/lib/getch/filesystem/partition.rb +19 -11
- data/lib/getch/filesystem/zfs/config.rb +10 -24
- data/lib/getch/filesystem/zfs/deps.rb +28 -58
- data/lib/getch/filesystem/zfs/device.rb +9 -1
- data/lib/getch/filesystem/zfs/encrypt/config.rb +12 -28
- data/lib/getch/filesystem/zfs/encrypt/deps.rb +29 -60
- data/lib/getch/filesystem/zfs/encrypt/device.rb +9 -1
- data/lib/getch/filesystem/zfs/encrypt/format.rb +24 -22
- data/lib/getch/filesystem/zfs/encrypt/mount.rb +15 -14
- data/lib/getch/filesystem/zfs/encrypt/partition.rb +24 -18
- data/lib/getch/filesystem/zfs/encrypt/void.rb +97 -0
- data/lib/getch/filesystem/zfs/encrypt.rb +3 -0
- data/lib/getch/filesystem/zfs/format.rb +21 -18
- data/lib/getch/filesystem/zfs/mount.rb +12 -13
- data/lib/getch/filesystem/zfs/partition.rb +20 -15
- data/lib/getch/filesystem/zfs/void.rb +81 -0
- data/lib/getch/filesystem/zfs.rb +3 -0
- data/lib/getch/filesystem.rb +2 -0
- data/lib/getch/gentoo/boot.rb +29 -67
- data/lib/getch/gentoo/bootloader.rb +68 -0
- data/lib/getch/gentoo/chroot.rb +26 -29
- data/lib/getch/gentoo/config.rb +69 -31
- data/lib/getch/gentoo/sources.rb +73 -38
- data/lib/getch/gentoo/stage.rb +12 -13
- data/lib/getch/gentoo/use.rb +39 -0
- data/lib/getch/gentoo/use_flag.rb +89 -0
- data/lib/getch/gentoo.rb +39 -21
- data/lib/getch/guard.rb +71 -0
- data/lib/getch/helpers.rb +180 -48
- data/lib/getch/log.rb +10 -7
- data/lib/getch/options.rb +50 -41
- data/lib/getch/states.rb +10 -3
- data/lib/getch/version.rb +1 -1
- data/lib/getch/void/boot.rb +84 -0
- data/lib/getch/void/chroot.rb +56 -0
- data/lib/getch/void/config.rb +90 -0
- data/lib/getch/void/stage.rb +69 -0
- data/lib/getch/void.rb +65 -0
- data/lib/getch.rb +125 -74
- data.tar.gz.sig +0 -0
- metadata +28 -10
- metadata.gz.sig +0 -0
- data/.gitignore +0 -2
- data/CHANGELOG.md +0 -80
- data/Rakefile +0 -21
- data/bin/setup.sh +0 -90
- data/getch.gemspec +0 -25
data/lib/getch/helpers.rb
CHANGED
|
@@ -1,71 +1,203 @@
|
|
|
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
|
-
|
|
26
|
+
def self.create_dir(path, perm = 0755)
|
|
27
|
+
FileUtils.mkdir_p path, mode: perm unless Dir.exist? path
|
|
28
|
+
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
def self.add_file(path, content = '')
|
|
31
|
+
File.write path, content unless File.exist? path
|
|
32
|
+
end
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
def self.mkdir(dir)
|
|
35
|
+
FileUtils.mkdir_p dir unless Dir.exist? dir
|
|
36
|
+
end
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
def self.touch(file)
|
|
39
|
+
File.write file, '' unless File.exist? file
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.echo(src, content = '')
|
|
43
|
+
File.write(src, "#{content}\n", mode: 'w')
|
|
44
|
+
end
|
|
45
|
+
|
|
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)
|
|
50
|
+
end
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
def self.cp(src, dest)
|
|
53
|
+
raise "Src file #{src} no found" unless File.exist? src
|
|
54
|
+
|
|
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) }
|
|
47
63
|
end
|
|
64
|
+
is_found
|
|
48
65
|
end
|
|
49
|
-
is_found
|
|
50
|
-
end
|
|
51
66
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
raise "Error with #{cmd}"
|
|
67
|
+
def self.sys(cmd)
|
|
68
|
+
system(cmd)
|
|
69
|
+
raise "Error with #{cmd}" unless $?.success?
|
|
56
70
|
end
|
|
57
|
-
end
|
|
58
71
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
def self.partuuid(dev)
|
|
73
|
+
`lsblk -o PARTUUID #{dev}`.match(/\w+-\w+-\w+-\w+-\w+/)
|
|
74
|
+
end
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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/')
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
66
83
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
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
|
|
111
|
+
end
|
|
112
|
+
raise "\n[-] Fail cmd #{args} - #{stderr}."
|
|
113
|
+
end
|
|
114
|
+
|
|
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
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def add_line(file, line)
|
|
130
|
+
raise "No file #{file} found !" unless File.exist? file
|
|
131
|
+
|
|
132
|
+
File.write(file, "#{line}\n", mode: 'a')
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def search(file, text)
|
|
136
|
+
File.open(file).each do |line|
|
|
137
|
+
return true if line.match(/#{text}/)
|
|
138
|
+
end
|
|
139
|
+
false
|
|
140
|
+
end
|
|
141
|
+
|
|
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
|
|
148
|
+
|
|
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
|
|
156
|
+
|
|
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}")
|
|
164
|
+
end
|
|
165
|
+
|
|
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
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
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
|
|
200
|
+
end
|
|
201
|
+
end
|
|
70
202
|
end
|
|
71
203
|
end
|
data/lib/getch/log.rb
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'logger'
|
|
2
4
|
|
|
3
5
|
module Getch
|
|
4
6
|
class Log
|
|
5
|
-
def initialize
|
|
7
|
+
def initialize(verbose = false)
|
|
6
8
|
@log_file = '/tmp/log_install.txt'
|
|
9
|
+
@verbose = verbose
|
|
7
10
|
check_file
|
|
8
11
|
init_log
|
|
9
12
|
init_log_text
|
|
@@ -32,21 +35,21 @@ module Getch
|
|
|
32
35
|
private
|
|
33
36
|
|
|
34
37
|
def check_file
|
|
35
|
-
puts "Creating log at #{@log_file}"
|
|
38
|
+
puts "Creating log at #{@log_file}" unless File.exist? @log_file
|
|
36
39
|
end
|
|
37
40
|
|
|
38
41
|
def init_log
|
|
39
|
-
@logger = Logger.new(
|
|
40
|
-
@logger.level =
|
|
41
|
-
@logger.formatter = proc { |severity,
|
|
42
|
-
"#{severity}, #{msg}\n"
|
|
42
|
+
@logger = Logger.new($stdout)
|
|
43
|
+
@logger.level = @verbose ? Logger::DEBUG : Logger::INFO
|
|
44
|
+
@logger.formatter = proc { |severity, _, _, msg|
|
|
45
|
+
"#{severity}, #{msg}\n"
|
|
43
46
|
}
|
|
44
47
|
end
|
|
45
48
|
|
|
46
49
|
def init_log_text
|
|
47
50
|
@logger_text = Logger.new(@log_file, 1)
|
|
48
51
|
@logger_text.level = Logger::DEBUG
|
|
49
|
-
@logger_text.formatter = proc { |severity, datetime,
|
|
52
|
+
@logger_text.formatter = proc { |severity, datetime, _, msg|
|
|
50
53
|
"#{severity}, #{datetime}, #{msg}\n"
|
|
51
54
|
}
|
|
52
55
|
end
|
data/lib/getch/options.rb
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'optparse'
|
|
2
4
|
|
|
3
5
|
module Getch
|
|
4
6
|
class Options
|
|
5
|
-
attr_reader :language, :zoneinfo, :keymap, :disk, :fs, :username, :boot_disk, :cache_disk, :home_disk, :encrypt, :verbose
|
|
6
|
-
|
|
7
7
|
def initialize(argv)
|
|
8
|
-
@language = DEFAULT_OPTIONS[:language]
|
|
9
|
-
@zoneinfo = DEFAULT_OPTIONS[:zoneinfo]
|
|
10
|
-
@keymap = DEFAULT_OPTIONS[:keymap]
|
|
11
|
-
@disk = DEFAULT_OPTIONS[:disk]
|
|
12
|
-
@fs = DEFAULT_OPTIONS[:fs]
|
|
13
|
-
@username = DEFAULT_OPTIONS[:username]
|
|
14
|
-
@boot_disk = DEFAULT_OPTIONS[:boot_disk]
|
|
15
|
-
@cache_disk = DEFAULT_OPTIONS[:cache_disk]
|
|
16
|
-
@home_disk = DEFAULT_OPTIONS[:home_disk]
|
|
17
|
-
@encrypt = DEFAULT_OPTIONS[:encrypt]
|
|
18
|
-
@verbose = DEFAULT_OPTIONS[:verbose]
|
|
19
8
|
parse(argv)
|
|
20
9
|
end
|
|
21
10
|
|
|
@@ -23,48 +12,68 @@ module Getch
|
|
|
23
12
|
|
|
24
13
|
def parse(argv)
|
|
25
14
|
OptionParser.new do |opts|
|
|
26
|
-
opts.
|
|
27
|
-
|
|
15
|
+
opts.version = VERSION
|
|
16
|
+
|
|
17
|
+
opts.on('-l', '--language LANG', 'Default is en_US') do |lang|
|
|
18
|
+
OPTIONS[:language] = lang
|
|
28
19
|
end
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
|
|
21
|
+
opts.on('-z', '--zoneinfo ZONE', 'Default is US/Eastern') do |zone|
|
|
22
|
+
OPTIONS[:zoneinfo] = Getch::Guard.zone(zone)
|
|
31
23
|
end
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
|
|
25
|
+
opts.on('-k', '--keymap KEY', 'Default is us') do |key|
|
|
26
|
+
OPTIONS[:keymap] = Getch::Guard.keymap(key)
|
|
34
27
|
end
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
|
|
29
|
+
opts.on('-d', '--disk DISK', 'Root Disk where install the system (sda,sdb)') do |disk|
|
|
30
|
+
OPTIONS[:disk] = Getch::Guard.disk(disk)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
opts.on('-f', '--format FS', 'Can be ext4, lvm or zfs. Default use ext4') do |fs|
|
|
34
|
+
OPTIONS[:fs] = Getch::Guard.format(fs)
|
|
37
35
|
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
|
|
37
|
+
opts.on('-u', '--username USERNAME', 'Create a new user /home/USERNAME with password.') do |user|
|
|
38
|
+
OPTIONS[:username] = user
|
|
41
39
|
end
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
|
|
41
|
+
opts.on('-o', '--os NAME', /gentoo|void/, 'Install distro NAME, can be gentoo or void.') do |name|
|
|
42
|
+
OPTIONS[:os] = name
|
|
44
43
|
end
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
|
|
45
|
+
opts.on('--separate-boot DISK', 'Use a different DISK for the /boot or /efi partition.') do |boot|
|
|
46
|
+
OPTIONS[:boot_disk] = Getch::Guard.disk(boot)
|
|
48
47
|
end
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
|
|
49
|
+
opts.on('--separate-cache DISK', 'Use a different DISK for the swap partition, add ZIL/L2ARC for ZFS when set.') do |swap|
|
|
50
|
+
OPTIONS[:cache_disk] = Getch::Guard.disk(swap)
|
|
52
51
|
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
|
|
53
|
+
opts.on('--separate-home DISK', 'Use a different DISK for the /home partition.') do |home|
|
|
54
|
+
OPTIONS[:home_disk] = Getch::Guard.disk(home)
|
|
56
55
|
end
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
|
|
57
|
+
opts.on('--encrypt', 'Encrypt your system, use LUKS or native encryption for ZFS.') do
|
|
58
|
+
OPTIONS[:encrypt] = true
|
|
59
59
|
end
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
|
|
61
|
+
opts.on('--verbose', 'Write more messages to the standard output.') do
|
|
62
|
+
OPTIONS[:verbose] = true
|
|
62
63
|
end
|
|
63
|
-
|
|
64
|
+
|
|
65
|
+
opts.on('-h', '--help', 'Display this') do
|
|
64
66
|
puts opts
|
|
65
67
|
exit
|
|
66
68
|
end
|
|
67
|
-
|
|
69
|
+
|
|
70
|
+
begin
|
|
71
|
+
opts.parse!(argv)
|
|
72
|
+
rescue OptionParser::ParseError => e
|
|
73
|
+
warn e.message, "\n", opts
|
|
74
|
+
exit 1
|
|
75
|
+
end
|
|
76
|
+
end
|
|
68
77
|
end
|
|
69
78
|
end
|
|
70
79
|
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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
module Getch
|
|
6
|
+
module Void
|
|
7
|
+
class Boot
|
|
8
|
+
include Helpers::Void
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@efi = Helpers.efi?
|
|
12
|
+
@class_fs = Getch::select_fs
|
|
13
|
+
@fs = @class_fs::Void.new
|
|
14
|
+
@user = OPTIONS[:username]
|
|
15
|
+
@fs.create_key if @class_fs::Void.method_defined? :create_key
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def new_user
|
|
19
|
+
puts ' => Add a password for root.'
|
|
20
|
+
chroot 'passwd'
|
|
21
|
+
puts
|
|
22
|
+
return unless @user
|
|
23
|
+
|
|
24
|
+
print " => Creating a new user #{@user}..."
|
|
25
|
+
puts "\s[OK]"
|
|
26
|
+
command "useradd -m -G users,wheel,audio,video #{@user}"
|
|
27
|
+
puts " => Add a password for #{@user}."
|
|
28
|
+
chroot "passwd #{@user}"
|
|
29
|
+
puts
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def fstab
|
|
33
|
+
print ' => Configuring fstab...'
|
|
34
|
+
@fs.fstab
|
|
35
|
+
puts "\s[OK]"
|
|
36
|
+
@fs.crypttab if @class_fs::Void.method_defined? :crypttab
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Test dracut in chroot (version in /lib/modules/5.1.7-1):
|
|
40
|
+
# dracut -H -f --kver 5.1.7-1
|
|
41
|
+
def dracut
|
|
42
|
+
print ' => Configuring Dracut...'
|
|
43
|
+
@fs.config_dracut
|
|
44
|
+
@fs.kernel_cmdline_dracut
|
|
45
|
+
puts "\s[OK]"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def grub
|
|
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' : ''
|
|
52
|
+
print " => Installing Grub on #{disk}..."
|
|
53
|
+
if @efi
|
|
54
|
+
command_output 'xbps-install -y grub-x86_64-efi'
|
|
55
|
+
@fs.config_grub if @class_fs::Void.method_defined? :config_grub
|
|
56
|
+
command_output "#{prefix} grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=\"Void\""
|
|
57
|
+
else
|
|
58
|
+
command_output 'xbps-install -y grub'
|
|
59
|
+
@fs.config_grub if @class_fs::Void.method_defined? :config_grub
|
|
60
|
+
command_output "#{prefix} grub-install /dev/#{disk}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def initramfs
|
|
65
|
+
puts ' => Generating an initramfs...'
|
|
66
|
+
command_output 'xbps-reconfigure -fa' # this command also start grub-mkconfig
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def finish
|
|
70
|
+
puts
|
|
71
|
+
puts '[*!*] Install finished [*!*]'
|
|
72
|
+
puts
|
|
73
|
+
@fs.finish
|
|
74
|
+
puts
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def chroot(cmd)
|
|
80
|
+
system('chroot', MOUNTPOINT, '/bin/bash', '-c', cmd)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Getch
|
|
4
|
+
module Void
|
|
5
|
+
class Chroot
|
|
6
|
+
include Helpers::Void
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
@state = Getch::States.new
|
|
10
|
+
@pkgs = []
|
|
11
|
+
mount
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# https://docs.voidlinux.org/installation/guides/chroot.html#install-base-system-rootfs-method-only
|
|
15
|
+
def update
|
|
16
|
+
return if STATES[:gentoo_update]
|
|
17
|
+
|
|
18
|
+
command_output '/usr/bin/xbps-install -Suy xbps' # y to force (--yes)
|
|
19
|
+
command_output '/usr/bin/xbps-install -uy'
|
|
20
|
+
command_output '/usr/bin/xbps-install -y base-system'
|
|
21
|
+
#command_output '/usr/bin/xbps-remove base-voidstrap'
|
|
22
|
+
@state.update
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def extras
|
|
26
|
+
@pkgs << 'vim'
|
|
27
|
+
@pkgs << 'iptables'
|
|
28
|
+
@pkgs << 'iwd'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def fs
|
|
32
|
+
@pkgs << 'lvm2' if OPTIONS[:fs] == 'lvm'
|
|
33
|
+
@pkgs << 'zfs' if OPTIONS[:fs] == 'zfs'
|
|
34
|
+
@pkgs << 'cryptsetup' if OPTIONS[:encrypt]
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def install_pkgs
|
|
38
|
+
all_pkgs = @pkgs.join(' ')
|
|
39
|
+
command_output "/usr/bin/xbps-install -y #{all_pkgs}"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def mount
|
|
45
|
+
puts 'Populate /proc, /sys and /dev.'
|
|
46
|
+
Helpers.exec_or_die("mount --types proc /proc \"#{MOUNTPOINT}/proc\"")
|
|
47
|
+
Helpers.exec_or_die("mount --rbind /sys \"#{MOUNTPOINT}/sys\"")
|
|
48
|
+
Helpers.exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/sys\"")
|
|
49
|
+
Helpers.exec_or_die("mount --rbind /dev \"#{MOUNTPOINT}/dev\"")
|
|
50
|
+
Helpers.exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/dev\"")
|
|
51
|
+
# Maybe add /dev/shm like describe here:
|
|
52
|
+
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|