getch 0.1.9 → 0.3.3

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 (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
@@ -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
@@ -0,0 +1,90 @@
1
+ require 'nito'
2
+ require 'tempfile'
3
+
4
+ module Getch
5
+ module Config
6
+ class Portage
7
+ include NiTo
8
+
9
+ def initialize
10
+ @log = Log.new
11
+ @dest = "#{OPTIONS[:mountpoint]}/etc/portage"
12
+ @usr_s = "#{OPTIONS[:mountpoint]}/usr/share/portage"
13
+ x
14
+ end
15
+
16
+ def x
17
+ @log.info "Configuring Portage...\n"
18
+ portage_dir
19
+ gentoo_repo
20
+ cpu_conf
21
+ make_conf
22
+ https_mirror
23
+ license
24
+ end
25
+
26
+ protected
27
+
28
+ def portage_dir
29
+ mkdir "#{@dest}/package.use", 0744
30
+ mkdir "#{@dest}/package.accept_keywords", 0744
31
+ mkdir "#{@dest}/package.unmask", 0744
32
+ mkdir "#{@dest}/package.license", 0744
33
+
34
+ touch "#{@dest}/package.use/zzz_via_autounmask"
35
+ touch "#{@dest}/package.accept_keywords/zzz_via_autounmask"
36
+ touch "#{@dest}/package.unmask/zzz_via_autounmask"
37
+ end
38
+
39
+ # Recreate a gentoo.conf from /usr/share/portage/config/repos.conf
40
+ def gentoo_repo
41
+ mkdir "#{@dest}/repos.conf", 0644
42
+ cp "#{@usr_s}/config/repos.conf", "#{@dest}/repos.conf/gentoo.conf"
43
+ sed "#{@dest}/repos.conf/gentoo.conf", /^sync-type/, 'sync-type = webrsync'
44
+ end
45
+
46
+ # -fomit-frame-pointer reduce code compiled
47
+ # but have repercussions on the debugging of applications
48
+ def cpu_conf
49
+ change = 'COMMON_FLAGS="-march=native -O2 -pipe -fomit-frame-pointer"'
50
+ sed "#{@dest}/make.conf", /^COMMON_FLAGS/, change
51
+ end
52
+
53
+ # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#MAKEOPTS
54
+ def make_conf
55
+ mem = get_memory
56
+ makeopts = mem[0].to_i / 2
57
+
58
+ echo_a "#{@dest}/make.conf", 'ACCEPT_KEYWORDS="amd64"'
59
+ echo_a "#{@dest}/make.conf", 'INPUT_DEVICES="libinput"'
60
+ echo_a "#{@dest}/make.conf", "MAKEOPTS=\"-j#{makeopts}\""
61
+ end
62
+
63
+ # https://www.gentoo.org/downloads/mirrors/
64
+ def https_mirror
65
+ list = 'https://gentoo.osuosl.org'
66
+ list << ' https://mirrors.rit.edu/gentoo'
67
+ list << ' https://ftp.belnet.be/pub/rsync.gentoo.org/gentoo'
68
+ list << ' https://mirror.init7.net/gentoo'
69
+ echo_a "#{@dest}/make.conf", "GENTOO_MIRRORS=\"#{list}\""
70
+ end
71
+
72
+ def license
73
+ conf = "#{@dest}/package.license/kernel"
74
+ echo conf, 'sys-kernel/linux-firmware @BINARY-REDISTRIBUTABLE'
75
+ echo_a conf, 'sys-firmware/intel-microcode intel-ucode'
76
+ end
77
+
78
+ private
79
+
80
+ def get_memory
81
+ mem = '2048'
82
+ File.open('/proc/meminfo').each do |l|
83
+ t = l.split(' ') if l =~ /memtotal/i
84
+ t && mem = t[1]
85
+ end
86
+ mem
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,37 @@
1
+ require 'nito'
2
+
3
+ module Getch
4
+ module Config
5
+ class PreNetwork
6
+ include NiTo
7
+
8
+ def initialize
9
+ @log = Log.new
10
+ x
11
+ end
12
+
13
+ protected
14
+
15
+ def x
16
+ @log.info "Configuring pre-network...\n"
17
+ hostname
18
+ copy_dns
19
+ end
20
+
21
+ private
22
+
23
+ def hostname
24
+ @log.info 'Writing /etc/hostname...'
25
+ echo "#{OPTIONS[:mountpoint]}/etc/hostname", 'host'
26
+ @log.result_ok
27
+ end
28
+
29
+ def copy_dns
30
+ @log.info 'Copying DNS from current host...'
31
+ cp '/etc/resolv.conf', "#{OPTIONS[:mountpoint]}/etc/resolv.conf"
32
+ echo_a "#{OPTIONS[:mountpoint]}/etc/resolv.conf", 'nameserver 127.0.0.1'
33
+ @log.result_ok
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nito'
4
+
5
+ module Getch
6
+ module Config
7
+ class TimeZone
8
+ include NiTo
9
+
10
+ def initialize
11
+ @log = Log.new
12
+ @etc_timezone = "#{OPTIONS[:mountpoint]}/etc/timezone"
13
+ @rc_conf = "#{OPTIONS[:mountpoint]}/etc/rc.conf"
14
+ @openrc = "#{OPTIONS[:mountpoint]}/etc/conf.d/keymaps"
15
+ @timezone = OPTIONS[:timezone]
16
+ x
17
+ end
18
+
19
+ protected
20
+
21
+ def x
22
+ @log.info "Configuring timezone to #{@timezone}...\n"
23
+ for_runit
24
+ for_openrc
25
+ for_systemd
26
+ end
27
+
28
+ private
29
+
30
+ def for_runit
31
+ return unless Helpers.runit?
32
+
33
+ echo_a @rc_conf, "TIMEZONE=\"#{@timezone}\""
34
+ end
35
+
36
+ def for_openrc
37
+ return unless Helpers.openrc?
38
+
39
+ echo_a @etc_timezone, OPTIONS[:timezone]
40
+ Getch::Chroot.new('emerge --config sys-libs/timezone-data')
41
+ end
42
+
43
+ def for_systemd
44
+ return unless Helpers.systemd?
45
+
46
+ src = "/usr/share/zoneinfo/#{OPTIONS[:timezone]}"
47
+ dest = "/etc/localtime"
48
+ Getch::Chroot.new('ln', '-sf', src, dest)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -3,42 +3,6 @@
3
3
  module Getch
4
4
  module Config
5
5
  class Void
6
- include Helpers::Void
7
-
8
- def initialize
9
- @service_dir = '/etc/runit/runsvdir/default/'
10
- end
11
-
12
- # Enable dhcpcd service
13
- def ethernet
14
- command "ln -fs /etc/sv/dhcpcd #{@service_dir}"
15
- end
16
-
17
- # with Quad9
18
- # https://www.dnsknowledge.com/tutorials/how-to-setup-quad9-dns-on-a-linux/
19
- def dns
20
- conf = "#{MOUNTPOINT}/etc/resolv.conf"
21
- content = [
22
- 'nameserver 9.9.9.9',
23
- 'nameserver 2620:fe::fe',
24
- 'options rotate',
25
- ]
26
- File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
27
- end
28
-
29
- # https://docs.voidlinux.org/config/network/iwd.html
30
- def wifi
31
- conf = "#{MOUNTPOINT}/etc/iwd/main.conf"
32
- content = [
33
- '[General]',
34
- 'UseDefaultInterface=true',
35
- ]
36
- File.write(conf, content.join("\n"), mode: 'a', chmod: 0644)
37
- # Enabling dbus and iwd
38
- command "ln -fs /etc/sv/dbus #{@service_dir}"
39
- command "ln -fs /etc/sv/iwd #{@service_dir}"
40
- end
41
-
42
6
  def shell
43
7
  command 'chsh -s /bin/bash'
44
8
  end
data/lib/getch/config.rb CHANGED
@@ -1,45 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'config/gentoo'
4
- require_relative 'config/void'
5
-
6
- CONFIG_LOAD = {
7
- gentoo: Getch::Config::Gentoo,
8
- void: Getch::Config::Void
9
- }.freeze
10
-
11
3
  module Getch
12
4
  module Config
13
- class Main
14
- def initialize
15
- os = OPTIONS[:os].to_sym
16
- @load = CONFIG_LOAD[os].new
17
- end
18
-
19
- def ethernet
20
- @load.ethernet
21
- end
22
-
23
- def dns
24
- @load.dns
25
- end
5
+ def sysctl
6
+ pwd = File.expand_path(File.dirname(__FILE__))
7
+ dest = "#{Getch::MOUNTPOINT}/etc/sysctl.d/"
26
8
 
27
- def wifi
28
- @load.wifi
29
- end
30
-
31
- def sysctl
32
- pwd = File.expand_path(File.dirname(__FILE__))
33
- dest = "#{Getch::MOUNTPOINT}/etc/sysctl.d/"
34
-
35
- Helpers.mkdir dest
36
- Helpers.cp("#{pwd}/../../assets/network-stack.conf", dest)
37
- Helpers.cp("#{pwd}/../../assets/system.conf", dest)
38
- end
39
-
40
- def shell
41
- @load.shell
42
- end
9
+ mkdir dest
10
+ Helpers.cp("#{pwd}/../../assets/network-stack.conf", dest)
11
+ Helpers.cp("#{pwd}/../../assets/system.conf", dest)
43
12
  end
44
13
  end
45
14
  end
15
+
16
+ require_relative 'config/portage'
17
+ require_relative 'config/locale'
18
+ require_relative 'config/pre_network'
19
+ require_relative 'config/keymap'
20
+ require_relative 'config/timezone'
21
+ require_relative 'config/grub'
22
+ require_relative 'config/account'
23
+ require_relative 'config/iwd'
24
+ require_relative 'config/dhcp'
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Getch
6
+ class Device
7
+ def initialize
8
+ @file = File.join('/tmp/getch_devs.yaml')
9
+ load_devs
10
+ end
11
+
12
+ def gpt(dev)
13
+ DEVS[:gpt] = dev
14
+ save
15
+ end
16
+
17
+ def efi(dev)
18
+ DEVS[:efi] = dev
19
+ save
20
+ end
21
+
22
+ def boot(dev)
23
+ DEVS[:boot] = dev
24
+ save
25
+ end
26
+
27
+ def swap(dev)
28
+ DEVS[:swap] = dev
29
+ save
30
+ end
31
+
32
+ def root(dev)
33
+ DEVS[:root] = dev
34
+ save
35
+ end
36
+
37
+ def home(dev)
38
+ DEVS[:home] = dev
39
+ save
40
+ end
41
+
42
+ def zlog(dev)
43
+ DEVS[:zlog] = dev
44
+ save
45
+ end
46
+
47
+ def zcache(dev)
48
+ DEVS[:zcache] = dev
49
+ save
50
+ end
51
+
52
+ private
53
+
54
+ def load_devs
55
+ if File.exist? @file
56
+ DEVS.merge! YAML.load_file @file
57
+ else
58
+ save
59
+ warn "Init devs at #{@file}"
60
+ end
61
+ end
62
+
63
+ def save
64
+ File.open(@file, 'w') { |f| YAML.dump(DEVS, f) }
65
+ end
66
+ end
67
+ end
@@ -1,86 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fileutils'
3
+ require 'fstab'
4
+ require 'dracut'
5
+ require 'cryptsetup'
4
6
 
5
7
  module Getch
6
8
  module FileSystem
7
9
  module Ext4
8
10
  module Encrypt
9
- class Config < Getch::FileSystem::Ext4::Encrypt::Device
11
+ class Config
10
12
  def initialize
11
- super
12
- gen_uuid
13
- @root_dir = MOUNTPOINT
14
- @init = '/usr/lib/systemd/systemd'
15
- move_secret_keys
16
- crypttab
17
- end
18
-
19
- def fstab
20
- file = "#{@root_dir}/etc/fstab"
21
- datas = data_fstab
22
- File.write(file, datas.join("\n"))
23
- end
24
-
25
- def systemd_boot
26
- return unless Helpers.efi?
27
-
28
- esp = '/efi'
29
- dir = "#{@root_dir}/#{esp}/loader/entries/"
30
- datas_gentoo = [
31
- 'title Gentoo Linux',
32
- 'linux /vmlinuz',
33
- 'initrd /initramfs',
34
- "options crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/root init=#{@init} keymap=#{Getch::OPTIONS[:keymap]} rw"
35
- ]
36
- File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
37
- end
38
-
39
- def crypttab
40
- home = @home_disk ? "crypthome UUID=#{@uuid_home} /root/secretkeys/crypto_keyfile.bin luks" : ''
41
- datas = [
42
- "cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=512",
43
- home
44
- ]
45
- File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
46
- end
47
-
48
- def grub
49
- return if Helpers.efi?
50
-
51
- file = "#{@root_dir}/etc/default/grub"
52
- cmdline = [
53
- "GRUB_CMDLINE_LINUX=\"crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/root init=#{@init} rw slub_debug=P page_poison=1 slab_nomerge pti=on vsyscall=none spectre_v2=on spec_store_bypass_disable=seccomp iommu=force keymap=#{Getch::OPTIONS[:keymap]}\"",
54
- "GRUB_ENABLE_CRYPTODISK=y"
55
- ]
56
- File.write(file, cmdline.join("\n"), mode: 'a')
13
+ x
57
14
  end
58
15
 
59
16
  private
60
17
 
61
- def gen_uuid
62
- @partuuid_swap = Helpers.partuuid(@dev_swap)
63
- @uuid_dev_root = `lsblk -d -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
64
- @uuid_esp = Helpers.uuid(@dev_esp) if @dev_esp
65
- @uuid_root = `lsblk -d -o "UUID" #{@luks_root} | tail -1`.chomp() if @dev_root
66
- @uuid_home = `lsblk -d -o "UUID" #{@dev_home} | tail -1`.chomp() if @luks_home
67
- end
68
-
69
- def data_fstab
70
- boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
71
- swap = @dev_swap ? "#{@luks_swap} none swap discard 0 0 " : ''
72
- root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
73
- home = @dev_home ? "#{@luks_home} /home/#{@user} ext4 defaults 0 2" : ''
74
-
75
- [ boot_efi, swap, root, home ]
76
- end
77
-
78
- def move_secret_keys
79
- return unless @luks_home
80
-
81
- puts 'Moving secret keys'
82
- keys_path = "#{@root_dir}/root/secretkeys"
83
- FileUtils.mv('/root/secretkeys', keys_path) unless Dir.exist? keys_path
18
+ def x
19
+ Fstab::Encrypt.new(DEVS, OPTIONS).generate
20
+ Dracut::Encrypt.new(DEVS, OPTIONS).generate
21
+ CryptSetup.new(DEVS, OPTIONS).configs
84
22
  end
85
23
  end
86
24
  end
@@ -5,38 +5,28 @@ module Getch
5
5
  module Ext4
6
6
  module Encrypt
7
7
  class Deps
8
- def make
9
- install_deps
10
- genkernel
11
- Getch::Make.new('genkernel --kernel-config=/usr/src/linux/.config all').run!
8
+ def initialize
9
+ install
10
+ service
12
11
  end
13
12
 
14
- private
13
+ protected
15
14
 
16
- def genkernel
17
- grub = Helpers.efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
18
- datas = [
19
- '',
20
- grub,
21
- 'INSTALL="yes"',
22
- 'MENUCONFIG="no"',
23
- 'CLEAN="yes"',
24
- 'KEYMAP="yes"',
25
- 'SAVE_CONFIG="yes"',
26
- 'MOUNTBOOT="yes"',
27
- 'MRPROPER="no"',
28
- 'LUKS="yes"',
29
- ]
30
- file = "#{MOUNTPOINT}/etc/genkernel.conf"
31
- File.write(file, datas.join("\n"), mode: 'a')
15
+ def install
16
+ case OPTIONS[:os]
17
+ when 'gentoo' then Install.new('sys-fs/cryptsetup')
18
+ when 'void' then Install.new('cryptsetup')
19
+ end
32
20
  end
33
21
 
34
- def install_deps
35
- Getch::Emerge.new('genkernel').pkg!
22
+ def service
23
+ openrc
36
24
  end
37
25
 
38
- def exec(cmd)
39
- Getch::Chroot.new(cmd).run!
26
+ def openrc
27
+ Helpers.openrc? || return
28
+
29
+ Chroot.new('rc-update add dmcrypt boot')
40
30
  end
41
31
  end
42
32
  end