getch 0.1.6 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +17 -26
  4. data/assets/system.conf +38 -0
  5. data/lib/cmdline.rb +128 -0
  6. data/lib/getch/command.rb +31 -21
  7. data/lib/getch/config/gentoo.rb +22 -23
  8. data/lib/getch/config/void.rb +8 -10
  9. data/lib/getch/config.rb +5 -2
  10. data/lib/getch/filesystem/clean.rb +15 -15
  11. data/lib/getch/filesystem/device.rb +3 -1
  12. data/lib/getch/filesystem/ext4/config.rb +8 -4
  13. data/lib/getch/filesystem/ext4/deps.rb +3 -1
  14. data/lib/getch/filesystem/ext4/device.rb +2 -3
  15. data/lib/getch/filesystem/ext4/encrypt/config.rb +12 -7
  16. data/lib/getch/filesystem/ext4/encrypt/deps.rb +4 -2
  17. data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
  18. data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -1
  19. data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -2
  20. data/lib/getch/filesystem/ext4/encrypt/partition.rb +21 -21
  21. data/lib/getch/filesystem/ext4/encrypt/void.rb +22 -21
  22. data/lib/getch/filesystem/ext4/encrypt.rb +2 -0
  23. data/lib/getch/filesystem/ext4/format.rb +3 -0
  24. data/lib/getch/filesystem/ext4/mount.rb +3 -0
  25. data/lib/getch/filesystem/ext4/partition.rb +9 -6
  26. data/lib/getch/filesystem/ext4/void.rb +8 -7
  27. data/lib/getch/filesystem/ext4.rb +2 -0
  28. data/lib/getch/filesystem/lvm/config.rb +7 -22
  29. data/lib/getch/filesystem/lvm/deps.rb +6 -4
  30. data/lib/getch/filesystem/lvm/device.rb +2 -0
  31. data/lib/getch/filesystem/lvm/encrypt/config.rb +12 -9
  32. data/lib/getch/filesystem/lvm/encrypt/deps.rb +6 -3
  33. data/lib/getch/filesystem/lvm/encrypt/device.rb +4 -2
  34. data/lib/getch/filesystem/lvm/encrypt/format.rb +4 -0
  35. data/lib/getch/filesystem/lvm/encrypt/mount.rb +3 -0
  36. data/lib/getch/filesystem/lvm/encrypt/partition.rb +7 -7
  37. data/lib/getch/filesystem/lvm/encrypt/void.rb +20 -19
  38. data/lib/getch/filesystem/lvm/encrypt.rb +2 -0
  39. data/lib/getch/filesystem/lvm/format.rb +3 -0
  40. data/lib/getch/filesystem/lvm/mount.rb +3 -0
  41. data/lib/getch/filesystem/lvm/partition.rb +8 -5
  42. data/lib/getch/filesystem/lvm/void.rb +7 -6
  43. data/lib/getch/filesystem/lvm.rb +2 -0
  44. data/lib/getch/filesystem/mount.rb +19 -12
  45. data/lib/getch/filesystem/partition.rb +16 -8
  46. data/lib/getch/filesystem/zfs/config.rb +9 -23
  47. data/lib/getch/filesystem/zfs/deps.rb +22 -57
  48. data/lib/getch/filesystem/zfs/device.rb +3 -1
  49. data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -26
  50. data/lib/getch/filesystem/zfs/encrypt/deps.rb +25 -60
  51. data/lib/getch/filesystem/zfs/encrypt/device.rb +3 -1
  52. data/lib/getch/filesystem/zfs/encrypt/format.rb +12 -8
  53. data/lib/getch/filesystem/zfs/encrypt/mount.rb +13 -8
  54. data/lib/getch/filesystem/zfs/encrypt/partition.rb +18 -15
  55. data/lib/getch/filesystem/zfs/encrypt/void.rb +23 -22
  56. data/lib/getch/filesystem/zfs/encrypt.rb +2 -0
  57. data/lib/getch/filesystem/zfs/format.rb +9 -5
  58. data/lib/getch/filesystem/zfs/mount.rb +9 -7
  59. data/lib/getch/filesystem/zfs/partition.rb +15 -12
  60. data/lib/getch/filesystem/zfs/void.rb +20 -20
  61. data/lib/getch/filesystem/zfs.rb +2 -0
  62. data/lib/getch/filesystem.rb +2 -0
  63. data/lib/getch/gentoo/boot.rb +21 -72
  64. data/lib/getch/gentoo/bootloader.rb +68 -0
  65. data/lib/getch/gentoo/chroot.rb +26 -33
  66. data/lib/getch/gentoo/config.rb +30 -26
  67. data/lib/getch/gentoo/sources.rb +55 -66
  68. data/lib/getch/gentoo/stage.rb +12 -12
  69. data/lib/getch/gentoo/use.rb +3 -7
  70. data/lib/getch/gentoo/use_flag.rb +77 -51
  71. data/lib/getch/gentoo.rb +22 -8
  72. data/lib/getch/guard.rb +50 -43
  73. data/lib/getch/helpers.rb +155 -143
  74. data/lib/getch/log.rb +7 -5
  75. data/lib/getch/options.rb +16 -14
  76. data/lib/getch/states.rb +10 -3
  77. data/lib/getch/version.rb +1 -1
  78. data/lib/getch/void/boot.rb +18 -14
  79. data/lib/getch/void/chroot.rb +20 -19
  80. data/lib/getch/void/config.rb +20 -17
  81. data/lib/getch/void/stage.rb +13 -14
  82. data/lib/getch/void.rb +7 -1
  83. data/lib/getch.rb +13 -5
  84. data.tar.gz.sig +0 -0
  85. metadata +6 -5
  86. metadata.gz.sig +0 -0
  87. data/lib/getch/filesystem/.mount.rb.swp +0 -0
  88. 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 Helpers
6
- def self.efi?
7
- Dir.exist? '/sys/firmware/efi/efivars'
8
- end
7
+ module Getch
8
+ module Helpers
9
+ def self.efi?
10
+ Dir.exist? '/sys/firmware/efi/efivars'
11
+ end
9
12
 
10
- def self.get_file_online(url, dest)
11
- URI.open(url) do |l|
12
- File.open(dest, "wb") do |f|
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
- def self.exec_or_die(cmd)
19
- _, stderr, status = Open3.capture3(cmd)
20
- unless status.success?
21
- raise "Problem running #{cmd}, stderr was:\n#{stderr}"
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
- def self.create_dir(path, perm = 0755)
26
- FileUtils.mkdir_p path, mode: perm if ! Dir.exist?(path)
27
- end
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
- def self.mkdir(dir)
34
- FileUtils.mkdir_p dir if ! Dir.exist? dir
35
- end
30
+ def self.add_file(path, content = '')
31
+ File.write path, content unless File.exist? path
32
+ end
36
33
 
37
- def self.touch(file)
38
- File.write file, '' if ! File.exist? file
39
- end
34
+ def self.mkdir(dir)
35
+ FileUtils.mkdir_p dir unless Dir.exist? dir
36
+ end
40
37
 
41
- def self.cp(src, dest)
42
- raise "Src file #{src} no found" unless File.exist? src
43
- FileUtils.cp(src, dest)
44
- end
38
+ def self.touch(file)
39
+ File.write file, '' unless File.exist? file
40
+ end
45
41
 
46
- def self.grep?(file, regex)
47
- is_found = false
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
- def self.sys(cmd)
58
- system(cmd)
59
- unless $?.success?
60
- raise "Error with #{cmd}"
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
- def self.partuuid(dev)
65
- `lsblk -o PARTUUID #{dev}`.match(/[\w]+-[\w]+-[\w]+-[\w]+-[\w]+/)
66
- end
52
+ def self.cp(src, dest)
53
+ raise "Src file #{src} no found" unless File.exist? src
67
54
 
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/")
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
- end
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
- # 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
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
- 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
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
- 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
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
- exit_status = wait_thr.value
117
- unless exit_status.success?
118
- raise "\n[-] Fail cmd #{args} - #{stdout_err}."
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
- 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
129
+ def add_line(file, line)
130
+ raise "No file #{file} found !" unless File.exist? file
127
131
 
128
- def search(file, text)
129
- File.open(file).each { |line|
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
- # Used only when need password
136
- def chroot(cmd)
137
- if !system("chroot", Getch::MOUNTPOINT, "/bin/bash", "-c", cmd)
138
- raise "[-] Error with: #{cmd}"
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
- 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
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
- 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
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
- 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')
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
- 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}")
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
- 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}")
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}" if ! File.exist? @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(STDOUT)
42
+ @logger = Logger.new($stdout)
41
43
  @logger.level = @verbose ? Logger::DEBUG : Logger::INFO
42
- @logger.formatter = proc { |severity, datetime, progname, msg|
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, progname, msg|
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("-l", "--language LANG", "Default is en_US") do |lang|
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("-z", "--zoneinfo ZONE", "Default is US/Eastern") do |zone|
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("-k", "--keymap KEY", "Default is us") do |key|
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("-d", "--disk DISK", "Root Disk where install the system (sda,sdb)") do |disk|
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("-f", "--format FS", "Can be ext4, lvm or zfs. Default use ext4") do |fs|
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("-u", "--username USERNAME", "Create a new user /home/USERNAME with password.") do |user|
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("-o", "--os NAME", /gentoo|void/, "Instal distro NAME, can be gentoo or void.") do |name|
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("--separate-boot DISK", "Use a different DISK for the /boot or /efi partition.") do |boot|
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("--separate-cache DISK", "Use a different DISK for the swap partition, add ZIL/L2ARC for ZFS when set.") do |swap|
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("--separate-home DISK", "Use a different DISK for the /home partition.") do |home|
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("--encrypt", "Encrypt your system, use LUKS or native encryption for ZFS.") do
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("--verbose", "Write more messages to the standard output.") do
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("-h", "--help", "Display this") do
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
- STDERR.puts e.message, "\n", opts
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::dump(STATES, f) }
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
- STDERR.puts "Initialize states"
64
+ warn 'Initialize states'
58
65
  end
59
66
  end
60
67
  end
data/lib/getch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Getch
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.9'.freeze
3
3
  end
@@ -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::efi?
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 " => Add a password for root."
19
- chroot "passwd"
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 " => Configuring fstab..."
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 " => Configuring Dracut..."
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 "xbps-install -y grub-x86_64-efi"
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 "xbps-install -y grub"
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 " => Generating an initramfs..."
62
- command_output "xbps-reconfigure -fa" # this command also start grub-mkconfig
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 "[*!*] Install finished [*!*]"
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("chroot", MOUNTPOINT, "/bin/bash", "-c", cmd)
80
+ system('chroot', MOUNTPOINT, '/bin/bash', '-c', cmd)
77
81
  end
78
82
  end
79
83
  end