getch 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,86 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cmdline'
4
+ require 'nito'
5
+
1
6
  module Getch
2
7
  module Gentoo
3
8
  class Sources
9
+ include NiTo
10
+
4
11
  def initialize
12
+ @log = Log.new
5
13
  @lsmod = `lsmod`.chomp
6
- @filesystem = Getch.class_fs::Deps.new()
14
+ x
7
15
  end
8
16
 
9
- def build_others
10
- cryptsetup
11
- virtualbox_guest
12
- qemu_guest
13
- install_wifi
14
- install_audio
17
+ protected
18
+
19
+ def x
20
+ bask
21
+ gen_cmdline
22
+ grub_mkconfig
23
+ use_flags
24
+ make
15
25
  end
16
26
 
17
- def build_kspp
18
- puts "Adding KSPP to the kernel source"
19
- bask("-b -a systemd")
27
+ def bask
28
+ @log.info "Kernel hardening...\n"
29
+ #Getch::Bask.new('10_kspp.config').cp
30
+ Getch::Bask.new('11-kspp-gcc.config').cp
31
+ Getch::Bask.new('12-kspp-x86_64.config').cp
32
+ #Getch::Bask.new('20-clipos.config').cp
33
+ Getch::Bask.new('30-grsecurity.config').cp
34
+ #Getch::Bask.new('40-kconfig-hardened.config').cp
35
+ Getch::Bask.new('50-blacklist.config').cp
36
+ Getch::Bask.new('51-blacklist-madaidans.config').cp
20
37
  end
21
38
 
22
- def make
23
- if DEFAULT_OPTIONS[:fs] == 'lvm' || DEFAULT_OPTIONS[:fs] == 'zfs' || DEFAULT_OPTIONS[:encrypt]
24
- @filesystem.make
25
- else
26
- make_kernel
27
- end
39
+ def gen_cmdline
40
+ cmdline = CmdLine::Kernel.new(workdir: "#{MOUNTPOINT}/etc/kernel")
41
+ cmdline.main
28
42
  end
29
43
 
30
- private
44
+ def grub_mkconfig
45
+ return if Helpers.systemd? and Helpers.efi?
31
46
 
32
- def make_kernel
33
- puts "Compiling kernel sources"
34
- cmd = "make -j$(nproc) && make modules_install && make install"
35
- Getch::Make.new(cmd).run!
36
- is_kernel = Dir.glob("#{MOUNTPOINT}/boot/vmlinuz-*")
37
- raise "No kernel installed, compiling source fail..." if is_kernel == []
38
- end
47
+ file = "#{OPTIONS[:mountpoint]}/etc/kernel/postinst.d/90-mkconfig.install"
48
+ content = <<~SHELL
49
+ #!/usr/bin/env sh
50
+ set -o errexit
39
51
 
40
- def cryptsetup
41
- return unless DEFAULT_OPTIONS[:encrypt]
42
- make_conf = "#{MOUNTPOINT}/etc/portage/make.conf"
52
+ if ! hash grub-mkconfig ; then
53
+ exit 0
54
+ fi
55
+ grub-mkconfig -o /boot/grub/grub.cfg
56
+ SHELL
57
+ mkdir "#{OPTIONS[:mountpoint]}/etc/kernel/postinst.d"
58
+ File.write file, content
59
+ File.chmod 0755, file
60
+ end
43
61
 
44
- puts "Adding support for cryptsetup."
45
- bask("-a cryptsetup")
46
- Getch::Chroot.new("euse -E cryptsetup").run! unless Helpers::grep?(make_conf, /cryptsetup/)
47
- Getch::Emerge.new("sys-fs/cryptsetup").pkg!
62
+ def use_flags
63
+ use = Getch::Gentoo::Use.new('sys-kernel/gentoo-kernel')
64
+ use.add('hardened')
48
65
  end
49
66
 
50
- def virtualbox_guest
51
- systemd=`systemd-detect-virt`.chomp
52
- return if ! ismatch?('vmwgfx') || systemd.match(/none/)
53
- bask("-a virtualbox-guest")
54
- Getch::Emerge.new("app-emulation/virtualbox-guest-additions").pkg!
67
+ # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel#Alternative:_Using_distribution_kernels
68
+ def make
69
+ Helpers.systemd? ?
70
+ Install.new('sys-kernel/installkernel-systemd-boot') :
71
+ Install.new('sys-kernel/installkernel-gentoo')
72
+
73
+ #Install.new 'sys-kernel/gentoo-kernel'
74
+ Install.new 'sys-kernel/gentoo-kernel-bin'
55
75
  end
56
76
 
57
- def qemu_guest
58
- bask("-a kvm-host") if ismatch?('kvm')
59
- bask("-a kvm-guest") if ismatch?('virtio')
77
+ def load_modules
78
+ wifi
79
+ flash_mod
60
80
  end
61
81
 
82
+ private
83
+
62
84
  def ismatch?(arg)
63
85
  @lsmod.match?(/#{arg}/)
64
86
  end
65
87
 
66
- def bask(cmd)
67
- Getch::Bask.new(cmd).run!
68
- end
88
+ def wifi
89
+ return unless ismatch?('cfg80211')
90
+
91
+ conf = "#{MOUNTPOINT}/etc/modules-load.d/wifi.conf"
92
+ File.delete(conf) if File.exist? conf
69
93
 
70
- def install_wifi
71
- return if ! ismatch?('cfg80211')
72
- bask("-a wifi")
73
- wifi_drivers
74
- Getch::Emerge.new("net-wireless/iw wpa_supplicant net-wireless/iwd").pkg!
94
+ module_load('iwlmvm', conf)
95
+ module_load('ath9k', conf)
75
96
  end
76
97
 
77
- def install_audio
78
- return if ! ismatch?('snd_pcm')
79
- bask("-a sound")
98
+ def flash_mod
99
+ conf = "#{MOUNTPOINT}/etc/modules-load.d/usb.conf"
100
+ File.delete(conf) if File.exist? conf
101
+
102
+ module_load('ehci_pci', conf)
103
+ module_load('rtsx_pci_sdmmc', conf)
104
+ module_load('sdhci_pci', conf)
105
+ module_load('uas', conf)
106
+ module_load('uhci_hcd', conf)
107
+ module_load('xhci_pci', conf)
80
108
  end
81
109
 
82
- def wifi_drivers
83
- bask("-a ath9k-driver") if ismatch?('ath9k')
110
+ def module_load(name, file)
111
+ return unless ismatch?(name)
112
+
113
+ File.write(file, "#{name}\n", mode: 'a')
84
114
  end
85
115
  end
86
116
  end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open-uri'
4
+ require 'open3'
5
+
6
+ module Getch
7
+ module Gentoo
8
+ class Tarball
9
+ def initialize
10
+ @log = Log.new
11
+ @mirror = 'https://mirror.rackspace.com/gentoo'
12
+ @release = release
13
+ @stage_file = OPTIONS[:musl] ?
14
+ "stage3-amd64-musl-#{@release}.tar.xz" :
15
+ "stage3-amd64-systemd-#{@release}.tar.xz"
16
+ end
17
+
18
+ def x
19
+ get_stage3
20
+ control_files
21
+ checksum
22
+ install
23
+ end
24
+
25
+ protected
26
+
27
+ def stage3
28
+ OPTIONS[:musl] ?
29
+ @mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-musl.txt' :
30
+ @mirror + '/releases/amd64/autobuilds/latest-stage3-amd64-systemd.txt'
31
+ end
32
+
33
+ def release
34
+ URI.open(stage3) do |file|
35
+ file.read.match(/^[[:alnum:]]+/)
36
+ end
37
+ rescue Net::OpenTimeout => e
38
+ @log.fatal "Problem with DNS? #{e}"
39
+ end
40
+
41
+ def file
42
+ "#{@release}/#{@stage_file}"
43
+ end
44
+
45
+ def get_stage3
46
+ Dir.chdir OPTIONS[:mountpoint]
47
+ return if File.exist? @stage_file
48
+
49
+ @log.info "wget #{@stage_file}, please wait...\n"
50
+ Helpers.get_file_online(@mirror + '/releases/amd64/autobuilds/' + file, @stage_file)
51
+ end
52
+
53
+ def control_files
54
+ @log.info "Download other files..."
55
+ ['DIGESTS', 'asc', 'CONTENTS.gz'].each do |f|
56
+ Helpers.get_file_online("#{@mirror}/releases/amd64/autobuilds/#{file}.#{f}", "#{@stage_file}.#{f}")
57
+ end
58
+ @log.result_ok
59
+ end
60
+
61
+ def checksum
62
+ @log.info 'Checking SHA512 checksum...'
63
+ command = "awk '/SHA512 HASH/{getline;print}' #{@stage_file}.DIGESTS | sha512sum --check"
64
+ _, stderr, status = Open3.capture3(command)
65
+ if status.success? then
66
+ @log.result_ok
67
+ else
68
+ cleaning
69
+ @log.fatal "Problem with the checksum, stderr\n#{stderr}"
70
+ end
71
+ end
72
+
73
+ def install
74
+ decompress
75
+ cleaning
76
+ end
77
+
78
+ private
79
+
80
+ # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage
81
+ def decompress
82
+ cmd = "tar xpf #{@stage_file} --xattrs-include=\'*.*\' --numeric-owner"
83
+ Getch::Command.new(cmd)
84
+ end
85
+
86
+ def cleaning
87
+ Dir.glob('stage3-amd64-*').each { |f| File.delete(f) }
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,34 @@
1
+ module Getch
2
+ module Gentoo
3
+ class Terraform
4
+ def initialize
5
+ x
6
+ end
7
+
8
+ protected
9
+
10
+ def x
11
+ Gentoo::Sources.new
12
+ install_pkgs
13
+ emerge_deep
14
+ end
15
+
16
+ def install_pkgs
17
+ @pkgs = 'app-portage/gentoolkit'
18
+ @pkgs << ' app-admin/sudo'
19
+ @pkgs << ' app-editors/vim'
20
+ @pkgs << ' net-firewall/iptables'
21
+ @pkgs << ' net-wireless/iwd'
22
+ @pkgs << ' net-misc/dhcpcd' unless Helpers.systemd?
23
+ @pkgs << ' sys-kernel/linux-firmware'
24
+ @pkgs << ' sys-firmware/intel-microcode'
25
+ @pkgs << ' sys-fs/dosfstools' if Helpers.efi?
26
+ Install.new(@pkgs)
27
+ end
28
+
29
+ def emerge_deep
30
+ ChrootOutput.new('emerge --deep --newuse @world')
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nito'
4
+
5
+ module Getch
6
+ module Gentoo
7
+ class Update
8
+ include NiTo
9
+
10
+ def initialize
11
+ @log = Log.new
12
+ x
13
+ end
14
+
15
+ protected
16
+
17
+ def x
18
+ sync
19
+ add_musl_repo if OPTIONS[:musl]
20
+ update
21
+ end
22
+
23
+ private
24
+
25
+ def sync
26
+ gentoo_conf = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/gentoo.conf"
27
+ @log.info "Synchronize index, please waiting...\n"
28
+ ChrootOutput.new('emaint sync --auto')
29
+ sed gentoo_conf, /^sync-type/, 'sync-type = rsync'
30
+ end
31
+
32
+ def add_musl_repo
33
+ Install.new('dev-vcs/git')
34
+
35
+ file = "#{OPTIONS[:mountpoint]}/etc/portage/repos.conf/musl.conf"
36
+ content = <<~CONF
37
+ [musl]
38
+ location = /var/db/repos/musl
39
+ sync-type = git
40
+ sync-uri = https://github.com/gentoo/musl.git
41
+ auto-sync = Yes
42
+ CONF
43
+ File.write file, "#{content}\n"
44
+
45
+ ChrootOutput.new('emaint sync -r musl')
46
+ end
47
+
48
+ def update
49
+ cmd = 'emerge --update --deep --newuse @world'
50
+ ChrootOutput.new(cmd)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,11 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'nito'
4
+
1
5
  module Getch
2
6
  module Gentoo
3
7
  class Use
8
+ include NiTo
9
+
4
10
  def initialize(pkg = nil)
5
- @use_dir = "#{MOUNTPOINT}/etc/portage/package.use"
11
+ @use_dir = "#{OPTIONS[:mountpoint]}/etc/portage/package.use"
6
12
  @pkg = pkg
7
13
  @file = @pkg ? @pkg.match(/[\w]+$/) : nil
8
- @make = "#{MOUNTPOINT}/etc/portage/make.conf"
14
+ @make = "#{OPTIONS[:mountpoint]}/etc/portage/make.conf"
9
15
  end
10
16
 
11
17
  def add(*flags)
@@ -22,21 +28,14 @@ module Getch
22
28
 
23
29
  def write
24
30
  content = "#{@pkg} #{@flags}\n"
25
- File.write("#{@use_dir}/#{@file}", content, mode: 'w')
31
+ echo "#{@use_dir}/#{@file}", content
26
32
  end
27
33
 
28
34
  def write_global
29
35
  list = []
30
-
31
- @flags.each { |f|
32
- unless Helpers::grep?(@make, /#{f}/)
33
- list << f
34
- end
35
- }
36
-
36
+ @flags.each { |f| list << f unless grep?(@make, f) }
37
37
  use = list.join(' ')
38
- line = "USE=\"${USE} #{use}\"\n"
39
- File.write(@make, line, mode: 'a')
38
+ echo_a @make, "USE=\"${USE} #{use}\""
40
39
  end
41
40
  end
42
41
  end
@@ -1,64 +1,86 @@
1
- # lib/use_flag.rb
1
+ # frozen_string_literal: true
2
2
 
3
- module Getch::Gentoo
4
- class UseFlag
5
- def initialize(options)
6
- @efi = Helpers::efi?
7
- @o = options
8
- end
3
+ module Getch
4
+ module Gentoo
5
+ class UseFlag
6
+ def initialize
7
+ x
8
+ end
9
9
 
10
- def apply
11
- systemd
12
- kmod
13
- grub
14
- zfs
15
- lvm
16
- cryptsetup
17
- end
10
+ protected
18
11
 
19
- private
12
+ def x
13
+ dist_kernel
14
+ systemd
15
+ pam
16
+ kmod
17
+ grub
18
+ zfs
19
+ lvm
20
+ cryptsetup
21
+ end
20
22
 
21
- def systemd
22
- flags = []
23
- use = Getch::Gentoo::Use.new('sys-apps/systemd')
24
- flags << 'dns-over-tls'
25
- flags << 'gnuefi' if @efi
26
- use.add(flags)
27
- end
23
+ private
28
24
 
29
- def kmod
30
- use = Getch::Gentoo::Use.new('sys-apps/kmod')
31
- use.add('zstd', 'lzma')
32
- end
25
+ # https://wiki.gentoo.org/wiki/Project:Distribution_Kernel#Trying_it_out
26
+ def dist_kernel
27
+ use = Getch::Gentoo::Use.new
28
+ use.add_global('dist-kernel')
29
+ end
33
30
 
34
- def grub
35
- return if @efi
36
- flags = []
37
- use = Getch::Gentoo::Use.new('sys-boot/grub')
38
- flags << '-grub_platforms_efi-64'
39
- flags << 'libzfs' if @o.fs == 'zfs'
40
- flags << 'device-mapper' if @o.fs == 'lvm'
41
- use.add(flags)
42
- end
31
+ def systemd
32
+ return unless Helpers.systemd?
43
33
 
44
- def zfs
45
- return unless @o.fs == 'zfs'
46
- use = Getch::Gentoo::Use.new('sys-fs/zfs-kmod')
47
- use.add('rootfs')
48
- use = Getch::Gentoo::Use.new('sys-fs/zfs')
49
- use.add('rootfs')
50
- end
34
+ flags = []
35
+ use = Getch::Gentoo::Use.new('sys-apps/systemd')
36
+ flags << 'dns-over-tls'
37
+ flags << 'gnuefi' if Helpers.efi?
38
+ use.add(flags)
39
+ end
51
40
 
52
- def lvm
53
- return unless @o.fs == 'lvm'
54
- use = Getch::Gentoo::Use.new
55
- use.add_global('lvm', 'device-mapper')
56
- end
41
+ def pam
42
+ flags = []
43
+ use = Getch::Gentoo::Use.new('sys-auth/pambase')
44
+ flags << 'sha512'
45
+ use.add(flags)
46
+ end
47
+
48
+ def kmod
49
+ use = Getch::Gentoo::Use.new('sys-apps/kmod')
50
+ use.add('zstd', 'lzma')
51
+ end
52
+
53
+ def grub
54
+ flags = []
55
+ use = Getch::Gentoo::Use.new('sys-boot/grub')
56
+ flags << '-grub_platforms_efi-64' unless Helpers.efi?
57
+ flags << 'libzfs' if OPTIONS[:fs] == 'zfs'
58
+ flags << 'device-mapper' if OPTIONS[:fs] == 'lvm' or OPTIONS[:encrypt]
59
+ use.add(flags)
60
+ end
61
+
62
+ def zfs
63
+ return unless Getch::OPTIONS[:fs] == 'zfs'
64
+
65
+ use = Getch::Gentoo::Use.new('sys-fs/zfs-kmod')
66
+ use.add('rootfs')
67
+ use = Getch::Gentoo::Use.new('sys-fs/zfs')
68
+ use.add('rootfs')
69
+ end
70
+
71
+ def lvm
72
+ return unless Getch::OPTIONS[:fs] == 'lvm'
73
+
74
+ use = Getch::Gentoo::Use.new
75
+ use.add_global('lvm', 'device-mapper')
76
+ end
77
+
78
+ def cryptsetup
79
+ return unless Getch::OPTIONS[:encrypt]
57
80
 
58
- def cryptsetup
59
- return unless @o.encrypt
60
- use = Getch::Gentoo::Use.new
61
- use.add_global('cryptsetup')
81
+ use = Getch::Gentoo::Use.new
82
+ use.add_global('cryptsetup')
83
+ end
62
84
  end
63
85
  end
64
86
  end
data/lib/getch/gentoo.rb CHANGED
@@ -1,71 +1,19 @@
1
- require_relative 'gentoo/stage'
2
- require_relative 'gentoo/config'
3
- require_relative 'gentoo/chroot'
1
+ # frozen_string_literal: true
2
+
4
3
  require_relative 'gentoo/sources'
5
- require_relative 'gentoo/boot'
6
4
  require_relative 'gentoo/use'
7
5
  require_relative 'gentoo/use_flag'
8
6
 
9
7
  module Getch
10
8
  module Gentoo
11
- class << self
12
- def new
13
- @state = Getch::States.new()
14
- end
15
-
16
- def stage3
17
- return if STATES[:gentoo_base]
18
- new
19
- stage = Getch::Gentoo::Stage.new()
20
- stage.get_stage3
21
- stage.control_files
22
- stage.checksum
23
- @state.stage3
24
- end
25
-
26
- def config(options)
27
- return if STATES[:gentoo_config]
28
- new
29
- config = Getch::Gentoo::Config.new()
30
- config.portage
31
- config.portage_fs
32
- config.repo
33
- config.network
34
- config.systemd(options)
35
- config.hostname
36
- @state.config
37
- end
38
-
39
- def chroot(options)
40
- chroot = Getch::Gentoo::Chroot.new()
41
- chroot.update
42
- chroot.cpuflags
43
- chroot.systemd
44
-
45
- flags = Getch::Gentoo::UseFlag.new(options)
46
- flags.apply
47
-
48
- chroot.world
49
- return if STATES[:gentoo_kernel]
50
- chroot.kernel
51
- chroot.kernel_deps
52
- chroot.install_pkgs
53
- end
54
-
55
- def kernel
56
- return if STATES[:gentoo_kernel]
57
- source = Getch::Gentoo::Sources.new()
58
- new
59
- source.build_kspp
60
- source.build_others
61
- source.make
62
- @state.kernel
63
- end
64
-
65
- def boot(options)
66
- boot = Getch::Gentoo::Boot.new(options)
67
- boot.start
68
- end
69
- end
70
9
  end
71
10
  end
11
+
12
+ require_relative 'gentoo/tarball'
13
+ require_relative 'gentoo/pre_config'
14
+ require_relative 'gentoo/update'
15
+ require_relative 'gentoo/post_config'
16
+ require_relative 'gentoo/terraform'
17
+ require_relative 'gentoo/services'
18
+ require_relative 'gentoo/bootloader'
19
+ require_relative 'gentoo/finalize'
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ class InvalidDisk < StandardError
4
+ end
5
+
6
+ class InvalidFormat < StandardError
7
+ end
8
+
9
+ class InvalidZone < StandardError
10
+ end
11
+
12
+ class InvalidKeymap < StandardError
13
+ end
14
+
15
+ module Getch
16
+ module Guard
17
+ def self.disk(name)
18
+ raise InvalidDisk, 'No disk.' unless name
19
+ raise InvalidDisk, "Bad device name #{name}." unless name.match(/^sd[a-z]{1}$/)
20
+ raise InvalidDisk, "Disk /dev/#{name} no found." unless File.exist? "/dev/#{name}"
21
+
22
+ name
23
+ rescue InvalidDisk => e
24
+ puts "#{e.class} => #{e}"
25
+ exit 1
26
+ end
27
+
28
+ def self.format(name)
29
+ raise InvalidFormat, 'No format specified.' unless name
30
+ raise InvalidFormat, "Format #{name} not yet available." if name.match(/btrfs|xfs/)
31
+ raise InvalidFormat, "Format #{name} not supported." unless name.match(/zfs|ext4/)
32
+
33
+ name
34
+ rescue InvalidFormat => e
35
+ puts "#{e.class} => #{e}"
36
+ exit 1
37
+ end
38
+
39
+ def self.zone(name)
40
+ raise InvalidZone, 'No zoneinfo specified.' unless name
41
+ raise InvalidZone, 'Directory /usr/share/zoneinfo/ no found on this system...' unless Dir.exist? '/usr/share/zoneinfo/'
42
+ raise InvalidZone, "Zoneinfo #{name} is no found in /usr/share/zoneinfo/." unless File.exist? "/usr/share/zoneinfo/#{name}"
43
+
44
+ name
45
+ rescue InvalidZone => e
46
+ puts "#{e.class} => #{e}"
47
+ exit 1
48
+ end
49
+
50
+ def self.keymap(name)
51
+ raise InvalidKeymap, 'No keymap specified.' unless name
52
+
53
+ key = []
54
+
55
+ if Dir.exist? '/usr/share/keymaps'
56
+ key = Dir.glob("/usr/share/keymaps/**/#{name}.map.gz")
57
+ elsif Dir.exist? '/usr/share/kbd/keymaps'
58
+ key = Dir.glob("/usr/share/kbd/keymaps/**/#{name}.map.gz")
59
+ else
60
+ raise InvalidKeymap, 'No directory found for keymap.'
61
+ end
62
+
63
+ raise InvalidKeymap, "Keymap #{name} no found." if key == []
64
+
65
+ name
66
+ rescue InvalidKeymap => e
67
+ puts "#{e.class} => #{e}"
68
+ exit 1
69
+ end
70
+ end
71
+ end