getch 0.1.2 → 0.1.9

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 (93) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +66 -32
  4. data/assets/network-stack.conf +63 -0
  5. data/assets/system.conf +38 -0
  6. data/bin/getch +12 -4
  7. data/lib/cmdline.rb +128 -0
  8. data/lib/getch/command.rb +32 -22
  9. data/lib/getch/config/gentoo.rb +58 -0
  10. data/lib/getch/config/void.rb +47 -0
  11. data/lib/getch/config.rb +45 -0
  12. data/lib/getch/filesystem/clean.rb +22 -15
  13. data/lib/getch/filesystem/device.rb +8 -6
  14. data/lib/getch/filesystem/ext4/config.rb +8 -4
  15. data/lib/getch/filesystem/ext4/deps.rb +3 -1
  16. data/lib/getch/filesystem/ext4/device.rb +2 -3
  17. data/lib/getch/filesystem/ext4/encrypt/config.rb +15 -11
  18. data/lib/getch/filesystem/ext4/encrypt/deps.rb +5 -10
  19. data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -3
  20. data/lib/getch/filesystem/ext4/encrypt/format.rb +4 -2
  21. data/lib/getch/filesystem/ext4/encrypt/mount.rb +3 -3
  22. data/lib/getch/filesystem/ext4/encrypt/partition.rb +29 -35
  23. data/lib/getch/filesystem/ext4/encrypt/void.rb +101 -0
  24. data/lib/getch/filesystem/ext4/encrypt.rb +3 -0
  25. data/lib/getch/filesystem/ext4/format.rb +4 -1
  26. data/lib/getch/filesystem/ext4/mount.rb +3 -0
  27. data/lib/getch/filesystem/ext4/partition.rb +11 -8
  28. data/lib/getch/filesystem/ext4/void.rb +44 -0
  29. data/lib/getch/filesystem/ext4.rb +3 -0
  30. data/lib/getch/filesystem/lvm/config.rb +10 -29
  31. data/lib/getch/filesystem/lvm/deps.rb +7 -11
  32. data/lib/getch/filesystem/lvm/device.rb +5 -3
  33. data/lib/getch/filesystem/lvm/encrypt/config.rb +17 -17
  34. data/lib/getch/filesystem/lvm/encrypt/deps.rb +8 -12
  35. data/lib/getch/filesystem/lvm/encrypt/device.rb +7 -5
  36. data/lib/getch/filesystem/lvm/encrypt/format.rb +5 -2
  37. data/lib/getch/filesystem/lvm/encrypt/mount.rb +4 -2
  38. data/lib/getch/filesystem/lvm/encrypt/partition.rb +17 -13
  39. data/lib/getch/filesystem/lvm/encrypt/void.rb +101 -0
  40. data/lib/getch/filesystem/lvm/encrypt.rb +3 -0
  41. data/lib/getch/filesystem/lvm/format.rb +4 -1
  42. data/lib/getch/filesystem/lvm/mount.rb +3 -0
  43. data/lib/getch/filesystem/lvm/partition.rb +10 -7
  44. data/lib/getch/filesystem/lvm/void.rb +46 -0
  45. data/lib/getch/filesystem/lvm.rb +3 -0
  46. data/lib/getch/filesystem/mount.rb +19 -12
  47. data/lib/getch/filesystem/partition.rb +19 -11
  48. data/lib/getch/filesystem/zfs/config.rb +10 -24
  49. data/lib/getch/filesystem/zfs/deps.rb +28 -58
  50. data/lib/getch/filesystem/zfs/device.rb +9 -1
  51. data/lib/getch/filesystem/zfs/encrypt/config.rb +12 -28
  52. data/lib/getch/filesystem/zfs/encrypt/deps.rb +29 -60
  53. data/lib/getch/filesystem/zfs/encrypt/device.rb +9 -1
  54. data/lib/getch/filesystem/zfs/encrypt/format.rb +24 -22
  55. data/lib/getch/filesystem/zfs/encrypt/mount.rb +15 -14
  56. data/lib/getch/filesystem/zfs/encrypt/partition.rb +24 -18
  57. data/lib/getch/filesystem/zfs/encrypt/void.rb +97 -0
  58. data/lib/getch/filesystem/zfs/encrypt.rb +3 -0
  59. data/lib/getch/filesystem/zfs/format.rb +21 -18
  60. data/lib/getch/filesystem/zfs/mount.rb +12 -13
  61. data/lib/getch/filesystem/zfs/partition.rb +20 -15
  62. data/lib/getch/filesystem/zfs/void.rb +81 -0
  63. data/lib/getch/filesystem/zfs.rb +3 -0
  64. data/lib/getch/filesystem.rb +2 -0
  65. data/lib/getch/gentoo/boot.rb +29 -67
  66. data/lib/getch/gentoo/bootloader.rb +68 -0
  67. data/lib/getch/gentoo/chroot.rb +26 -29
  68. data/lib/getch/gentoo/config.rb +69 -31
  69. data/lib/getch/gentoo/sources.rb +73 -38
  70. data/lib/getch/gentoo/stage.rb +12 -13
  71. data/lib/getch/gentoo/use.rb +39 -0
  72. data/lib/getch/gentoo/use_flag.rb +89 -0
  73. data/lib/getch/gentoo.rb +39 -21
  74. data/lib/getch/guard.rb +71 -0
  75. data/lib/getch/helpers.rb +180 -48
  76. data/lib/getch/log.rb +10 -7
  77. data/lib/getch/options.rb +50 -41
  78. data/lib/getch/states.rb +10 -3
  79. data/lib/getch/version.rb +1 -1
  80. data/lib/getch/void/boot.rb +84 -0
  81. data/lib/getch/void/chroot.rb +56 -0
  82. data/lib/getch/void/config.rb +90 -0
  83. data/lib/getch/void/stage.rb +69 -0
  84. data/lib/getch/void.rb +65 -0
  85. data/lib/getch.rb +125 -74
  86. data.tar.gz.sig +0 -0
  87. metadata +28 -10
  88. metadata.gz.sig +0 -0
  89. data/.gitignore +0 -2
  90. data/CHANGELOG.md +0 -80
  91. data/Rakefile +0 -21
  92. data/bin/setup.sh +0 -90
  93. data/getch.gemspec +0 -25
@@ -1,21 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
4
- class Partition < Getch::FileSystem::Zfs::Device
6
+ class Partition < Device
5
7
  def initialize
6
8
  super
7
9
  @clean = Getch::FileSystem::Clean
8
10
  @partition = Getch::FileSystem::Partition.new
9
- @state = Getch::States.new()
10
- @log = Getch::Log.new()
11
+ @state = Getch::States.new
12
+ @log = Getch::Log.new
11
13
  run_partition
12
14
  end
13
15
 
14
16
  def run_partition
15
17
  return if STATES[:partition ]
18
+
16
19
  @clean.old_zpool
17
- @clean.struct(@disk, @cache_disk, @home_disk)
18
- @clean.hdd(@disk, @cache_disk, @home_disk)
20
+ @clean.hdd(@disk)
21
+ @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
22
+
19
23
  partition
20
24
  cache
21
25
  @state.partition
@@ -26,24 +30,25 @@ module Getch
26
30
  def partition
27
31
  if @efi
28
32
  @partition.efi(@dev_esp)
29
- @partition.swap(@dev_swap)
30
- @partition.root(@dev_root, "BF00") if @root_part != 1
33
+ @partition.boot(@dev_boot) if Getch::OPTIONS[:os] == 'void'
34
+ @partition.swap(@dev_swap) unless @cache_disk
35
+ @partition.root(@dev_root, 'BF00') if @root_part != 1
31
36
  else
32
37
  @partition.gpt(@dev_gpt)
33
38
  # Boot pool for GRUB2
34
39
  @partition.boot(@dev_boot)
35
- @partition.swap(@dev_swap)
36
- @partition.root(@dev_root, "BF00") if @root_part != 1
40
+ @partition.swap(@dev_swap) unless @cache_disk
41
+ @partition.root(@dev_root, 'BF00') if @root_part != 1
37
42
  end
38
43
  end
39
44
 
40
45
  def cache
41
- if @dev_log
42
- exec("sgdisk -n2:0:+4G -t2:BF07 #{cache_disk}")
43
- end
44
- if @dev_cache
45
- exec("sgdisk -n3:0:0 -t3:BF08 #{cache_disk}")
46
- end
46
+ return unless @cache_disk
47
+
48
+ mem = `awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
49
+ exec("sgdisk -n1:0:+#{mem} -t1:8200 /dev/#{@cache_disk}")
50
+ exec("sgdisk -n2:0:+4G -t2:BF07 /dev/#{@cache_disk}")
51
+ exec("sgdisk -n3:0:0 -t3:BF00 /dev/#{@cache_disk}")
47
52
  end
48
53
 
49
54
  # Partition_efi
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Getch
4
+ module FileSystem
5
+ module Zfs
6
+ class Void < Device
7
+ include Helpers::Void
8
+
9
+ attr_reader :boot_disk
10
+
11
+ def initialize
12
+ super
13
+ hostid
14
+ zfs_zed # mountpoint for zfs
15
+ end
16
+
17
+ # Fstab contain:
18
+ # > /efi noauto
19
+ # > swap
20
+ # > /boot zfs-legacy
21
+ # > /tmp
22
+ def fstab
23
+ conf = "#{MOUNTPOINT}/etc/fstab"
24
+ File.write(conf, "\n", mode: 'w', chmod: 0644)
25
+ line_fstab(@dev_esp, '/efi vfat noauto,rw,relatime 0 0') if @dev_esp
26
+ line_fstab(@dev_swap, 'swap swap rw,noatime,discard 0 0') if @dev_swap
27
+ #add_line(conf, "#{@boot_pool_name}/BOOT/#{@n} /boot zfs defaults 0 0") if @dev_boot
28
+ add_line(conf, 'tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0')
29
+ end
30
+
31
+ def config_dracut
32
+ conf = "#{MOUNTPOINT}/etc/dracut.conf.d/zfs.conf"
33
+ # dracut: value+= should be surrounding by white space
34
+ content = [
35
+ 'hostonly="yes"',
36
+ 'omit_dracutmodules+=" btrfs lvm "',
37
+ ]
38
+ File.write(conf, content.join("\n"), mode: 'w', chmod: 0644)
39
+ end
40
+
41
+ def kernel_cmdline_dracut
42
+ #command "zfs set mountpoint=legacy #{@boot_pool_name}/BOOT/#{@n}"
43
+ end
44
+
45
+ def config_grub
46
+ grub_cmdline("root=zfs:#{@pool_name}/ROOT/#{@n}", 'zfs_force=1', 'zfs.zfs_arc_max=536870912')
47
+ end
48
+
49
+ def finish
50
+ zed_update_path
51
+ puts '+ Enter in your system: chroot /mnt /bin/bash'
52
+ puts '+ Reboot with: shutdown -r now'
53
+ end
54
+
55
+ private
56
+
57
+ def zfs_zed
58
+ service_dir = '/etc/runit/runsvdir/default/'
59
+
60
+ Helpers.mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
61
+ Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
62
+ Helpers.touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
63
+ fork { command '/etc/sv/zed/run' }
64
+ command "ln -fs /etc/sv/zed #{service_dir}"
65
+ end
66
+
67
+ def zed_update_path
68
+ Dir.glob("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/*").each do |f|
69
+ unless system('sed', '-Ei', "s|#{MOUNTPOINT}/?|/|", f)
70
+ raise 'System exec sed'
71
+ end
72
+ end
73
+ end
74
+
75
+ def hostid
76
+ command 'zgenhostid $(hostid)'
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  module Zfs
@@ -11,4 +13,5 @@ require_relative 'zfs/format'
11
13
  require_relative 'zfs/mount'
12
14
  require_relative 'zfs/config'
13
15
  require_relative 'zfs/deps'
16
+ require_relative 'zfs/void'
14
17
  require_relative 'zfs/encrypt'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module FileSystem
3
5
  end
@@ -1,101 +1,63 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
 
3
5
  module Getch
4
6
  module Gentoo
5
7
  class Boot
6
- def initialize(opts)
7
- @disk = opts.boot_disk ? opts.boot_disk : opts.disk
8
- @user = opts.username
9
- @config = Getch.class_fs::Config.new()
8
+ def initialize
9
+ @user = Getch::OPTIONS[:username]
10
10
  end
11
11
 
12
12
  def start
13
- @config.fstab
14
13
  bootloader
15
14
  password
15
+ permission
16
16
  the_end
17
17
  end
18
18
 
19
19
  def bootloader
20
- if Helpers::efi?
21
- bootctl
22
- else
23
- grub
24
- end
20
+ # Ensure all packages are build
21
+ Getch::Emerge.new('@world').pkg!
22
+ bootloader = Getch::Gentoo::Bootloader.new
23
+ bootloader.setup
24
+ bootloader.update
25
25
  end
26
26
 
27
- # bootctl is alrealy installed with the stage3-amd64-systemd
28
- def bootctl
29
- bootctl_dep
30
- puts "Configuring systemd-boot."
31
- # ref: https://forums.gentoo.org/viewtopic-p-8118822.html
32
- esp = '/efi'
33
- exec_chroot("bootctl --path #{esp} install")
34
- datas_loader = [
35
- 'default gentoo',
36
- 'timeout 3',
37
- 'editor 0'
38
- ]
39
- @config.systemd_boot
40
- File.write("#{MOUNTPOINT}/#{esp}/loader/loader.conf", datas_loader.join("\n"))
41
-
42
- FileUtils.cp("#{MOUNTPOINT}/usr/src/linux/arch/x86/boot/bzImage", "#{MOUNTPOINT}/#{esp}/vmlinuz", preserve: true)
43
-
44
- initramfs = Dir.glob("#{MOUNTPOINT}/boot/initramfs-*.img")
45
- FileUtils.cp("#{initramfs[0]}", "#{MOUNTPOINT}/#{esp}/initramfs", preserve: true) if initramfs != []
46
-
47
- exec_chroot("bootctl --path #{esp} update")
48
- end
27
+ def password
28
+ puts 'Password for root'
29
+ chroot "passwd"
30
+ return unless @user
49
31
 
50
- def bootctl_dep
51
- puts 'Installing systemd-boot...'
52
- exec_chroot("euse -p sys-apps/systemd -E gnuefi")
53
- Getch::Emerge.new("sys-apps/systemd efivar").pkg!
32
+ puts "Creating user #{@user}"
33
+ Getch::Chroot.new("useradd -m -G users,wheel,audio,video #{@user}").run!
34
+ puts "Password for your user #{@user}"
35
+ chroot "passwd #{@user}"
54
36
  end
55
37
 
56
- def grub
57
- puts 'Installing GRUB...'
58
- Getch::Emerge.new("sys-boot/grub:2").pkg!
59
- @config.grub
60
- exec_chroot("grub-install /dev/#{@disk}")
61
- exec_chroot('grub-mkconfig -o /boot/grub/grub.cfg')
62
- end
38
+ private
63
39
 
64
- def password
65
- puts 'Password for root'
66
- cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile && passwd\""
67
- system(cmd)
40
+ def permission
41
+ FileUtils.chmod_R 0755, "#{MOUNTPOINT}/etc/portage"
68
42
  if @user
69
- puts "Creating user #{@user}"
70
- exec_chroot("useradd -m -G users,wheel,audio,video #{@user}")
71
- puts "Password for your user #{@user}"
72
- cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile && passwd #{@user}\""
73
- system(cmd)
43
+ Getch::Chroot.new("chown -R #{@user}:#{@user} /home/#{@user}").run!
74
44
  end
75
45
  end
76
46
 
77
- private
78
-
79
47
  def the_end
80
- #Helpers::exec_or_die("umount -l /mnt/gentoo/dev{/shm,/pts,}")
81
- #Helpers::exec_or_die("umount -R #{MOUNTPOINT}")
82
48
  puts
83
- puts "getch has finish, before reboot, you can:"
49
+ puts 'getch has finish, before reboot, you can:'
84
50
  puts " + Chroot on your system with: chroot #{MOUNTPOINT} /bin/bash"
85
- puts " + Install more packages like networkmanager or emacs"
51
+ puts ' + Install more packages like networkmanager or emacs'
86
52
  puts
87
- puts " + Add more modules for your kernel (graphic, wifi card) and recompile it with:"
88
- puts " genkernel --kernel-config=/usr/src/linux/.config all "
53
+ puts ' + Add more modules for your kernel (graphic, wifi card) and recompile it with:'
54
+ puts ' genkernel --kernel-config=/usr/src/linux/.config all '
89
55
  puts
90
- puts "Reboot the system when you have done !"
56
+ puts 'Reboot the system when you have done !'
91
57
  end
92
58
 
93
- def exec_chroot(cmd)
94
- script = "chroot #{MOUNTPOINT} /bin/bash -c \"
95
- source /etc/profile
96
- #{cmd}
97
- \""
98
- Getch::Command.new(script).run!
59
+ def chroot(cmd)
60
+ system('chroot', MOUNTPOINT, '/bin/bash', '-c', cmd)
99
61
  end
100
62
  end
101
63
  end
@@ -0,0 +1,68 @@
1
+ # frozen_strin_literal: true
2
+
3
+ module Getch
4
+ module Gentoo
5
+ class Bootloader
6
+ def initialize
7
+ @pkgs = []
8
+ @class_fs = Getch.select_fs
9
+ @config = @class_fs::Config.new
10
+ @disk = Getch::OPTIONS[:boot_disk] ?
11
+ Getch::OPTIONS[:boot_disk] :
12
+ Getch::OPTIONS[:disk]
13
+ @esp = '/efi'
14
+ end
15
+
16
+ def start
17
+ @config.fstab
18
+ config_useflag
19
+ dependencies
20
+ install
21
+ @config.cmdline
22
+ end
23
+
24
+ def config_useflag
25
+ end
26
+
27
+ # Dracut is used by sys-kernel/gentoo-kernel
28
+ def dependencies
29
+ @pkgs << 'app-shells/dash'
30
+ @pkgs << 'sys-kernel/dracut'
31
+ if Helpers.efi?
32
+ @pkgs << 'efivar'
33
+ @pkgs << 'sys-kernel/installkernel-systemd-boot'
34
+ else
35
+ @pkgs << 'sys-boot/grub:2'
36
+ @pkgs << 'sys-kernel/installkernel-gentoo' # for Grub
37
+ end
38
+ end
39
+
40
+ def install
41
+ all_pkgs = @pkgs.join(' ')
42
+ Getch::Emerge.new(all_pkgs).pkg!
43
+ end
44
+
45
+ def setup
46
+ if Helpers.efi?
47
+ Getch::Chroot.new("bootctl --path #{@esp} install").run!
48
+ else
49
+ Getch::Chroot.new("grub-install /dev/#{@disk}").run!
50
+ end
51
+ end
52
+
53
+ def update
54
+ Getch::Emerge.new('--config sys-kernel/gentoo-kernel').pkg!
55
+ if Helpers.efi?
56
+ puts ' => Updating systemd-boot...'
57
+ Getch::Chroot.new("bootctl --path #{@esp} update").run!
58
+ else
59
+ puts ' => Updating grub...'
60
+ Getch::Chroot.new('grub-mkconfig -o /boot/grub/grub.cfg').run!
61
+ end
62
+ end
63
+
64
+ def config
65
+ end
66
+ end
67
+ end
68
+ end
@@ -1,58 +1,55 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Getch
2
4
  module Gentoo
3
5
  class Chroot
4
6
  def initialize
5
- @state = Getch::States.new()
6
7
  @pkgs = []
7
8
  mount
8
9
  end
9
10
 
10
11
  def cpuflags
11
- Getch::Emerge.new("app-portage/cpuid2cpuflags").pkg!
12
+ Getch::Emerge.new('app-portage/cpuid2cpuflags').pkg!
12
13
  cpuflags = `chroot #{MOUNTPOINT} /bin/bash -c "source /etc/profile; cpuid2cpuflags"`.chomp
13
14
  File.write("#{MOUNTPOINT}/etc/portage/package.use/00cpuflags", "*/* #{cpuflags}")
14
15
  end
15
16
 
16
17
  def update
17
18
  return if STATES[:gentoo_update]
18
- puts "Downloading the last ebuilds for Gentoo..."
19
- Helpers::create_dir("#{MOUNTPOINT}/var/db/repos/gentoo")
20
- cmd = "emaint sync --auto"
19
+
20
+ puts 'Downloading the last ebuilds for Gentoo...'
21
+ Helpers.create_dir("#{MOUNTPOINT}/var/db/repos/gentoo")
22
+ cmd = 'emaint sync --auto'
21
23
  exec_chroot(cmd)
22
24
  end
23
25
 
24
26
  def world
25
27
  return if STATES[:gentoo_update]
26
- puts "Update Gentoo world"
27
- Getch::Emerge.new("emerge --update --deep --newuse @world").run!
28
- @state.update
28
+
29
+ puts 'Update Gentoo world'
30
+ Getch::Emerge.new('emerge --update --deep --changed-use --newuse @world').run!
29
31
  end
30
32
 
31
33
  def systemd
32
- puts "Updating locale, keymap..."
33
- cmd = "locale-gen; emerge --config sys-libs/timezone-data"
34
+ puts 'Updating locale, keymap...'
35
+ cmd = 'locale-gen; emerge --config sys-libs/timezone-data'
34
36
  exec_chroot(cmd)
35
37
  end
36
38
 
37
- def kernel
39
+ def kernel_license
38
40
  return if Dir.exist? "#{MOUNTPOINT}/usr/src/linux"
41
+
39
42
  license = "#{MOUNTPOINT}/etc/portage/package.license"
40
43
  File.write(license, "sys-kernel/linux-firmware linux-fw-redistributable no-source-code\n")
41
- @pkgs << "sys-kernel/gentoo-sources"
42
- @pkgs << "dev-util/dwarves"
43
- end
44
-
45
- def kernel_deps
46
- Getch::Emerge.new("gentoolkit").pkg!
47
- exec_chroot("euse -p sys-apps/kmod -E lzma")
48
- @pkgs << "sys-apps/kmod"
49
44
  end
50
45
 
51
46
  def install_pkgs
52
- @pkgs << "app-admin/sudo"
53
- @pkgs << "app-editors/vim"
54
- @pkgs << "sys-kernel/linux-firmware"
55
- all_pkgs = @pkgs.join(" ")
47
+ @pkgs << 'app-portage/gentoolkit'
48
+ @pkgs << 'app-admin/sudo'
49
+ @pkgs << 'app-editors/vim'
50
+ @pkgs << 'net-firewall/iptables'
51
+ @pkgs << 'sys-fs/dosftools' if Helpers.efi?
52
+ all_pkgs = @pkgs.join(' ')
56
53
  puts "Installing #{all_pkgs}..."
57
54
  Getch::Emerge.new(all_pkgs).pkg!
58
55
  end
@@ -60,12 +57,12 @@ module Getch
60
57
  private
61
58
 
62
59
  def mount
63
- puts "Populate /proc, /sys and /dev."
64
- Helpers::exec_or_die("mount --types proc /proc \"#{MOUNTPOINT}/proc\"")
65
- Helpers::exec_or_die("mount --rbind /sys \"#{MOUNTPOINT}/sys\"")
66
- Helpers::exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/sys\"")
67
- Helpers::exec_or_die("mount --rbind /dev \"#{MOUNTPOINT}/dev\"")
68
- Helpers::exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/dev\"")
60
+ puts 'Populate /proc, /sys and /dev.'
61
+ Helpers.exec_or_die("mount --types proc /proc \"#{MOUNTPOINT}/proc\"")
62
+ Helpers.exec_or_die("mount --rbind /sys \"#{MOUNTPOINT}/sys\"")
63
+ Helpers.exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/sys\"")
64
+ Helpers.exec_or_die("mount --rbind /dev \"#{MOUNTPOINT}/dev\"")
65
+ Helpers.exec_or_die("mount --make-rslave \"#{MOUNTPOINT}/dev\"")
69
66
  # Maybe add /dev/shm like describe here:
70
67
  # https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base
71
68
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'tempfile'
3
5
  require 'securerandom'
@@ -11,12 +13,13 @@ module Getch
11
13
  end
12
14
 
13
15
  def portage
14
- grub_pc = Helpers::efi? ? '' : 'GRUB_PLATFORMS="pc"'
16
+ grub_pc = Helpers.efi? ? '' : 'GRUB_PLATFORMS="pc"'
15
17
  nproc = `nproc`.chomp()
16
18
 
17
19
  # Add cpu name
18
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
19
- raise "Error, no cpu found" if ! cpu or cpu == ""
21
+ raise 'Error, no cpu found' unless cpu || cpu == ''
22
+
20
23
  @log.debug "CPU found ==> #{cpu}"
21
24
 
22
25
  tmp = Tempfile.new('make.conf')
@@ -29,7 +32,7 @@ module Getch
29
32
  end
30
33
  }
31
34
 
32
- FileUtils.copy_file(tmp, @make, preserve = true)
35
+ FileUtils.copy_file(tmp, @make)
33
36
 
34
37
  # Add the rest
35
38
  data = [
@@ -37,16 +40,17 @@ module Getch
37
40
  "MAKEOPTS=\"-j#{nproc}\"",
38
41
  'ACCEPT_KEYWORDS="amd64"',
39
42
  'INPUT_DEVICES="libinput"',
43
+ 'USE="${USE} audit"',
40
44
  grub_pc
41
45
  ]
42
- File.write(@make, data.join("\n"), mode: "a")
46
+ File.write(@make, data.join("\n"), mode: 'a')
43
47
  end
44
48
 
45
49
  # Write a repos.conf/gentoo.conf with the gpg verification
46
50
  def repo
47
51
  src = "#{MOUNTPOINT}/usr/share/portage/config/repos.conf"
48
52
  dest = "#{MOUNTPOINT}/etc/portage/repos.conf"
49
- FileUtils.mkdir dest, mode: 0644 if ! Dir.exist?(dest)
53
+ FileUtils.mkdir dest, mode: 0644 unless Dir.exist?(dest)
50
54
  tmp = Tempfile.new('gentoo.conf')
51
55
  line_count = 0
52
56
 
@@ -60,22 +64,22 @@ module Getch
60
64
  line_count += 1
61
65
  }
62
66
 
63
- FileUtils.copy_file(tmp, "#{dest}/gentoo.conf", preserve = true)
67
+ FileUtils.copy_file(tmp, "#{dest}/gentoo.conf")
64
68
  end
65
69
 
66
70
  def network
67
71
  src = '/etc/resolv.conf'
68
72
  dest = "#{MOUNTPOINT}/etc/resolv.conf"
69
- FileUtils.copy_file(src, dest, preserve = true)
73
+ FileUtils.copy_file(src, dest)
70
74
  end
71
75
 
72
- def systemd(options)
73
- control_options(options)
74
- File.write("#{MOUNTPOINT}/etc/locale.gen", @utf8)
75
- File.write("#{MOUNTPOINT}/etc/locale.conf", "LANG=#{@lang}\n")
76
- File.write("#{MOUNTPOINT}/etc/locale.conf", 'LC_COLLATE=C', mode: 'a')
77
- File.write("#{MOUNTPOINT}/etc/timezone", "#{options.zoneinfo}")
78
- File.write("#{MOUNTPOINT}/etc/vconsole.conf", "KEYMAP=#{options.keymap}")
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")
79
83
  end
80
84
 
81
85
  def hostname
@@ -85,21 +89,55 @@ module Getch
85
89
 
86
90
  def portage_fs
87
91
  portage = "#{MOUNTPOINT}/etc/portage"
88
- Helpers::create_dir("#{portage}/package.use")
89
- Helpers::create_dir("#{portage}/package.accept_keywords")
90
- Helpers::create_dir("#{portage}/package.unmask")
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
91
100
 
92
- Helpers::add_file("#{portage}/package.use/zzz_via_autounmask")
93
- Helpers::add_file("#{portage}/package.accept_keywords/zzz_via_autounmask")
94
- Helpers::add_file("#{portage}/package.unmask/zzz_via_autounmask")
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
95
133
  end
96
134
 
97
135
  private
98
136
 
99
- def control_options(options)
100
- search_zone(options.zoneinfo)
101
- search_utf8(options.language)
102
- search_key(options.keymap)
137
+ def control_options
138
+ search_zone(Getch::OPTIONS[:zoneinfo])
139
+ search_utf8(Getch::OPTIONS[:language])
140
+ search_key(Getch::OPTIONS[:keymap])
103
141
  end
104
142
 
105
143
  def search_key(keys)
@@ -107,22 +145,22 @@ module Getch
107
145
  Dir.glob("#{MOUNTPOINT}/usr/share/keymaps/**/#{keys}.map.gz") { |f|
108
146
  @keymap = f
109
147
  }
110
- raise ArgumentError, "No keymap #{@keymap} found" if ! @keymap
148
+ raise ArgumentError, "No keymap #{@keymap} found" unless @keymap
111
149
  end
112
150
 
113
151
  def search_zone(zone)
114
- if !File.exist?("#{MOUNTPOINT}/usr/share/zoneinfo/#{zone}")
152
+ unless File.exist? "#{MOUNTPOINT}/usr/share/zoneinfo/#{zone}"
115
153
  raise ArgumentError, "Zoneinfo #{zone} doesn\'t exist."
116
154
  end
117
155
  end
118
156
 
119
157
  def search_utf8(lang)
120
158
  @utf8, @lang = nil, nil
121
- File.open("#{MOUNTPOINT}/usr/share/i18n/SUPPORTED").each { |l|
122
- @utf8 = $~[0] if l.match(/^#{lang}[. ]+[utf\-8 ]+/i)
123
- @lang = $~[0] if l.match(/^#{lang}[. ]+utf\-8/i)
124
- }
125
- raise ArgumentError, "Lang #{lang} no found" if ! @utf8
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
126
164
  end
127
165
  end
128
166
  end