getch 0.1.3 → 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 +75 -35
  4. data/assets/network-stack.conf +63 -0
  5. data/assets/system.conf +38 -0
  6. data/bin/getch +14 -4
  7. data/lib/clean.rb +149 -0
  8. data/lib/cmdline.rb +128 -0
  9. data/lib/cryptsetup.rb +132 -0
  10. data/lib/devs.rb +199 -0
  11. data/lib/dracut/encrypt.rb +36 -0
  12. data/lib/dracut/hybrid.rb +15 -0
  13. data/lib/dracut/lvm.rb +14 -0
  14. data/lib/dracut/minimal.rb +11 -0
  15. data/lib/dracut/root.rb +45 -0
  16. data/lib/dracut/zfs.rb +35 -0
  17. data/lib/dracut.rb +11 -0
  18. data/lib/fstab/encrypt.rb +44 -0
  19. data/lib/fstab/hybrid.rb +34 -0
  20. data/lib/fstab/lvm.rb +25 -0
  21. data/lib/fstab/minimal.rb +6 -0
  22. data/lib/fstab/root.rb +93 -0
  23. data/lib/fstab/zfs.rb +23 -0
  24. data/lib/fstab.rb +11 -0
  25. data/lib/getch/assembly.rb +150 -0
  26. data/lib/getch/command.rb +94 -124
  27. data/lib/getch/config/account.rb +39 -0
  28. data/lib/getch/config/dhcp.rb +104 -0
  29. data/lib/getch/config/grub.rb +42 -0
  30. data/lib/getch/config/iwd.rb +60 -0
  31. data/lib/getch/config/keymap.rb +78 -0
  32. data/lib/getch/config/locale.rb +96 -0
  33. data/lib/getch/config/portage.rb +90 -0
  34. data/lib/getch/config/pre_network.rb +37 -0
  35. data/lib/getch/config/timezone.rb +52 -0
  36. data/lib/getch/config/void.rb +11 -0
  37. data/lib/getch/config.rb +19 -53
  38. data/lib/getch/device.rb +67 -0
  39. data/lib/getch/filesystem/ext4/encrypt/config.rb +11 -68
  40. data/lib/getch/filesystem/ext4/encrypt/deps.rb +17 -25
  41. data/lib/getch/filesystem/ext4/encrypt/device.rb +13 -5
  42. data/lib/getch/filesystem/ext4/encrypt/format.rb +8 -15
  43. data/lib/getch/filesystem/ext4/encrypt/mount.rb +9 -13
  44. data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -82
  45. data/lib/getch/filesystem/ext4/encrypt/void.rb +63 -0
  46. data/lib/getch/filesystem/ext4/encrypt.rb +4 -0
  47. data/lib/getch/filesystem/ext4/hybrid/config.rb +27 -0
  48. data/lib/getch/filesystem/ext4/hybrid/deps.rb +55 -0
  49. data/lib/getch/filesystem/ext4/hybrid/device.rb +24 -0
  50. data/lib/getch/filesystem/ext4/hybrid/format.rb +23 -0
  51. data/lib/getch/filesystem/ext4/hybrid/mount.rb +21 -0
  52. data/lib/getch/filesystem/ext4/hybrid/partition.rb +27 -0
  53. data/lib/getch/filesystem/ext4/hybrid/void.rb +62 -0
  54. data/lib/getch/filesystem/ext4/hybrid.rb +19 -0
  55. data/lib/getch/filesystem/ext4/lvm/config.rb +25 -0
  56. data/lib/getch/filesystem/ext4/lvm/deps.rb +56 -0
  57. data/lib/getch/filesystem/ext4/lvm/device.rb +28 -0
  58. data/lib/getch/filesystem/ext4/lvm/format.rb +21 -0
  59. data/lib/getch/filesystem/ext4/lvm/mount.rb +21 -0
  60. data/lib/getch/filesystem/ext4/lvm/partition.rb +28 -0
  61. data/lib/getch/filesystem/{lvm.rb → ext4/lvm.rb} +8 -3
  62. data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
  63. data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +4 -3
  64. data/lib/getch/filesystem/ext4/minimal/device.rb +22 -0
  65. data/lib/getch/filesystem/ext4/minimal/format.rb +23 -0
  66. data/lib/getch/filesystem/ext4/minimal/mount.rb +21 -0
  67. data/lib/getch/filesystem/ext4/minimal/partition.rb +28 -0
  68. data/lib/getch/filesystem/ext4/minimal.rb +19 -0
  69. data/lib/getch/filesystem/ext4.rb +9 -6
  70. data/lib/getch/filesystem/zfs/encrypt/config.rb +12 -57
  71. data/lib/getch/filesystem/zfs/encrypt/deps.rb +7 -86
  72. data/lib/getch/filesystem/zfs/encrypt/device.rb +9 -45
  73. data/lib/getch/filesystem/zfs/encrypt/format.rb +8 -90
  74. data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -34
  75. data/lib/getch/filesystem/zfs/encrypt/partition.rb +8 -50
  76. data/lib/getch/filesystem/zfs/encrypt.rb +4 -0
  77. data/lib/getch/filesystem/zfs/minimal/config.rb +37 -0
  78. data/lib/getch/filesystem/zfs/minimal/deps.rb +126 -0
  79. data/lib/getch/filesystem/zfs/minimal/device.rb +24 -0
  80. data/lib/getch/filesystem/zfs/minimal/format.rb +23 -0
  81. data/lib/getch/filesystem/zfs/minimal/mount.rb +23 -0
  82. data/lib/getch/filesystem/zfs/minimal/partition.rb +23 -0
  83. data/lib/getch/filesystem/zfs/minimal.rb +19 -0
  84. data/lib/getch/filesystem/zfs.rb +3 -6
  85. data/lib/getch/filesystem.rb +2 -6
  86. data/lib/getch/gentoo/bootloader.rb +47 -0
  87. data/lib/getch/gentoo/finalize.rb +25 -0
  88. data/lib/getch/gentoo/post_config.rb +75 -0
  89. data/lib/getch/gentoo/pre_config.rb +37 -0
  90. data/lib/getch/gentoo/services.rb +18 -0
  91. data/lib/getch/gentoo/sources.rb +82 -52
  92. data/lib/getch/gentoo/tarball.rb +91 -0
  93. data/lib/getch/gentoo/terraform.rb +34 -0
  94. data/lib/getch/gentoo/update.rb +54 -0
  95. data/lib/getch/gentoo/use.rb +11 -12
  96. data/lib/getch/gentoo/use_flag.rb +74 -52
  97. data/lib/getch/gentoo.rb +11 -63
  98. data/lib/getch/guard.rb +71 -0
  99. data/lib/getch/helpers.rb +128 -48
  100. data/lib/getch/log.rb +91 -26
  101. data/lib/getch/options.rb +79 -40
  102. data/lib/getch/states.rb +37 -10
  103. data/lib/getch/tree.rb +56 -0
  104. data/lib/getch/version.rb +1 -1
  105. data/lib/getch/void/bootloader.rb +18 -0
  106. data/lib/getch/void/finalize.rb +31 -0
  107. data/lib/getch/void/post_config.rb +19 -0
  108. data/lib/getch/void/pre_config.rb +18 -0
  109. data/lib/getch/void/services.rb +18 -0
  110. data/lib/getch/void/tarball.rb +89 -0
  111. data/lib/getch/void/terraform.rb +28 -0
  112. data/lib/getch/void/update.rb +33 -0
  113. data/lib/getch/void.rb +15 -0
  114. data/lib/getch.rb +104 -92
  115. data/lib/luks.rb +239 -0
  116. data/lib/lvm2.rb +112 -0
  117. data/lib/mkfs/zfs.rb +167 -0
  118. data/lib/mkfs.rb +140 -0
  119. data/lib/mountfs.rb +154 -0
  120. data/lib/nito.rb +131 -0
  121. data/lib/sgdisk.rb +160 -0
  122. data.tar.gz.sig +0 -0
  123. metadata +96 -45
  124. metadata.gz.sig +0 -0
  125. data/.gitignore +0 -2
  126. data/CHANGELOG.md +0 -90
  127. data/Rakefile +0 -21
  128. data/bin/setup.sh +0 -90
  129. data/getch.gemspec +0 -25
  130. data/lib/getch/filesystem/clean.rb +0 -51
  131. data/lib/getch/filesystem/device.rb +0 -61
  132. data/lib/getch/filesystem/ext4/config.rb +0 -58
  133. data/lib/getch/filesystem/ext4/deps.rb +0 -22
  134. data/lib/getch/filesystem/ext4/format.rb +0 -28
  135. data/lib/getch/filesystem/ext4/mount.rb +0 -23
  136. data/lib/getch/filesystem/ext4/partition.rb +0 -52
  137. data/lib/getch/filesystem/lvm/config.rb +0 -59
  138. data/lib/getch/filesystem/lvm/deps.rb +0 -42
  139. data/lib/getch/filesystem/lvm/device.rb +0 -43
  140. data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -71
  141. data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -46
  142. data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -46
  143. data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -32
  144. data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -25
  145. data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -80
  146. data/lib/getch/filesystem/lvm/encrypt.rb +0 -15
  147. data/lib/getch/filesystem/lvm/format.rb +0 -29
  148. data/lib/getch/filesystem/lvm/mount.rb +0 -23
  149. data/lib/getch/filesystem/lvm/partition.rb +0 -69
  150. data/lib/getch/filesystem/mount.rb +0 -56
  151. data/lib/getch/filesystem/partition.rb +0 -77
  152. data/lib/getch/filesystem/zfs/config.rb +0 -57
  153. data/lib/getch/filesystem/zfs/deps.rb +0 -95
  154. data/lib/getch/filesystem/zfs/device.rb +0 -58
  155. data/lib/getch/filesystem/zfs/format.rb +0 -114
  156. data/lib/getch/filesystem/zfs/mount.rb +0 -48
  157. data/lib/getch/filesystem/zfs/partition.rb +0 -64
  158. data/lib/getch/gentoo/boot.rb +0 -109
  159. data/lib/getch/gentoo/chroot.rb +0 -77
  160. data/lib/getch/gentoo/config.rb +0 -129
  161. data/lib/getch/gentoo/stage.rb +0 -74
data/lib/fstab/zfs.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Fstab
2
+ class Zfs < Root
3
+ def initialize(devs, options)
4
+ super
5
+ @encrypt = options[:encrypt]
6
+ end
7
+
8
+ def generate
9
+ @log.info 'Generating fstab...'
10
+ write_efi
11
+ write_swap
12
+ @log.result_ok
13
+ end
14
+
15
+ def write_swap
16
+ uuid = gen_uuid @swap
17
+ @encrypt ?
18
+ line = "/dev/mapper/swap-luks none swap sw 0 0" :
19
+ line = "UUID=#{uuid} swap swap rw,noatime,discard 0 0"
20
+ echo_a @conf, line
21
+ end
22
+ end
23
+ end
data/lib/fstab.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_litteral: true
2
+
3
+ module Fstab
4
+ end
5
+
6
+ require_relative 'fstab/root'
7
+ require_relative 'fstab/minimal'
8
+ require_relative 'fstab/lvm'
9
+ require_relative 'fstab/encrypt'
10
+ require_relative 'fstab/hybrid'
11
+ require_relative 'fstab/zfs'
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'clean'
4
+ require 'nito'
5
+ require 'cryptsetup'
6
+
7
+ module Getch
8
+ class Assembly
9
+ include NiTo
10
+
11
+ def initialize
12
+ @os = Tree::Os.new.select
13
+ @fs = Tree::FS.new.select
14
+ @state = Getch::States.new
15
+ Getch::Device.new
16
+ init_devs
17
+ end
18
+
19
+ def init_devs
20
+ DEVS[:root] && return
21
+
22
+ @fs::Device.new
23
+ DEVS[:root] || Log.new.fatal('No root, device prob !')
24
+ end
25
+
26
+ def clean
27
+ return if STATES[:partition]
28
+
29
+ print "\nPartition and format disk #{OPTIONS[:disk]}, this will erase all data, continue? (y,N) "
30
+ case gets.chomp
31
+ when /^y|^Y/
32
+ else
33
+ exit
34
+ end
35
+
36
+ Clean.new(OPTIONS).x
37
+ end
38
+
39
+ def partition
40
+ return if STATES[:partition]
41
+
42
+ @fs::Partition.new
43
+ @state.partition
44
+ end
45
+
46
+ def format
47
+ return if STATES[:format]
48
+
49
+ @fs::Format.new
50
+ @state.format
51
+ end
52
+
53
+ def mount
54
+ return if STATES[:mount]
55
+
56
+ @fs::Mount.new
57
+ @state.mount
58
+ end
59
+
60
+ def tarball
61
+ return if STATES[:tarball]
62
+
63
+ @os::Tarball.new.x
64
+ @state.tarball
65
+ end
66
+
67
+ # pre_config
68
+ # Pre configuration before updates and install packages
69
+ # Can contain config for a repository, CPU compilation flags, etc...
70
+ def pre_config
71
+ return if STATES[:pre_config]
72
+
73
+ @os::PreConfig.new
74
+ @state.pre_config
75
+ end
76
+
77
+ # update
78
+ # Synchronise and Update the new system
79
+ def update
80
+ return if STATES[:update]
81
+
82
+ Helpers.mount_all
83
+ @os::Update.new
84
+ @state.update
85
+ end
86
+
87
+ def post_config
88
+ return if STATES[:post_config]
89
+
90
+ @os::PostConfig.new
91
+ @state.post_config
92
+ end
93
+
94
+ # terraform
95
+ # Install all the required packages
96
+ # Also add services
97
+ def terraform
98
+ return if STATES[:terraform]
99
+
100
+ #@fs::PreDeps.new
101
+ @os::Terraform.new
102
+ @fs::Deps.new
103
+ @state.terraform
104
+ end
105
+
106
+ def services
107
+ return if STATES[:services]
108
+
109
+ @os::Services.new
110
+ @state.services
111
+ end
112
+
113
+ # Luks_keys
114
+ # Install external keys to avoid enter password multiple times
115
+ def luks_keys
116
+ return if not OPTIONS[:encrypt] or OPTIONS[:fs] == 'zfs'
117
+
118
+ return if STATES[:luks_keys]
119
+
120
+ CryptSetup.new(DEVS, OPTIONS).keys
121
+ @state.luks_keys
122
+ end
123
+
124
+ # bootloader
125
+ # Install and configure Grub2 or Systemd-boot with Dracut
126
+ # Adding keys for Luks
127
+ def bootloader
128
+ return if STATES[:bootloader]
129
+
130
+ bootloader = @os::Bootloader.new
131
+ bootloader.dependencies
132
+ @fs::Config.new
133
+ bootloader.install
134
+ @state.bootloader
135
+ end
136
+
137
+ # finalize
138
+ # Password for root, etc
139
+ def finalize
140
+ return if STATES[:finalize]
141
+
142
+ @os::Finalize.new
143
+ puts
144
+ puts '[*!*] Installation finished [*!*]'
145
+ puts
146
+ @fs.end
147
+ @state.finalize
148
+ end
149
+ end
150
+ end
data/lib/getch/command.rb CHANGED
@@ -1,177 +1,147 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open3'
4
+ require 'nito'
2
5
 
3
6
  module Getch
4
7
  class Command
5
- def initialize(cmd)
6
- @cmd = cmd
7
- @block_size = 1024
8
+ attr_reader :res
9
+
10
+ def initialize(*args)
11
+ @cmd = args.join(' ')
8
12
  @log = Getch::Log.new
13
+ x
9
14
  end
10
15
 
11
- def run!
12
- @log.info "Running command: " + @cmd.gsub(/\"/, '')
13
-
14
- Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
15
- stdin.close_write
16
- code = wait_thr.value
17
-
18
- # only stderr
19
- begin
20
- @log.debug stderr.readline until stderr.eof.nil?
21
- rescue EOFError
22
- end
16
+ def to_s
17
+ @res
18
+ end
23
19
 
24
- begin
25
- files = [stdout, stderr]
20
+ protected
26
21
 
27
- until all_eof(files) do
28
- ready = IO.select(files)
22
+ def x
23
+ @log.info 'Exec: ' + @cmd
24
+ cmd = build_cmd
29
25
 
30
- if ready
31
- readable = ready[0]
32
- # writable = ready[1]
33
- # exceptions = ready[2]
26
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
27
+ stdin.close_write
28
+ code = wait_thr.value
34
29
 
35
- display_lines(readable)
36
- end
30
+ unless code.success?
31
+ begin
32
+ @log.debug stderr.readline until stderr.eof.nil?
33
+ rescue EOFError
34
+ print
37
35
  end
38
- rescue IOError => e
39
- puts "IOError: #{e}"
40
36
  end
41
37
 
42
- unless code.success?
43
- @log.fatal "Running #{@cmd}"
44
- exit 1
38
+ if code.success?
39
+ @log.result_ok
40
+ @res = stdout.read.chomp
41
+ return
45
42
  end
46
43
 
47
- @log.debug "Done - #{@cmd} - #{code}"
44
+ puts
45
+ @log.error "#{@cmd} - #{code}"
46
+ @log.fatal "Running #{@cmd}"
48
47
  end
49
48
  end
50
49
 
51
50
  private
52
51
 
53
- # Returns true if all files are EOF
54
- def all_eof(files)
55
- files.find { |f| !f.eof }.nil?
56
- end
57
-
58
- def display_lines(block)
59
- block.each do |f|
60
- begin
61
- data = f.read_nonblock(@block_size)
62
- puts data if DEFAULT_OPTIONS[:verbose]
63
- rescue EOFError
64
- puts ""
65
- rescue => e
66
- puts "Fatal - #{e}"
67
- end
68
- end
52
+ def build_cmd
53
+ @cmd
69
54
  end
70
55
  end
71
56
 
72
- # Use system, the only ruby method to display stdout with colors !
73
- class Emerge
57
+ class Bask
74
58
  def initialize(cmd)
75
- @gentoo = MOUNTPOINT
76
59
  @cmd = cmd
77
- @log = Getch::Log.new
60
+ @log = Log.new
61
+ @version = '0.6'
62
+ @config = "#{MOUNTPOINT}/etc/kernel/config.d"
63
+ download_bask unless Dir.exist? "#{MOUNTPOINT}/root/bask-#{@version}"
78
64
  end
79
65
 
80
- def run!
81
- @log.info "Running emerge: #{@cmd}"
82
- system("chroot", @gentoo, "/bin/bash", "-c", "source /etc/profile && #{@cmd}")
83
- read_exit
66
+ def cp
67
+ NiTo.mkdir @config
68
+ NiTo.cp(
69
+ "#{MOUNTPOINT}/root/bask-#{@version}/config.d/#{@cmd}",
70
+ "#{@config}/#{@cmd}"
71
+ )
84
72
  end
85
73
 
86
- def pkg!
87
- @log.info "Running emerge pkg: #{@cmd}"
88
- system("chroot", @gentoo, "/bin/bash", "-c", "source /etc/profile && emerge --changed-use #{@cmd}")
89
- read_exit
74
+ def add(content)
75
+ Helpers.add_file "#{@config}/#{@cmd}", content
90
76
  end
91
77
 
92
78
  private
93
79
 
94
- def read_exit
95
- if $?.exitstatus > 0
96
- @log.fatal "Running #{@cmd}"
97
- else
98
- @log.info "Done #{@cmd}"
99
- end
100
- end
101
- end
80
+ def download_bask
81
+ @log.info "Installing Bask...\n"
82
+ url = "https://github.com/szorfein/bask/archive/refs/tags/#{@version}.tar.gz"
83
+ file = "bask-#{@version}.tar.gz"
102
84
 
103
- class Make
104
- def initialize(cmd)
105
- @gentoo = MOUNTPOINT
106
- @cmd = cmd
107
- @log = Getch::Log.new
85
+ Dir.chdir("#{MOUNTPOINT}/root")
86
+ Helpers.get_file_online(url, file)
87
+ Getch::Command.new("tar xzf #{file}")
108
88
  end
89
+ end
109
90
 
110
- def run!
111
- @log.info "Running Make: #{@cmd}"
112
- cmd = "chroot #{@gentoo} /bin/bash -c \"source /etc/profile \
113
- && env-update \
114
- && cd /usr/src/linux \
115
- && #{@cmd}\""
116
- Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
117
- while line = stdout_err.gets
118
- puts line
119
- end
120
-
121
- exit_status = wait_thr.value
122
- unless exit_status.success?
123
- @log.fatal "Running #{cmd}"
124
- exit 1
125
- end
91
+ class Chroot < Command
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}\""
126
99
  end
127
100
  end
128
101
  end
129
102
 
130
- class Bask
131
- def initialize(cmd)
132
- @gentoo = MOUNTPOINT
133
- @cmd = cmd
134
- @log = Getch::Log.new
135
- @version = "0.5"
103
+ class ChrootOutput
104
+ def initialize(*args)
105
+ @cmd = args.join(' ')
106
+ @log = Log.new
107
+ x
136
108
  end
137
109
 
138
- def run!
139
- download_bask if ! Dir.exist? "#{MOUNTPOINT}/root/bask-#{@version}"
140
- @log.info "Running Bask: #{@cmd}"
141
- cmd = "chroot #{@gentoo} /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 |stdin, stdout_err, wait_thr|
146
- while line = stdout_err.gets
147
- puts line
148
- end
110
+ private
149
111
 
150
- exit_status = wait_thr.value
151
- unless exit_status.success?
152
- @log.fatal "Running #{cmd}"
153
- exit 1
154
- end
155
- end
156
- end
112
+ def x
113
+ msg
114
+ system('chroot', OPTIONS[:mountpoint], '/bin/bash', '-c', other_args)
115
+ $?.success? && return
157
116
 
158
- private
117
+ @log.fatal "Running #{@cmd}"
118
+ end
159
119
 
160
- def download_bask
161
- @log.info "Installing Bask..."
162
- url = "https://github.com/szorfein/bask/archive/v#{@version}.tar.gz"
163
- file = "bask-#{@version}.tar.gz"
120
+ def msg
121
+ @log.info "Exec: #{@cmd}...\n"
122
+ end
164
123
 
165
- Dir.chdir("#{MOUNTPOINT}/root")
166
- Helpers::get_file_online(url, file)
167
- Getch::Command.new("tar xzf #{file}").run!
124
+ def other_args
125
+ case OPTIONS[:os]
126
+ when 'gentoo' then "source /etc/profile && #{@cmd}"
127
+ when 'void' then @cmd
128
+ end
168
129
  end
169
130
  end
170
131
 
171
- class Chroot < Command
172
- def initialize(cmd)
173
- super
174
- @cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile; #{cmd}\""
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
175
145
  end
176
146
  end
177
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