getch 0.0.9 → 0.1.5

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 (64) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/CHANGELOG.md +45 -0
  5. data/README.md +57 -11
  6. data/bin/setup.sh +4 -2
  7. data/lib/getch.rb +27 -10
  8. data/lib/getch/command.rb +25 -4
  9. data/lib/getch/config.rb +58 -0
  10. data/lib/getch/filesystem.rb +6 -0
  11. data/lib/getch/filesystem/clean.rb +58 -0
  12. data/lib/getch/filesystem/device.rb +61 -0
  13. data/lib/getch/filesystem/ext4/config.rb +8 -9
  14. data/lib/getch/filesystem/ext4/device.rb +2 -7
  15. data/lib/getch/filesystem/ext4/encrypt/config.rb +8 -9
  16. data/lib/getch/filesystem/ext4/encrypt/deps.rb +3 -19
  17. data/lib/getch/filesystem/ext4/encrypt/device.rb +3 -8
  18. data/lib/getch/filesystem/ext4/encrypt/format.rb +3 -5
  19. data/lib/getch/filesystem/ext4/encrypt/mount.rb +6 -43
  20. data/lib/getch/filesystem/ext4/encrypt/partition.rb +19 -38
  21. data/lib/getch/filesystem/ext4/format.rb +3 -5
  22. data/lib/getch/filesystem/ext4/mount.rb +7 -46
  23. data/lib/getch/filesystem/ext4/partition.rb +16 -39
  24. data/lib/getch/filesystem/lvm/config.rb +11 -15
  25. data/lib/getch/filesystem/lvm/deps.rb +5 -20
  26. data/lib/getch/filesystem/lvm/device.rb +33 -9
  27. data/lib/getch/filesystem/lvm/encrypt/config.rb +9 -12
  28. data/lib/getch/filesystem/lvm/encrypt/deps.rb +5 -22
  29. data/lib/getch/filesystem/lvm/encrypt/device.rb +33 -9
  30. data/lib/getch/filesystem/lvm/encrypt/format.rb +3 -3
  31. data/lib/getch/filesystem/lvm/encrypt/mount.rb +7 -46
  32. data/lib/getch/filesystem/lvm/encrypt/partition.rb +20 -31
  33. data/lib/getch/filesystem/lvm/format.rb +11 -7
  34. data/lib/getch/filesystem/lvm/mount.rb +7 -46
  35. data/lib/getch/filesystem/lvm/partition.rb +19 -31
  36. data/lib/getch/filesystem/mount.rb +56 -0
  37. data/lib/getch/filesystem/partition.rb +77 -0
  38. data/lib/getch/filesystem/zfs.rb +14 -0
  39. data/lib/getch/filesystem/zfs/config.rb +57 -0
  40. data/lib/getch/filesystem/zfs/deps.rb +95 -0
  41. data/lib/getch/filesystem/zfs/device.rb +58 -0
  42. data/lib/getch/filesystem/zfs/encrypt.rb +15 -0
  43. data/lib/getch/filesystem/zfs/encrypt/config.rb +67 -0
  44. data/lib/getch/filesystem/zfs/encrypt/deps.rb +97 -0
  45. data/lib/getch/filesystem/zfs/encrypt/device.rb +60 -0
  46. data/lib/getch/filesystem/zfs/encrypt/format.rb +104 -0
  47. data/lib/getch/filesystem/zfs/encrypt/mount.rb +51 -0
  48. data/lib/getch/filesystem/zfs/encrypt/partition.rb +66 -0
  49. data/lib/getch/filesystem/zfs/format.rb +113 -0
  50. data/lib/getch/filesystem/zfs/mount.rb +48 -0
  51. data/lib/getch/filesystem/zfs/partition.rb +65 -0
  52. data/lib/getch/gentoo.rb +11 -4
  53. data/lib/getch/gentoo/boot.rb +34 -16
  54. data/lib/getch/gentoo/chroot.rb +16 -25
  55. data/lib/getch/gentoo/config.rb +59 -7
  56. data/lib/getch/gentoo/sources.rb +54 -26
  57. data/lib/getch/gentoo/use.rb +43 -0
  58. data/lib/getch/gentoo/use_flag.rb +64 -0
  59. data/lib/getch/guard.rb +62 -0
  60. data/lib/getch/helpers.rb +31 -13
  61. data/lib/getch/options.rb +24 -9
  62. data/lib/getch/version.rb +1 -1
  63. metadata +40 -18
  64. metadata.gz.sig +0 -0
@@ -0,0 +1,51 @@
1
+ require 'fileutils'
2
+
3
+ module Getch
4
+ module FileSystem
5
+ module Zfs
6
+ module Encrypt
7
+ class Mount < Getch::FileSystem::Zfs::Encrypt::Device
8
+ def initialize
9
+ super
10
+ @root_dir = MOUNTPOINT
11
+ @mount = Getch::FileSystem::Mount.new
12
+ @state = Getch::States.new
13
+ @log = Getch::Log.new
14
+ end
15
+
16
+ def run
17
+ return if STATES[:mount]
18
+ exec("zpool export -a")
19
+ exec("rm -rf #{MOUNTPOINT}/*")
20
+ exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
21
+ exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
22
+ exec("zfs load-key -a")
23
+ @mount.swap(@dev_swap)
24
+ mount_root
25
+ mount_boot
26
+ @mount.esp(@dev_esp)
27
+ exec("zfs mount -a")
28
+ @state.mount
29
+ end
30
+
31
+ private
32
+
33
+ def mount_root
34
+ Helpers::mkdir(@root_dir)
35
+ exec("zfs mount #{@pool_name}/ROOT/gentoo")
36
+ end
37
+
38
+ def mount_boot
39
+ return if ! @dev_boot
40
+ exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
41
+ end
42
+
43
+ def exec(cmd)
44
+ @log.info("==> #{cmd}")
45
+ Helpers::sys(cmd)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,66 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ module Encrypt
5
+ class Partition < Getch::FileSystem::Zfs::Encrypt::Device
6
+ def initialize
7
+ super
8
+ @state = Getch::States.new()
9
+ @clean = Getch::FileSystem::Clean
10
+ @partition = Getch::FileSystem::Partition.new
11
+ @log = Getch::Log.new()
12
+ run
13
+ end
14
+
15
+ def run
16
+ return if STATES[:partition ]
17
+ @clean.old_zpool
18
+ @clean.hdd(@disk)
19
+ @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
20
+
21
+ partition
22
+ cache
23
+ @state.partition
24
+ end
25
+
26
+ private
27
+
28
+ def partition
29
+ if Helpers::efi?
30
+ @partition.efi(@dev_esp)
31
+ @partition.swap(@dev_swap) if !@cache_disk
32
+ @partition.root(@dev_root, "BF00") if @root_part != 1
33
+ else
34
+ @partition.gpt(@dev_gpt)
35
+ @partition.boot(@dev_boot)
36
+ @partition.swap(@dev_swap) if !@cache_disk
37
+ @partition.root(@dev_root, "BF00") if @root_part != 1
38
+ end
39
+ end
40
+
41
+ def cache
42
+ if @cache_disk
43
+ mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
44
+ exec("sgdisk -n1:0:+#{mem} -t1:8200 /dev/#{@cache_disk}")
45
+ exec("sgdisk -n2:0:+4G -t2:BF07 /dev/#{@cache_disk}")
46
+ exec("sgdisk -n3:0:0 -t3:BF08 /dev/#{@cache_disk}")
47
+ end
48
+ end
49
+
50
+ # Partition_efi
51
+ # /efi - EFI system partition - 260MB
52
+ # / - Root
53
+
54
+ # Partition_bios
55
+ # None - Bios Boot Partition - 1MiB
56
+ # /boot - Boot - 8300
57
+ # / - Root
58
+
59
+ def exec(cmd)
60
+ Helpers::sys(cmd)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,113 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ class Format < Getch::FileSystem::Zfs::Device
5
+ def initialize
6
+ super
7
+ @log = Getch::Log.new
8
+ @state = Getch::States.new
9
+ if ! @id
10
+ @log.info "Research pool id for #{@dev_root}..."
11
+ @id = Helpers::pool_id(@dev_root)
12
+ @boot_pool_name = "bpool-#{@id}"
13
+ @pool_name = "rpool-#{@id}"
14
+ end
15
+ format
16
+ end
17
+
18
+ private
19
+
20
+ def format
21
+ return if STATES[:format]
22
+ raise "Error, no id found for #{@dev_root}." if ! @id
23
+ @log.info "Create #{@id} for #{@pool_name}"
24
+ system("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
25
+ zfs
26
+ cache
27
+ datasets
28
+ @state.format
29
+ end
30
+
31
+ def zfs
32
+ bloc=`blockdev --getpbsz #{@dev_root}`
33
+ ashift = case bloc
34
+ when /8096/
35
+ 13
36
+ when /4096/
37
+ 12
38
+ else # 512
39
+ 9
40
+ end
41
+
42
+ Helpers::mkdir(MOUNTPOINT)
43
+ @log.debug("ashift found for #{bloc} - #{ashift}")
44
+
45
+ if @dev_boot
46
+ # https://openzfs.github.io/openzfs-docs/Getting%20Started/Ubuntu/Ubuntu%2020.04%20Root%20on%20ZFS.html
47
+ @log.info("Creating boot pool on #{@pool_name}")
48
+ exec("zpool create -f \\
49
+ -o ashift=#{ashift} -o autotrim=on -d \\
50
+ -o feature@async_destroy=enabled \\
51
+ -o feature@bookmarks=enabled \\
52
+ -o feature@embedded_data=enabled \\
53
+ -o feature@empty_bpobj=enabled \\
54
+ -o feature@enabled_txg=enabled \\
55
+ -o feature@extensible_dataset=enabled \\
56
+ -o feature@filesystem_limits=enabled \\
57
+ -o feature@hole_birth=enabled \\
58
+ -o feature@large_blocks=enabled \\
59
+ -o feature@lz4_compress=enabled \\
60
+ -o feature@spacemap_histogram=enabled \\
61
+ -O acltype=posixacl -O canmount=off -O compression=lz4 \\
62
+ -O devices=off -O normalization=formD -O atime=off -O xattr=sa \\
63
+ -O mountpoint=/boot -R #{MOUNTPOINT} \\
64
+ #{@boot_pool_name} #{@dev_boot}
65
+ ")
66
+ end
67
+
68
+ exec("zpool create -f -o ashift=#{ashift} -o autotrim=on \\
69
+ -O acltype=posixacl -O canmount=off -O compression=lz4 \\
70
+ -O dnodesize=auto -O normalization=formD -O atime=off \\
71
+ -O xattr=sa -O mountpoint=/ -R #{MOUNTPOINT} \\
72
+ #{@pool_name} #{@dev_root}
73
+ ")
74
+ end
75
+
76
+ def cache
77
+ system("mkswap -f #{@dev_swap}")
78
+ if @dev_log
79
+ exec("zpool add #{@pool_name} log #{@dev_log}")
80
+ end
81
+ if @dev_cache
82
+ exec("zpool add #{@pool_name} cache #{@dev_cache}")
83
+ end
84
+ end
85
+
86
+ def datasets
87
+ exec("zfs create -o canmount=off -o mountpoint=none #{@pool_name}/ROOT")
88
+ exec("zfs create -o canmount=off -o mountpoint=none #{@boot_pool_name}/BOOT") if @dev_boot
89
+
90
+ exec("zfs create -o canmount=noauto -o mountpoint=/ #{@pool_name}/ROOT/gentoo")
91
+ exec("zfs create -o canmount=noauto -o mountpoint=/boot #{@boot_pool_name}/BOOT/gentoo") if @dev_boot
92
+
93
+ exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/usr")
94
+ exec("zfs create #{@pool_name}/ROOT/gentoo/usr/src")
95
+ exec("zfs create -o canmount=off #{@pool_name}/ROOT/gentoo/var")
96
+ exec("zfs create #{@pool_name}/ROOT/gentoo/var/log")
97
+ exec("zfs create #{@pool_name}/ROOT/gentoo/var/db")
98
+ exec("zfs create #{@pool_name}/ROOT/gentoo/var/tmp")
99
+
100
+ exec("zfs create -o canmount=off -o mountpoint=/ #{@pool_name}/USERDATA")
101
+ exec("zfs create -o canmount=on -o mountpoint=/root #{@pool_name}/USERDATA/root")
102
+ if @user
103
+ exec("zfs create -o canmount=on -o mountpoint=/home/#{@user} #{@pool_name}/USERDATA/#{@user}")
104
+ end
105
+ end
106
+
107
+ def exec(cmd)
108
+ Getch::Command.new(cmd).run!
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,48 @@
1
+ require 'fileutils'
2
+
3
+ module Getch
4
+ module FileSystem
5
+ module Zfs
6
+ class Mount < Getch::FileSystem::Zfs::Device
7
+ def initialize
8
+ super
9
+ @root_dir = MOUNTPOINT
10
+ @mount = Getch::FileSystem::Mount.new
11
+ @state = Getch::States.new
12
+ @log = Getch::Log.new
13
+ end
14
+
15
+ def run
16
+ return if STATES[:mount]
17
+ exec("zpool export -a")
18
+ exec("rm -rf #{MOUNTPOINT}/*")
19
+ exec("zpool import -N -R #{MOUNTPOINT} #{@pool_name}")
20
+ exec("zpool import -N -R #{MOUNTPOINT} #{@boot_pool_name}") if @dev_boot
21
+ @mount.swap(@dev_swap)
22
+ mount_root
23
+ mount_boot
24
+ @mount.esp(@dev_esp)
25
+ exec("zfs mount -a")
26
+ @state.mount
27
+ end
28
+
29
+ private
30
+
31
+ def mount_root
32
+ Helpers::mkdir(@root_dir)
33
+ exec("zfs mount #{@pool_name}/ROOT/gentoo")
34
+ end
35
+
36
+ def mount_boot
37
+ return if ! @dev_boot
38
+ exec("zfs mount #{@boot_pool_name}/BOOT/gentoo")
39
+ end
40
+
41
+ def exec(cmd)
42
+ @log.info("==> #{cmd}")
43
+ Helpers::sys(cmd)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,65 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ class Partition < Getch::FileSystem::Zfs::Device
5
+ def initialize
6
+ super
7
+ @clean = Getch::FileSystem::Clean
8
+ @partition = Getch::FileSystem::Partition.new
9
+ @state = Getch::States.new()
10
+ @log = Getch::Log.new()
11
+ run_partition
12
+ end
13
+
14
+ def run_partition
15
+ return if STATES[:partition ]
16
+ @clean.old_zpool
17
+ @clean.hdd(@disk)
18
+ @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
19
+
20
+ partition
21
+ cache
22
+ @state.partition
23
+ end
24
+
25
+ private
26
+
27
+ def partition
28
+ if @efi
29
+ @partition.efi(@dev_esp)
30
+ @partition.swap(@dev_swap) if !@cache_disk
31
+ @partition.root(@dev_root, "BF00") if @root_part != 1
32
+ else
33
+ @partition.gpt(@dev_gpt)
34
+ # Boot pool for GRUB2
35
+ @partition.boot(@dev_boot)
36
+ @partition.swap(@dev_swap) if !@cache_disk
37
+ @partition.root(@dev_root, "BF00") if @root_part != 1
38
+ end
39
+ end
40
+
41
+ def cache
42
+ if @cache_disk
43
+ mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
44
+ exec("sgdisk -n1:0:+#{mem} -t1:8200 /dev/#{@cache_disk}")
45
+ exec("sgdisk -n2:0:+4G -t2:BF07 /dev/#{@cache_disk}")
46
+ exec("sgdisk -n3:0:0 -t3:BF00 /dev/#{@cache_disk}")
47
+ end
48
+ end
49
+
50
+ # Partition_efi
51
+ # /efi - EFI system partition - 260MB
52
+ # / - Root
53
+
54
+ # Partition_bios
55
+ # None - Bios Boot Partition - 1MiB
56
+ # /boot - Boot - 8300
57
+ # / - Root
58
+
59
+ def exec(cmd)
60
+ Getch::Command.new(cmd).run!
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
data/lib/getch/gentoo.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'open-uri'
2
- require 'open3'
3
1
  require_relative 'gentoo/stage'
4
2
  require_relative 'gentoo/config'
5
3
  require_relative 'gentoo/chroot'
6
4
  require_relative 'gentoo/sources'
7
5
  require_relative 'gentoo/boot'
6
+ require_relative 'gentoo/use'
7
+ require_relative 'gentoo/use_flag'
8
8
 
9
9
  module Getch
10
10
  module Gentoo
@@ -29,6 +29,7 @@ module Getch
29
29
  config = Getch::Gentoo::Config.new()
30
30
  config.portage
31
31
  config.portage_fs
32
+ config.portage_bashrc
32
33
  config.repo
33
34
  config.network
34
35
  config.systemd(options)
@@ -36,15 +37,21 @@ module Getch
36
37
  @state.config
37
38
  end
38
39
 
39
- def chroot
40
+ def chroot(options)
40
41
  chroot = Getch::Gentoo::Chroot.new()
41
42
  chroot.update
43
+ chroot.cpuflags
42
44
  chroot.systemd
45
+
46
+ flags = Getch::Gentoo::UseFlag.new(options)
47
+ flags.apply
48
+
43
49
  chroot.world
44
50
  return if STATES[:gentoo_kernel]
45
51
  chroot.kernel
46
52
  chroot.kernel_deps
47
53
  chroot.install_pkgs
54
+ chroot.kernel_link
48
55
  end
49
56
 
50
57
  def kernel
@@ -52,8 +59,8 @@ module Getch
52
59
  source = Getch::Gentoo::Sources.new()
53
60
  new
54
61
  source.build_kspp
55
- source.init_config
56
62
  source.build_others
63
+ source.firewall
57
64
  source.make
58
65
  @state.kernel
59
66
  end
@@ -4,7 +4,7 @@ module Getch
4
4
  module Gentoo
5
5
  class Boot
6
6
  def initialize(opts)
7
- @disk = opts.disk
7
+ @disk = opts.boot_disk ? opts.boot_disk : opts.disk
8
8
  @user = opts.username
9
9
  @config = Getch.class_fs::Config.new()
10
10
  end
@@ -13,10 +13,14 @@ module Getch
13
13
  @config.fstab
14
14
  bootloader
15
15
  password
16
- umount
16
+ permission
17
+ the_end
17
18
  end
18
19
 
19
20
  def bootloader
21
+ # Ensure than systemd is build with all our flags
22
+ Getch::Emerge.new("@world").pkg!
23
+
20
24
  if Helpers::efi?
21
25
  bootctl
22
26
  else
@@ -29,8 +33,8 @@ module Getch
29
33
  bootctl_dep
30
34
  puts "Configuring systemd-boot."
31
35
  # ref: https://forums.gentoo.org/viewtopic-p-8118822.html
32
- esp = '/boot/efi'
33
- exec_chroot("bootctl --path #{esp} install")
36
+ esp = '/efi'
37
+ Getch::Chroot.new("bootctl --path #{esp} install").run!
34
38
  datas_loader = [
35
39
  'default gentoo',
36
40
  'timeout 3',
@@ -44,43 +48,57 @@ module Getch
44
48
  initramfs = Dir.glob("#{MOUNTPOINT}/boot/initramfs-*.img")
45
49
  FileUtils.cp("#{initramfs[0]}", "#{MOUNTPOINT}/#{esp}/initramfs", preserve: true) if initramfs != []
46
50
 
47
- exec_chroot("bootctl --path #{esp} update")
51
+ Getch::Chroot.new("bootctl --path #{esp} update").run!
48
52
  end
49
53
 
50
54
  def bootctl_dep
51
55
  puts 'Installing systemd-boot...'
52
- exec_chroot("euse -p sys-apps/systemd -E gnuefi")
53
- Getch::Emerge.new("sys-apps/systemd efivar").pkg!
56
+ Getch::Emerge.new("efivar").pkg!
54
57
  end
55
58
 
56
59
  def grub
57
60
  puts 'Installing GRUB...'
58
61
  Getch::Emerge.new("sys-boot/grub:2").pkg!
59
62
  @config.grub
60
- exec_chroot("grub-install /dev/#{@disk}")
61
- exec_chroot('grub-mkconfig -o /boot/grub/grub.cfg')
63
+ Getch::Chroot.new("grub-install /dev/#{@disk}").run!
64
+ Getch::Chroot.new("grub-mkconfig -o /boot/grub/grub.cfg").run!
62
65
  end
63
66
 
64
67
  def password
65
68
  puts 'Password for root'
66
69
  cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile && passwd\""
67
70
  system(cmd)
68
- if @user != nil
71
+ if @user
69
72
  puts "Creating user #{@user}"
70
- exec_chroot("useradd -m -G users,wheel,audio,video #{@user}")
73
+ Getch::Chroot.new("useradd -m -G users,wheel,audio,video #{@user}").run!
71
74
  puts "Password for your user #{@user}"
72
75
  cmd = "chroot #{MOUNTPOINT} /bin/bash -c \"source /etc/profile && passwd #{@user}\""
73
76
  system(cmd)
74
77
  end
75
78
  end
76
79
 
77
- def umount
78
- Helpers::exec_or_die("umount -l /mnt/gentoo/dev{/shm,/pts,}")
79
- Helpers::exec_or_die("umount -R #{MOUNTPOINT}")
80
- puts "Reboot when you have done"
80
+ private
81
+
82
+ def permission
83
+ FileUtils.chmod_R 0755, "#{MOUNTPOINT}/etc/portage"
84
+ if @user
85
+ Getch::Chroot.new("chown -R #{@user}:#{@user} /home/#{@user}").run!
86
+ end
81
87
  end
82
88
 
83
- private
89
+ def the_end
90
+ #Helpers::exec_or_die("umount -l /mnt/gentoo/dev{/shm,/pts,}")
91
+ #Helpers::exec_or_die("umount -R #{MOUNTPOINT}")
92
+ puts
93
+ puts "getch has finish, before reboot, you can:"
94
+ puts " + Chroot on your system with: chroot #{MOUNTPOINT} /bin/bash"
95
+ puts " + Install more packages like networkmanager or emacs"
96
+ puts
97
+ puts " + Add more modules for your kernel (graphic, wifi card) and recompile it with:"
98
+ puts " genkernel --kernel-config=/usr/src/linux/.config all "
99
+ puts
100
+ puts "Reboot the system when you have done !"
101
+ end
84
102
 
85
103
  def exec_chroot(cmd)
86
104
  script = "chroot #{MOUNTPOINT} /bin/bash -c \"