getch 0.1.9 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/CHANGELOG.md +132 -0
  4. data/LICENSE +10 -0
  5. data/README.md +35 -29
  6. data/bin/getch +8 -6
  7. data/getch.gemspec +31 -0
  8. data/lib/clean.rb +149 -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 +88 -128
  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 +0 -36
  37. data/lib/getch/config.rb +16 -37
  38. data/lib/getch/device.rb +67 -0
  39. data/lib/getch/filesystem/ext4/encrypt/config.rb +9 -71
  40. data/lib/getch/filesystem/ext4/encrypt/deps.rb +15 -25
  41. data/lib/getch/filesystem/ext4/encrypt/device.rb +11 -5
  42. data/lib/getch/filesystem/ext4/encrypt/format.rb +6 -15
  43. data/lib/getch/filesystem/ext4/encrypt/mount.rb +7 -11
  44. data/lib/getch/filesystem/ext4/encrypt/partition.rb +10 -76
  45. data/lib/getch/filesystem/ext4/encrypt/void.rb +0 -38
  46. data/lib/getch/filesystem/ext4/encrypt.rb +2 -1
  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/{lvm/encrypt → ext4/hybrid}/void.rb +0 -39
  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} +6 -4
  62. data/lib/getch/filesystem/ext4/minimal/config.rb +25 -0
  63. data/lib/getch/filesystem/ext4/{device.rb → minimal/deps.rb} +3 -1
  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 +7 -7
  70. data/lib/getch/filesystem/zfs/encrypt/config.rb +10 -39
  71. data/lib/getch/filesystem/zfs/encrypt/deps.rb +4 -55
  72. data/lib/getch/filesystem/zfs/encrypt/device.rb +7 -51
  73. data/lib/getch/filesystem/zfs/encrypt/format.rb +6 -90
  74. data/lib/getch/filesystem/zfs/encrypt/mount.rb +16 -35
  75. data/lib/getch/filesystem/zfs/encrypt/partition.rb +6 -54
  76. data/lib/getch/filesystem/zfs/encrypt.rb +2 -1
  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 +1 -7
  85. data/lib/getch/filesystem.rb +0 -6
  86. data/lib/getch/gentoo/bootloader.rb +23 -44
  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 +39 -33
  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 +9 -6
  96. data/lib/getch/gentoo/use_flag.rb +17 -20
  97. data/lib/getch/gentoo.rb +9 -75
  98. data/lib/getch/guard.rb +3 -3
  99. data/lib/getch/helpers.rb +63 -115
  100. data/lib/getch/log.rb +87 -25
  101. data/lib/getch/options.rb +41 -11
  102. data/lib/getch/states.rb +28 -8
  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/{stage.rb → tarball.rb} +34 -14
  111. data/lib/getch/void/terraform.rb +28 -0
  112. data/lib/getch/void/update.rb +33 -0
  113. data/lib/getch/void.rb +9 -59
  114. data/lib/getch.rb +58 -90
  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 +144 -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 +113 -74
  124. metadata.gz.sig +0 -0
  125. data/lib/getch/config/gentoo.rb +0 -58
  126. data/lib/getch/filesystem/clean.rb +0 -58
  127. data/lib/getch/filesystem/device.rb +0 -63
  128. data/lib/getch/filesystem/ext4/config.rb +0 -62
  129. data/lib/getch/filesystem/ext4/deps.rb +0 -24
  130. data/lib/getch/filesystem/ext4/format.rb +0 -31
  131. data/lib/getch/filesystem/ext4/mount.rb +0 -26
  132. data/lib/getch/filesystem/ext4/partition.rb +0 -55
  133. data/lib/getch/filesystem/ext4/void.rb +0 -44
  134. data/lib/getch/filesystem/lvm/config.rb +0 -44
  135. data/lib/getch/filesystem/lvm/deps.rb +0 -44
  136. data/lib/getch/filesystem/lvm/device.rb +0 -45
  137. data/lib/getch/filesystem/lvm/encrypt/config.rb +0 -74
  138. data/lib/getch/filesystem/lvm/encrypt/deps.rb +0 -49
  139. data/lib/getch/filesystem/lvm/encrypt/device.rb +0 -48
  140. data/lib/getch/filesystem/lvm/encrypt/format.rb +0 -35
  141. data/lib/getch/filesystem/lvm/encrypt/mount.rb +0 -27
  142. data/lib/getch/filesystem/lvm/encrypt/partition.rb +0 -84
  143. data/lib/getch/filesystem/lvm/encrypt.rb +0 -18
  144. data/lib/getch/filesystem/lvm/format.rb +0 -32
  145. data/lib/getch/filesystem/lvm/mount.rb +0 -26
  146. data/lib/getch/filesystem/lvm/partition.rb +0 -72
  147. data/lib/getch/filesystem/lvm/void.rb +0 -46
  148. data/lib/getch/filesystem/mount.rb +0 -63
  149. data/lib/getch/filesystem/partition.rb +0 -85
  150. data/lib/getch/filesystem/zfs/config.rb +0 -43
  151. data/lib/getch/filesystem/zfs/deps.rb +0 -67
  152. data/lib/getch/filesystem/zfs/device.rb +0 -66
  153. data/lib/getch/filesystem/zfs/encrypt/void.rb +0 -97
  154. data/lib/getch/filesystem/zfs/format.rb +0 -117
  155. data/lib/getch/filesystem/zfs/mount.rb +0 -47
  156. data/lib/getch/filesystem/zfs/partition.rb +0 -69
  157. data/lib/getch/filesystem/zfs/void.rb +0 -81
  158. data/lib/getch/gentoo/boot.rb +0 -64
  159. data/lib/getch/gentoo/chroot.rb +0 -75
  160. data/lib/getch/gentoo/config.rb +0 -167
  161. data/lib/getch/gentoo/stage.rb +0 -73
  162. data/lib/getch/void/boot.rb +0 -84
  163. data/lib/getch/void/chroot.rb +0 -56
  164. data/lib/getch/void/config.rb +0 -90
@@ -1,167 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
- require 'tempfile'
5
- require 'securerandom'
6
-
7
- module Getch
8
- module Gentoo
9
- class Config
10
- def initialize
11
- @make = "#{MOUNTPOINT}/etc/portage/make.conf"
12
- @log = Getch::Log.new
13
- end
14
-
15
- def portage
16
- grub_pc = Helpers.efi? ? '' : 'GRUB_PLATFORMS="pc"'
17
- nproc = `nproc`.chomp()
18
-
19
- # Add cpu name
20
- cpu=`chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile ; gcc -c -Q -march=native --help=target | grep march\" | awk '{print $2}' | head -1`.chomp
21
- raise 'Error, no cpu found' unless cpu || cpu == ''
22
-
23
- @log.debug "CPU found ==> #{cpu}"
24
-
25
- tmp = Tempfile.new('make.conf')
26
-
27
- File.open(@make).each { |l|
28
- if l.match(/^COMMON_FLAGS/)
29
- File.write(tmp, "COMMON_FLAGS=\"-march=#{cpu} -O2 -pipe -fomit-frame-pointer\"\n", mode: 'a')
30
- else
31
- File.write(tmp, l, mode: 'a')
32
- end
33
- }
34
-
35
- FileUtils.copy_file(tmp, @make)
36
-
37
- # Add the rest
38
- data = [
39
- '',
40
- "MAKEOPTS=\"-j#{nproc}\"",
41
- 'ACCEPT_KEYWORDS="amd64"',
42
- 'INPUT_DEVICES="libinput"',
43
- 'USE="${USE} audit"',
44
- grub_pc
45
- ]
46
- File.write(@make, data.join("\n"), mode: 'a')
47
- end
48
-
49
- # Write a repos.conf/gentoo.conf with the gpg verification
50
- def repo
51
- src = "#{MOUNTPOINT}/usr/share/portage/config/repos.conf"
52
- dest = "#{MOUNTPOINT}/etc/portage/repos.conf"
53
- FileUtils.mkdir dest, mode: 0644 unless Dir.exist?(dest)
54
- tmp = Tempfile.new('gentoo.conf')
55
- line_count = 0
56
-
57
- File.open(src).each { |l|
58
- File.write(tmp, "sync-allow-hardlinks = yes\n", mode: 'a') if line_count == 2
59
- if l.match(/^sync-type = rsync/)
60
- File.write(tmp, "sync-type = webrsync\n", mode: 'a')
61
- else
62
- File.write(tmp, l, mode: 'a')
63
- end
64
- line_count += 1
65
- }
66
-
67
- FileUtils.copy_file(tmp, "#{dest}/gentoo.conf")
68
- end
69
-
70
- def network
71
- src = '/etc/resolv.conf'
72
- dest = "#{MOUNTPOINT}/etc/resolv.conf"
73
- FileUtils.copy_file(src, dest)
74
- end
75
-
76
- def systemd
77
- control_options
78
- Helpers.echo "#{MOUNTPOINT}/etc/locale.gen", @utf8
79
- Helpers.echo "#{MOUNTPOINT}/etc/locale.conf", "LANG=#{@lang}"
80
- Helpers.echo_a "#{MOUNTPOINT}/etc/locale.conf", 'LC_COLLATE=C'
81
- File.write("#{MOUNTPOINT}/etc/timezone", "#{Getch::OPTIONS[:zoneinfo]}\n")
82
- File.write("#{MOUNTPOINT}/etc/vconsole.conf", "KEYMAP=#{Getch::OPTIONS[:keymap]}\n")
83
- end
84
-
85
- def hostname
86
- id = SecureRandom.hex(2)
87
- File.write("#{MOUNTPOINT}/etc/hostname", "gentoo-hatch-#{id}")
88
- end
89
-
90
- def portage_fs
91
- portage = "#{MOUNTPOINT}/etc/portage"
92
- Helpers.mkdir("#{portage}/package.use")
93
- Helpers.mkdir("#{portage}/package.accept_keywords")
94
- Helpers.mkdir("#{portage}/package.unmask")
95
-
96
- Helpers.add_file("#{portage}/package.use/zzz_via_autounmask")
97
- Helpers.add_file("#{portage}/package.accept_keywords/zzz_via_autounmask")
98
- Helpers.add_file("#{portage}/package.unmask/zzz_via_autounmask")
99
- end
100
-
101
- # https://wiki.gentoo.org/wiki/Signed_kernel_module_support
102
- def portage_bashrc
103
- conf = "#{MOUNTPOINT}/etc/portage/bashrc"
104
- content = %q{
105
- function pre_pkg_preinst() {
106
- # This hook signs any out-of-tree kernel modules.
107
- if [[ "$(type -t linux-mod_pkg_preinst)" != "function" ]]; then
108
- # The package does not seem to install any kernel modules.
109
- return
110
- fi
111
- # Get the signature algorithm used by the kernel.
112
- local module_sig_hash="$(grep -Po '(?<=CONFIG_MODULE_SIG_HASH=").*(?=")' "${KERNEL_DIR}/.config")"
113
- # Get the key file used by the kernel.
114
- local module_sig_key="$(grep -Po '(?<=CONFIG_MODULE_SIG_KEY=").*(?=")' "${KERNEL_DIR}/.config")"
115
- module_sig_key="${module_sig_key:-certs/signing_key.pem}"
116
- # Path to the key file or PKCS11 URI
117
- if [[ "${module_sig_key#pkcs11:}" == "${module_sig_key}" && "${module_sig_key#/}" == "${module_sig_key}" ]]; then
118
- local key_path="${KERNEL_DIR}/${module_sig_key}"
119
- else
120
- local key_path="${module_sig_key}"
121
- fi
122
- # Certificate path
123
- local cert_path="${KERNEL_DIR}/certs/signing_key.x509"
124
- # Sign all installed modules before merging.
125
- find "${D%/}/${INSDESTTREE#/}/" -name "*.ko" -exec "${KERNEL_DIR}/scripts/sign-file" "${module_sig_hash}" "${key_path}" "${cert_path}" '{}' \;
126
- }
127
- }
128
-
129
- f = File.new(conf, 'w')
130
- f.write("#{content}\n")
131
- f.chmod(0700)
132
- f.close
133
- end
134
-
135
- private
136
-
137
- def control_options
138
- search_zone(Getch::OPTIONS[:zoneinfo])
139
- search_utf8(Getch::OPTIONS[:language])
140
- search_key(Getch::OPTIONS[:keymap])
141
- end
142
-
143
- def search_key(keys)
144
- @keymap = nil
145
- Dir.glob("#{MOUNTPOINT}/usr/share/keymaps/**/#{keys}.map.gz") { |f|
146
- @keymap = f
147
- }
148
- raise ArgumentError, "No keymap #{@keymap} found" unless @keymap
149
- end
150
-
151
- def search_zone(zone)
152
- unless File.exist? "#{MOUNTPOINT}/usr/share/zoneinfo/#{zone}"
153
- raise ArgumentError, "Zoneinfo #{zone} doesn\'t exist."
154
- end
155
- end
156
-
157
- def search_utf8(lang)
158
- @utf8, @lang = nil, nil
159
- File.open("#{MOUNTPOINT}/usr/share/i18n/SUPPORTED").each do |l|
160
- @utf8 = l if l.match(/^#{lang}[. ]+utf-8 /i)
161
- @lang = $~[0] if l.match(/^#{lang}[. ]+utf-8/i)
162
- end
163
- raise ArgumentError, "Lang #{lang} no found" unless @utf8
164
- end
165
- end
166
- end
167
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open-uri'
4
- require 'open3'
5
-
6
- module Getch
7
- module Gentoo
8
- class Stage
9
- def initialize
10
- @mirror = 'https://mirrors.soeasyto.com/distfiles.gentoo.org'
11
- @release = release
12
- @stage_file="stage3-amd64-systemd-#{@release}.tar.xz"
13
- end
14
-
15
- def stage3
16
- @mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt'
17
- end
18
-
19
- def release
20
- URI.open(stage3) do |file|
21
- file.read.match(/^[[:alnum:]]+/)
22
- end
23
- end
24
-
25
- def file
26
- "#{@release}/#{@stage_file}"
27
- end
28
-
29
- def get_stage3
30
- Dir.chdir(MOUNTPOINT)
31
- return if File.exist?(@stage_file)
32
- puts "Download the last #{@stage_file}, please wait..."
33
- Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file, @stage_file)
34
- end
35
-
36
- def control_files
37
- puts 'Download the DIGESTS'
38
- Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file + '.DIGESTS', "#{@stage_file}.DIGESTS")
39
- puts 'Download the DIGESTS.asc'
40
- Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file + '.DIGESTS.asc', "#{@stage_file}.DIGESTS.asc")
41
- puts "Download the CONTENTS.gz"
42
- Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file + '.CONTENTS.gz', "#{@stage_file}.CONTENTS.gz")
43
- end
44
-
45
- def checksum
46
- puts 'Check the SHA512 checksum.'
47
- command = "awk '/SHA512 HASH/{getline;print}' #{@stage_file}.DIGESTS.asc | sha512sum --check"
48
- _, stderr, status = Open3.capture3(command)
49
- if status.success? then
50
- puts 'Checksum is ok'
51
- decompress
52
- cleaning
53
- else
54
- cleaning
55
- raise "Problem with the checksum, stderr\n#{stderr}"
56
- end
57
- end
58
-
59
- private
60
-
61
- # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
62
- def decompress
63
- puts "Decompressing archive #{@stage_file}..."
64
- cmd = "tar xpf #{@stage_file} --xattrs-include=\'*.*\' --numeric-owner"
65
- Getch::Command.new(cmd).run!
66
- end
67
-
68
- def cleaning
69
- Dir.glob('stage3-amd64-systemd*').each { |f| File.delete(f) }
70
- end
71
- end
72
- end
73
- end
@@ -1,84 +0,0 @@
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
@@ -1,56 +0,0 @@
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
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
- require 'securerandom'
5
-
6
- module Getch
7
- module Void
8
- class Config
9
- include Helpers::Void
10
-
11
- def initialize
12
- @log = Getch::Log.new
13
- @network_dir = "#{MOUNTPOINT}/etc"
14
- @id = SecureRandom.hex(2)
15
- @hostname = "void-hatch-#{@id}"
16
- end
17
-
18
- def host
19
- print " => Adding hostname #{@hostname}..."
20
- conf = "#{@network_dir}/hostname"
21
- File.write(conf, "#{@hostname}\n", mode: 'w', chmod: 0744)
22
- puts "\s[OK]"
23
- end
24
-
25
- def network
26
- print ' => Copying /etc/resolv.conf...'
27
- src = '/etc/resolv.conf'
28
- dest = "#{@network_dir}/resolv.conf"
29
- FileUtils.copy_file(src, dest)
30
- puts "\s[Ok]"
31
- end
32
-
33
- def system
34
- print ' => Updating configs system...'
35
- control_options
36
- rc = "#{MOUNTPOINT}/etc/rc.conf"
37
- add_line(rc, 'HARDWARECLOCK="UTC"') unless search(rc, /^HARDWARECLOCK/)
38
- add_line(rc, "KEYMAP=\"#{OPTIONS[:keymap]}\"") unless search(rc, /^KEYMAP/)
39
- add_line(rc, "TIMEZONE=\"#{OPTIONS[:zoneinfo]}\"") unless search(rc, /^TIMEZONE/)
40
- add_line(rc, "HOSTNAME=\"#{@hostname}\"") unless search(rc, /^HOSTNAME/)
41
- puts "\s[OK]"
42
- end
43
-
44
- def locale
45
- print ' => Updating locale system...'
46
- control_options
47
- conf = "#{MOUNTPOINT}/etc/locale.conf"
48
- File.write(conf, "LANG=#{@lang}\n")
49
- add_line(conf, 'LC_COLLATE=C')
50
- conf = "#{MOUNTPOINT}/etc/default/libc-locales"
51
- add_line(conf, @utf8)
52
- puts "\s[OK]"
53
- command 'xbps-reconfigure -f glibc-locales'
54
- end
55
-
56
- private
57
-
58
- def control_options
59
- search_zone(OPTIONS[:zoneinfo])
60
- search_utf8(OPTIONS[:language])
61
- search_key(OPTIONS[:keymap])
62
- end
63
-
64
- def search_key(keys)
65
- @keymap = nil
66
- Dir.glob("#{MOUNTPOINT}/usr/share/kbd/keymaps/**/#{keys}.map.gz") { |f|
67
- @keymap = f
68
- }
69
- raise ArgumentError, "No keymap #{@keymap} found" unless @keymap
70
- end
71
-
72
- def search_zone(zone)
73
- unless File.exist? "#{MOUNTPOINT}/usr/share/zoneinfo/#{zone}"
74
- raise ArgumentError, "Zoneinfo #{zone} doesn\'t exist."
75
- end
76
- end
77
-
78
- def search_utf8(lang)
79
- @utf8, @lang = nil, nil
80
- File.open("#{MOUNTPOINT}/etc/default/libc-locales").each do |l|
81
- @utf8 = l.delete_prefix('#') if l.match(/#{lang}.UTF-8/)
82
-
83
- found = l.split if l.match(/#{lang}.UTF-8/)
84
- @lang = found[0].delete_prefix('#') if found
85
- end
86
- raise ArgumentError, "Lang #{lang} no found" unless @utf8
87
- end
88
- end
89
- end
90
- end