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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +35 -29
  4. data/bin/getch +8 -6
  5. data/lib/clean.rb +149 -0
  6. data/lib/cryptsetup.rb +132 -0
  7. data/lib/devs.rb +199 -0
  8. data/lib/dracut/encrypt.rb +36 -0
  9. data/lib/dracut/hybrid.rb +15 -0
  10. data/lib/dracut/lvm.rb +14 -0
  11. data/lib/dracut/minimal.rb +11 -0
  12. data/lib/dracut/root.rb +45 -0
  13. data/lib/dracut/zfs.rb +35 -0
  14. data/lib/dracut.rb +11 -0
  15. data/lib/fstab/encrypt.rb +44 -0
  16. data/lib/fstab/hybrid.rb +34 -0
  17. data/lib/fstab/lvm.rb +25 -0
  18. data/lib/fstab/minimal.rb +6 -0
  19. data/lib/fstab/root.rb +93 -0
  20. data/lib/fstab/zfs.rb +23 -0
  21. data/lib/fstab.rb +11 -0
  22. data/lib/getch/assembly.rb +150 -0
  23. data/lib/getch/command.rb +88 -128
  24. data/lib/getch/config/account.rb +39 -0
  25. data/lib/getch/config/dhcp.rb +104 -0
  26. data/lib/getch/config/grub.rb +42 -0
  27. data/lib/getch/config/iwd.rb +60 -0
  28. data/lib/getch/config/keymap.rb +78 -0
  29. data/lib/getch/config/locale.rb +96 -0
  30. data/lib/getch/config/portage.rb +90 -0
  31. data/lib/getch/config/pre_network.rb +37 -0
  32. data/lib/getch/config/timezone.rb +52 -0
  33. data/lib/getch/config/void.rb +0 -36
  34. data/lib/getch/config.rb +16 -37
  35. data/lib/getch/device.rb +67 -0
  36. data/lib/getch/filesystem/ext4/encrypt/config.rb +9 -71
  37. data/lib/getch/filesystem/ext4/encrypt/deps.rb +15 -25
  38. data/lib/getch/filesystem/ext4/encrypt/device.rb +11 -5
  39. data/lib/getch/filesystem/ext4/encrypt/format.rb +6 -15
  40. data/lib/getch/filesystem/ext4/encrypt/mount.rb +7 -11
  41. data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -76
  42. data/lib/getch/filesystem/ext4/encrypt/void.rb +0 -38
  43. data/lib/getch/filesystem/ext4/encrypt.rb +2 -1
  44. data/lib/getch/filesystem/ext4/hybrid/config.rb +27 -0
  45. data/lib/getch/filesystem/ext4/hybrid/deps.rb +55 -0
  46. data/lib/getch/filesystem/ext4/hybrid/device.rb +24 -0
  47. data/lib/getch/filesystem/ext4/hybrid/format.rb +23 -0
  48. data/lib/getch/filesystem/ext4/hybrid/mount.rb +21 -0
  49. data/lib/getch/filesystem/ext4/hybrid/partition.rb +27 -0
  50. data/lib/getch/filesystem/{lvm/encrypt → ext4/hybrid}/void.rb +0 -39
  51. data/lib/getch/filesystem/ext4/hybrid.rb +19 -0
  52. data/lib/getch/filesystem/ext4/lvm/config.rb +25 -0
  53. data/lib/getch/filesystem/ext4/lvm/deps.rb +56 -0
  54. data/lib/getch/filesystem/ext4/lvm/device.rb +28 -0
  55. data/lib/getch/filesystem/ext4/lvm/format.rb +21 -0
  56. data/lib/getch/filesystem/ext4/lvm/mount.rb +21 -0
  57. data/lib/getch/filesystem/ext4/lvm/partition.rb +28 -0
  58. data/lib/getch/filesystem/{lvm.rb → ext4/lvm.rb} +6 -4
  59. data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
  60. data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +3 -1
  61. data/lib/getch/filesystem/ext4/minimal/device.rb +22 -0
  62. data/lib/getch/filesystem/ext4/minimal/format.rb +23 -0
  63. data/lib/getch/filesystem/ext4/minimal/mount.rb +21 -0
  64. data/lib/getch/filesystem/ext4/minimal/partition.rb +28 -0
  65. data/lib/getch/filesystem/ext4/minimal.rb +19 -0
  66. data/lib/getch/filesystem/ext4.rb +7 -7
  67. data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -39
  68. data/lib/getch/filesystem/zfs/encrypt/deps.rb +4 -55
  69. data/lib/getch/filesystem/zfs/encrypt/device.rb +7 -51
  70. data/lib/getch/filesystem/zfs/encrypt/format.rb +6 -90
  71. data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -35
  72. data/lib/getch/filesystem/zfs/encrypt/partition.rb +6 -54
  73. data/lib/getch/filesystem/zfs/encrypt.rb +2 -1
  74. data/lib/getch/filesystem/zfs/minimal/config.rb +37 -0
  75. data/lib/getch/filesystem/zfs/minimal/deps.rb +126 -0
  76. data/lib/getch/filesystem/zfs/minimal/device.rb +24 -0
  77. data/lib/getch/filesystem/zfs/minimal/format.rb +23 -0
  78. data/lib/getch/filesystem/zfs/minimal/mount.rb +23 -0
  79. data/lib/getch/filesystem/zfs/minimal/partition.rb +23 -0
  80. data/lib/getch/filesystem/zfs/minimal.rb +19 -0
  81. data/lib/getch/filesystem/zfs.rb +1 -7
  82. data/lib/getch/filesystem.rb +0 -6
  83. data/lib/getch/gentoo/bootloader.rb +23 -44
  84. data/lib/getch/gentoo/finalize.rb +25 -0
  85. data/lib/getch/gentoo/post_config.rb +75 -0
  86. data/lib/getch/gentoo/pre_config.rb +37 -0
  87. data/lib/getch/gentoo/services.rb +18 -0
  88. data/lib/getch/gentoo/sources.rb +39 -33
  89. data/lib/getch/gentoo/tarball.rb +91 -0
  90. data/lib/getch/gentoo/terraform.rb +34 -0
  91. data/lib/getch/gentoo/update.rb +54 -0
  92. data/lib/getch/gentoo/use.rb +9 -6
  93. data/lib/getch/gentoo/use_flag.rb +17 -20
  94. data/lib/getch/gentoo.rb +9 -75
  95. data/lib/getch/guard.rb +2 -2
  96. data/lib/getch/helpers.rb +63 -115
  97. data/lib/getch/log.rb +87 -25
  98. data/lib/getch/options.rb +41 -11
  99. data/lib/getch/states.rb +28 -8
  100. data/lib/getch/tree.rb +56 -0
  101. data/lib/getch/version.rb +1 -1
  102. data/lib/getch/void/bootloader.rb +18 -0
  103. data/lib/getch/void/finalize.rb +31 -0
  104. data/lib/getch/void/post_config.rb +19 -0
  105. data/lib/getch/void/pre_config.rb +18 -0
  106. data/lib/getch/void/services.rb +18 -0
  107. data/lib/getch/void/{stage.rb → tarball.rb} +34 -14
  108. data/lib/getch/void/terraform.rb +28 -0
  109. data/lib/getch/void/update.rb +33 -0
  110. data/lib/getch/void.rb +9 -59
  111. data/lib/getch.rb +58 -90
  112. data/lib/luks.rb +239 -0
  113. data/lib/lvm2.rb +112 -0
  114. data/lib/mkfs/zfs.rb +167 -0
  115. data/lib/mkfs.rb +140 -0
  116. data/lib/mountfs.rb +154 -0
  117. data/lib/nito.rb +131 -0
  118. data/lib/sgdisk.rb +160 -0
  119. data.tar.gz.sig +0 -0
  120. metadata +83 -47
  121. metadata.gz.sig +0 -0
  122. data/lib/getch/config/gentoo.rb +0 -58
  123. data/lib/getch/filesystem/clean.rb +0 -58
  124. data/lib/getch/filesystem/device.rb +0 -63
  125. data/lib/getch/filesystem/ext4/config.rb +0 -62
  126. data/lib/getch/filesystem/ext4/deps.rb +0 -24
  127. data/lib/getch/filesystem/ext4/format.rb +0 -31
  128. data/lib/getch/filesystem/ext4/mount.rb +0 -26
  129. data/lib/getch/filesystem/ext4/partition.rb +0 -55
  130. data/lib/getch/filesystem/ext4/void.rb +0 -44
  131. data/lib/getch/filesystem/lvm/config.rb +0 -44
  132. data/lib/getch/filesystem/lvm/deps.rb +0 -44
  133. data/lib/getch/filesystem/lvm/device.rb +0 -45
  134. data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -74
  135. data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -49
  136. data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -48
  137. data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -35
  138. data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -27
  139. data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -84
  140. data/lib/getch/filesystem/lvm/encrypt.rb +0 -18
  141. data/lib/getch/filesystem/lvm/format.rb +0 -32
  142. data/lib/getch/filesystem/lvm/mount.rb +0 -26
  143. data/lib/getch/filesystem/lvm/partition.rb +0 -72
  144. data/lib/getch/filesystem/lvm/void.rb +0 -46
  145. data/lib/getch/filesystem/mount.rb +0 -63
  146. data/lib/getch/filesystem/partition.rb +0 -85
  147. data/lib/getch/filesystem/zfs/config.rb +0 -43
  148. data/lib/getch/filesystem/zfs/deps.rb +0 -67
  149. data/lib/getch/filesystem/zfs/device.rb +0 -66
  150. data/lib/getch/filesystem/zfs/encrypt/void.rb +0 -97
  151. data/lib/getch/filesystem/zfs/format.rb +0 -117
  152. data/lib/getch/filesystem/zfs/mount.rb +0 -47
  153. data/lib/getch/filesystem/zfs/partition.rb +0 -69
  154. data/lib/getch/filesystem/zfs/void.rb +0 -81
  155. data/lib/getch/gentoo/boot.rb +0 -64
  156. data/lib/getch/gentoo/chroot.rb +0 -75
  157. data/lib/getch/gentoo/config.rb +0 -167
  158. data/lib/getch/gentoo/stage.rb +0 -73
  159. data/lib/getch/void/boot.rb +0 -84
  160. data/lib/getch/void/chroot.rb +0 -56
  161. data/lib/getch/void/config.rb +0 -90
data/lib/getch/command.rb CHANGED
@@ -1,161 +1,71 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'open3'
4
+ require 'nito'
4
5
 
5
6
  module Getch
6
7
  class Command
7
- def initialize(cmd)
8
- @cmd = cmd
9
- @block_size = 1024
8
+ attr_reader :res
9
+
10
+ def initialize(*args)
11
+ @cmd = args.join(' ')
10
12
  @log = Getch::Log.new
13
+ x
11
14
  end
12
15
 
13
- def run!
14
- @log.info 'Running command: ' + @cmd.gsub(/\"/, '')
15
-
16
- Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
17
- stdin.close_write
18
- code = wait_thr.value
19
-
20
- # only stderr
21
- begin
22
- @log.debug stderr.readline until stderr.eof.nil?
23
- rescue
24
- end
16
+ def to_s
17
+ @res
18
+ end
25
19
 
26
- begin
27
- files = [stdout, stderr]
20
+ protected
28
21
 
29
- until all_eof(files) do
30
- ready = IO.select(files)
22
+ def x
23
+ @log.info 'Exec: ' + @cmd
24
+ cmd = build_cmd
31
25
 
32
- if ready
33
- readable = ready[0]
34
- # writable = ready[1]
35
- # exceptions = ready[2]
26
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
27
+ stdin.close_write
28
+ code = wait_thr.value
36
29
 
37
- display_lines(readable)
38
- end
30
+ unless code.success?
31
+ begin
32
+ @log.debug stderr.readline until stderr.eof.nil?
33
+ rescue EOFError
34
+ print
39
35
  end
40
- rescue IOError => e
41
- puts "IOError: #{e}"
42
36
  end
43
37
 
44
- unless code.success?
45
- @log.fatal "Running #{@cmd}"
46
- exit 1
38
+ if code.success?
39
+ @log.result_ok
40
+ @res = stdout.read.chomp
41
+ return
47
42
  end
48
43
 
49
- @log.debug "Done - #{@cmd} - #{code}"
50
- end
51
- end
52
-
53
- private
54
-
55
- # Returns true if all files are EOF
56
- def all_eof(files)
57
- files.find { |f| !f.eof }.nil?
58
- end
59
-
60
- def display_lines(block)
61
- block.each do |f|
62
- begin
63
- data = f.read_nonblock(@block_size)
64
- puts data if OPTIONS[:verbose]
65
- rescue EOFError
66
- puts
67
- rescue => e
68
- puts "Fatal - #{e}"
69
- end
70
- end
71
- end
72
- end
73
-
74
- # Use system, the only ruby method to display stdout with colors !
75
- class Emerge
76
- def initialize(cmd)
77
- @gentoo = MOUNTPOINT
78
- @cmd = cmd
79
- @log = Getch::Log.new
80
- end
81
-
82
- def run!
83
- @log.info "Running emerge: #{@cmd}"
84
- system('chroot', @gentoo, '/bin/bash', '-c', "source /etc/profile && #{@cmd}")
85
- read_exit
86
- end
87
-
88
- def pkg!
89
- @log.info "Running emerge pkg: #{@cmd}"
90
- system('chroot', @gentoo, '/bin/bash', '-c', "source /etc/profile && emerge --changed-use #{@cmd}")
91
- read_exit
92
- end
93
-
94
- private
95
-
96
- def read_exit
97
- if $?.exitstatus > 0
44
+ puts
45
+ @log.error "#{@cmd} - #{code}"
98
46
  @log.fatal "Running #{@cmd}"
99
- else
100
- @log.info "Done #{@cmd}"
101
47
  end
102
48
  end
103
- end
104
49
 
105
- class Make
106
- def initialize(cmd)
107
- @gentoo = MOUNTPOINT
108
- @cmd = cmd
109
- @log = Getch::Log.new
110
- end
50
+ private
111
51
 
112
- def run!
113
- @log.info "Running Make: #{@cmd}"
114
- cmd = "chroot #{@gentoo} /bin/bash -c \"source /etc/profile \
115
- && env-update \
116
- && cd /usr/src/linux \
117
- && #{@cmd}\""
118
- Open3.popen2e(cmd) do |_, stdout_err, wait_thr|
119
- stdout_err.each { |l| puts l }
120
-
121
- exit_status = wait_thr.value
122
- unless exit_status.success?
123
- @log.fatal "Running #{cmd}"
124
- exit 1
125
- end
126
- end
52
+ def build_cmd
53
+ @cmd
127
54
  end
128
55
  end
129
56
 
130
57
  class Bask
131
58
  def initialize(cmd)
132
59
  @cmd = cmd
133
- @log = Getch::Log.new
60
+ @log = Log.new
134
61
  @version = '0.6'
135
62
  @config = "#{MOUNTPOINT}/etc/kernel/config.d"
136
63
  download_bask unless Dir.exist? "#{MOUNTPOINT}/root/bask-#{@version}"
137
64
  end
138
65
 
139
- def run!
140
- @log.info "Running Bask: #{@cmd}"
141
- cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile \
142
- && env-update \
143
- && cd /root/bask-#{@version} \
144
- && ./bask.sh #{@cmd} -k /usr/src/linux\""
145
- Open3.popen2e(cmd) do |_, stdout_err, wait_thr|
146
- stdout_err.each { |l| puts l }
147
-
148
- exit_status = wait_thr.value
149
- unless exit_status.success?
150
- @log.fatal "Running #{cmd}"
151
- exit 1
152
- end
153
- end
154
- end
155
-
156
66
  def cp
157
- Helpers.mkdir @config
158
- Helpers.cp(
67
+ NiTo.mkdir @config
68
+ NiTo.cp(
159
69
  "#{MOUNTPOINT}/root/bask-#{@version}/config.d/#{@cmd}",
160
70
  "#{@config}/#{@cmd}"
161
71
  )
@@ -168,20 +78,70 @@ module Getch
168
78
  private
169
79
 
170
80
  def download_bask
171
- @log.info 'Installing Bask...'
81
+ @log.info "Installing Bask...\n"
172
82
  url = "https://github.com/szorfein/bask/archive/refs/tags/#{@version}.tar.gz"
173
83
  file = "bask-#{@version}.tar.gz"
174
84
 
175
85
  Dir.chdir("#{MOUNTPOINT}/root")
176
86
  Helpers.get_file_online(url, file)
177
- Getch::Command.new("tar xzf #{file}").run!
87
+ Getch::Command.new("tar xzf #{file}")
178
88
  end
179
89
  end
180
90
 
181
91
  class Chroot < Command
182
- def initialize(cmd)
183
- super
184
- @cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile; #{cmd}\""
92
+ def build_cmd
93
+ dest = OPTIONS[:mountpoint]
94
+ case OPTIONS[:os]
95
+ when 'gentoo'
96
+ "chroot #{dest} /bin/bash -c \"source /etc/profile; #{@cmd}\""
97
+ when 'void'
98
+ "chroot #{dest} /bin/bash -c \"#{@cmd}\""
99
+ end
100
+ end
101
+ end
102
+
103
+ class ChrootOutput
104
+ def initialize(*args)
105
+ @cmd = args.join(' ')
106
+ @log = Log.new
107
+ x
108
+ end
109
+
110
+ private
111
+
112
+ def x
113
+ msg
114
+ system('chroot', OPTIONS[:mountpoint], '/bin/bash', '-c', other_args)
115
+ $?.success? && return
116
+
117
+ @log.fatal "Running #{@cmd}"
118
+ end
119
+
120
+ def msg
121
+ @log.info "Exec: #{@cmd}...\n"
122
+ end
123
+
124
+ def other_args
125
+ case OPTIONS[:os]
126
+ when 'gentoo' then "source /etc/profile && #{@cmd}"
127
+ when 'void' then @cmd
128
+ end
129
+ end
130
+ end
131
+
132
+ # Install
133
+ # use system() to install packages
134
+ # Usage: Install.new(pkg_name)
135
+ class Install < ChrootOutput
136
+ def msg
137
+ @log.info "Installing #{@cmd}...\n"
138
+ end
139
+
140
+ def other_args
141
+ case OPTIONS[:os]
142
+ when 'gentoo' then "source /etc/profile && emerge --changed-use #{@cmd}"
143
+ when 'void' then "/usr/bin/xbps-install -y #{@cmd}"
144
+ end
185
145
  end
186
146
  end
187
147
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getch
4
+ module Config
5
+ class Account
6
+ def initialize
7
+ @user = OPTIONS[:username] ||= nil
8
+ @log = Log.new
9
+ end
10
+
11
+ def root
12
+ @log.info "Add a password for root.\n"
13
+ ChrootOutput.new('passwd')
14
+ end
15
+
16
+ def new_user
17
+ return unless @user
18
+
19
+ create_user
20
+ @log.info "Add a password for #{@user}.\n"
21
+ ChrootOutput.new("passwd #{@user}")
22
+ fix_perm
23
+ end
24
+
25
+ private
26
+
27
+ def create_user
28
+ @log.info "Creating a new user #{@user}..."
29
+ Getch::Chroot.new("useradd -m -G users,wheel,audio,video #{@user}")
30
+ @log.result_ok
31
+ end
32
+
33
+ def fix_perm
34
+ Getch::Chroot.new("chown -R #{@user}:#{@user} /home/#{@user}")
35
+ Getch::Chroot.new("chmod 700 -R /home/#{@user}")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nito'
4
+
5
+ module Getch
6
+ module Config
7
+ class Dhcp
8
+ include NiTo
9
+
10
+ def initialize
11
+ x
12
+ end
13
+
14
+ protected
15
+
16
+ def x
17
+ runit
18
+ systemd
19
+ openrc
20
+ end
21
+
22
+ private
23
+
24
+ # https://docs.voidlinux.org/config/network/iwd.html
25
+ def runit
26
+ Helpers.runit? || return
27
+
28
+ echo_a "#{OPTIONS[:mountpoint]}/etc/dhcpcd.conf", 'nohook resolv.conf'
29
+ resolv_conf
30
+ service = '/etc/runit/runsvdir/default/'
31
+ Chroot.new("ln -fs /etc/sv/dhcpcd #{service}")
32
+ end
33
+
34
+ def systemd
35
+ Helpers.systemd? || return
36
+
37
+ systemd_ethernet
38
+ systemd_wireless
39
+ systemd_resolve
40
+ Chroot.new('systemctl enable systemd-networkd')
41
+ Chroot.new('systemctl enable systemd-resolved')
42
+ end
43
+
44
+ def openrc
45
+ Helpers.openrc? || return
46
+
47
+ echo_a "#{OPTIONS[:mountpoint]}/etc/dhcpcd.conf", 'nohook resolv.conf'
48
+ resolv_conf
49
+ Chroot.new('rc-update add dhcpcd default')
50
+ end
51
+
52
+ # https://www.dnsknowledge.com/tutorials/how-to-setup-quad9-dns-on-a-linux/
53
+ def resolv_conf
54
+ conf = "#{OPTIONS[:mountpoint]}/etc/resolv.conf"
55
+ content = <<~CONF
56
+ nameserver 9.9.9.9
57
+ nameserver 2620:fe::fe
58
+ options rotate
59
+ CONF
60
+ File.write conf, "#{content}\n"
61
+ end
62
+
63
+ def systemd_ethernet
64
+ conf = "#{OPTIONS[:mountpoint]}/etc/systemd/network/20-ethernet.network"
65
+ content = <<~NETWORK
66
+ [Match]
67
+ Name=en*
68
+ Name=eth*
69
+ [Network]
70
+ DHCP=yes
71
+ IPv6PrivacyExtensions=yes
72
+ [DHCP]
73
+ RouteMetric=512
74
+ NETWORK
75
+ File.write(conf, "#{content}\n")
76
+ end
77
+
78
+ def systemd_wireless
79
+ conf = "#{OPTIONS[:mountpoint]}/etc/systemd/network/20-wireless.network"
80
+ content = <<~NETWORK
81
+ [Match]
82
+ Name=wl*
83
+ [Network]
84
+ DHCP=yes
85
+ IPv6PrivacyExtensions=yes
86
+ [DHCP]
87
+ RouteMetric=1024
88
+ NETWORK
89
+ File.write conf, "#{content}\n"
90
+ end
91
+
92
+ def systemd_resolve
93
+ mkdir "#{OPTIONS[:mountpoint]}/etc/systemd/resolved.conf.d"
94
+ conf = "#{OPTIONS[:mountpoint]}/etc/systemd/resolved.conf.d/dns_tls.conf"
95
+ content = <<~CONF
96
+ [Resolve]
97
+ DNS=9.9.9.9#dns.quad9.net
98
+ DNSOverTLS=yes
99
+ CONF
100
+ File.write conf, "#{content}\n"
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nito'
4
+
5
+ module Getch
6
+ module Config
7
+ class Grub
8
+ def initialize
9
+ @log = Log.new
10
+ @disk = OPTIONS[:boot_disk] ||= OPTIONS[:disk]
11
+ # https://wiki.archlinux.org/title/Install_Arch_Linux_on_ZFS
12
+ @prefix = OPTIONS[:fs] == 'zfs' ? 'ZPOOL_VDEV_NAME_PATH=1' : ''
13
+ @os_name = OPTIONS[:os].capitalize
14
+ x
15
+ end
16
+
17
+ def x
18
+ @log.info "Installing Grub on #{@disk}...\n"
19
+ Helpers.efi? ? grub_efi : grub_bios
20
+ end
21
+
22
+ private
23
+
24
+ def grub_efi
25
+ mount_efivars
26
+ cmd = "#{@prefix} grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=\"#{@os_name}\""
27
+ ChrootOutput.new(cmd)
28
+ end
29
+
30
+ def grub_bios
31
+ cmd = "#{@prefix} grub-install /dev/#{@disk}"
32
+ ChrootOutput.new(cmd)
33
+ end
34
+
35
+ # In case where efivars is not mounted
36
+ # avoid error with grub
37
+ def mount_efivars
38
+ NiTo.mount '-t efivarfs', 'efivarfs', '/sys/firmware/efi/efivars'
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,60 @@
1
+ module Getch
2
+ module Config
3
+ class Iwd
4
+ include NiTo
5
+
6
+ def initialize
7
+ x
8
+ end
9
+
10
+ protected
11
+
12
+ def x
13
+ runit
14
+ systemd
15
+ openrc
16
+ end
17
+
18
+ private
19
+
20
+ # https://docs.voidlinux.org/config/network/iwd.html
21
+ def runit
22
+ Helpers.runit? || return
23
+
24
+ iwd_conf
25
+ service = '/etc/runit/runsvdir/default/'
26
+ Chroot.new("ln -fs /etc/sv/dbus #{service}")
27
+ Chroot.new("ln -fs /etc/sv/iwd #{service}")
28
+ end
29
+
30
+ def systemd
31
+ Helpers.systemd? || return
32
+
33
+ iwd_conf
34
+ Chroot.new('systemctl enable iwd')
35
+ end
36
+
37
+ def openrc
38
+ Helpers.openrc? || return
39
+
40
+ iwd_conf
41
+ Chroot.new('rc-update add iwd default')
42
+ end
43
+
44
+ # https://docs.voidlinux.org/config/network/iwd.html#troubleshooting
45
+ def iwd_conf
46
+ conf = "#{OPTIONS[:mountpoint]}/etc/iwd/main.conf"
47
+ content = "[General]\n"
48
+ content << "UseDefaultInterface=true\n"
49
+ content << "[Network]\n"
50
+ Helpers.systemd? ?
51
+ content << "NameResolvingService=systemd\n" :
52
+ content << "NameResolvingService=resolvconf\n"
53
+ content << "[Scan]\n"
54
+ content << "DisablePeriodicScan=true\n"
55
+ mkdir "#{OPTIONS[:mountpoint]}/etc/iwd"
56
+ echo conf, "#{content}\n"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nito'
4
+
5
+ module Getch
6
+ module Config
7
+ # Search and configure the keymap (man loadkeys)
8
+ class Keymap
9
+ include NiTo
10
+
11
+ def initialize
12
+ @log = Log.new
13
+ @rc_conf = "#{OPTIONS[:mountpoint]}/etc/rc.conf"
14
+ @vconsole_conf = "#{OPTIONS[:mountpoint]}/etc/vconsole.conf"
15
+ @conf_d = "#{OPTIONS[:mountpoint]}/etc/conf.d/keymaps"
16
+ @keymaps_dir = nil
17
+ @keymap = nil
18
+ x
19
+ end
20
+
21
+ protected
22
+
23
+ def x
24
+ @log.info "Configuring keymap...\n"
25
+ search_keymap
26
+ apply_conf
27
+ end
28
+
29
+ def search_keymap
30
+ search_dir
31
+ path = "#{OPTIONS[:mountpoint]}#{@keymaps_dir}/**/#{OPTIONS[:keymap]}.map.gz"
32
+ Dir.glob(path) { |f| @keymap = OPTIONS[:keymap] if f }
33
+
34
+ @keymap || @log.fatal("No keymap found for #{OPTIONS[:keymap]}.")
35
+ end
36
+
37
+ def apply_conf
38
+ @log.info "Setting keymap to \"#{@keymap}\"..."
39
+ writing_rc_conf
40
+ writing_vconsole_conf
41
+ writing_conf_d_keymaps
42
+ @log.result_ok
43
+ end
44
+
45
+ def writing_rc_conf
46
+ return unless File.exist? @rc_conf
47
+
48
+ echo_a @rc_conf, "KEYMAP=\"#{@keymap}\""
49
+ end
50
+
51
+ def writing_vconsole_conf
52
+ return unless Helpers.systemd?
53
+
54
+ echo_a @vconsole_conf, "KEYMAP=\"#{@keymap}\""
55
+ end
56
+
57
+ def writing_conf_d_keymaps
58
+ return unless File.exist? @conf_d
59
+
60
+ sed @conf_d, /^keymap=/, "keymap=\"#{@keymap}\""
61
+ end
62
+
63
+ private
64
+
65
+ def search_dir
66
+ case OPTIONS[:os]
67
+ when 'gentoo' then @keymaps_dir = '/usr/share/keymaps'
68
+ when 'void' then @keymaps_dir = '/usr/share/kbd/keymaps'
69
+ else
70
+ @log.fatal('OPTIONS[:os] not supported yet.')
71
+ end
72
+
73
+ File.exist? "#{OPTIONS[:mountpoint]}#{@keymaps_dir}" ||
74
+ @log.fatal("No dir keymaps #{@keymaps_dir} found.")
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nito'
4
+
5
+ # Gentoo: https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base#Locale_generation
6
+ # Void: https://docs.voidlinux.org/config/locales.html#locales-and-translations
7
+ module Getch
8
+ module Config
9
+ class Locale
10
+ include NiTo
11
+
12
+ # Gentoo use i18n_supported
13
+ # Void use libc_locale
14
+ def initialize
15
+ @log = Log.new
16
+ @i18n_supported = "#{OPTIONS[:mountpoint]}/usr/share/i18n/SUPPORTED"
17
+ @libc_locales = "#{OPTIONS[:mountpoint]}/etc/default/libc-locales"
18
+ @locale_conf = "#{OPTIONS[:mountpoint]}/etc/locale.conf"
19
+ @i18n = nil
20
+ @lang = nil
21
+ x
22
+ end
23
+
24
+ def x
25
+ @log.info "Configuring locales...\n"
26
+ search_locale
27
+ apply_conf
28
+ end
29
+
30
+ protected
31
+
32
+ def search_locale
33
+ search_i18n
34
+ search_libc
35
+ lang
36
+ end
37
+
38
+ def apply_conf
39
+ return if OPTIONS[:musl]
40
+
41
+ File.exist?("#{OPTIONS[:mountpoint]}/etc/locale.gen") && write_locale_gen
42
+ File.exist?(@libc_locales) && write_libc_locales
43
+ end
44
+
45
+ def write_locale_gen
46
+ @log.fatal("No UTF8 locale found for #{OPTIONS[:language]}") unless @i18n
47
+
48
+ @log.info "Using locale #{@i18n}...\n"
49
+ echo "#{OPTIONS[:mountpoint]}/etc/locale.gen", @i18n
50
+ locale_conf
51
+ Getch::Chroot.new('locale-gen')
52
+ end
53
+
54
+ def write_libc_locales
55
+ @log.fatal("No UTF8 locale found for #{OPTIONS[:language]}") unless @i18n
56
+
57
+ @log.info "Using locale #{@i18n}...\n"
58
+ echo @libc_locales, @i18n
59
+ locale_conf
60
+ Getch::Chroot.new('xbps-reconfigure -f glibc-locales')
61
+ end
62
+
63
+ private
64
+
65
+ def search_i18n
66
+ return unless File.exist? @i18n_supported
67
+
68
+ File.open(@i18n_supported).each do |l|
69
+ @i18n = l.chomp if l =~ /#{OPTIONS[:language]}.*UTF-8$/
70
+ end
71
+ end
72
+
73
+ def search_libc
74
+ return unless File.exist? @libc_locales
75
+
76
+ File.open(@libc_locales).each do |l|
77
+ @i18n = l.tr('#', '').chomp if l =~ /\#?#{OPTIONS[:language]}.*UTF-8/
78
+ end
79
+ end
80
+
81
+ def lang
82
+ return unless @i18n
83
+
84
+ lang = @i18n.split(' ')
85
+ @lang = lang[0]
86
+ end
87
+
88
+ def locale_conf
89
+ return unless Helpers.systemd?
90
+
91
+ echo @locale_conf, "LANG=#{@lang}"
92
+ echo_a @locale_conf, 'LC_COLLATE=C.UTF-8'
93
+ end
94
+ end
95
+ end
96
+ end