getch 0.0.8 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) 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 +44 -0
  5. data/README.md +57 -8
  6. data/bin/setup.sh +4 -2
  7. data/lib/getch.rb +43 -15
  8. data/lib/getch/command.rb +26 -5
  9. data/lib/getch/config.rb +58 -0
  10. data/lib/getch/filesystem.rb +6 -0
  11. data/lib/getch/filesystem/clean.rb +51 -0
  12. data/lib/getch/filesystem/device.rb +61 -0
  13. data/lib/getch/filesystem/ext4.rb +1 -0
  14. data/lib/getch/filesystem/ext4/config.rb +8 -9
  15. data/lib/getch/filesystem/ext4/device.rb +2 -7
  16. data/lib/getch/filesystem/ext4/encrypt/config.rb +69 -47
  17. data/lib/getch/filesystem/ext4/encrypt/deps.rb +21 -15
  18. data/lib/getch/filesystem/ext4/encrypt/device.rb +5 -9
  19. data/lib/getch/filesystem/ext4/encrypt/format.rb +10 -6
  20. data/lib/getch/filesystem/ext4/encrypt/mount.rb +6 -43
  21. data/lib/getch/filesystem/ext4/encrypt/partition.rb +57 -55
  22. data/lib/getch/filesystem/ext4/format.rb +3 -5
  23. data/lib/getch/filesystem/ext4/mount.rb +7 -46
  24. data/lib/getch/filesystem/ext4/partition.rb +16 -39
  25. data/lib/getch/filesystem/lvm.rb +1 -0
  26. data/lib/getch/filesystem/lvm/config.rb +12 -15
  27. data/lib/getch/filesystem/lvm/deps.rb +5 -20
  28. data/lib/getch/filesystem/lvm/device.rb +33 -9
  29. data/lib/getch/filesystem/lvm/encrypt.rb +15 -0
  30. data/lib/getch/filesystem/lvm/encrypt/config.rb +71 -0
  31. data/lib/getch/filesystem/lvm/encrypt/deps.rb +46 -0
  32. data/lib/getch/filesystem/lvm/encrypt/device.rb +46 -0
  33. data/lib/getch/filesystem/lvm/encrypt/format.rb +32 -0
  34. data/lib/getch/filesystem/lvm/encrypt/mount.rb +25 -0
  35. data/lib/getch/filesystem/lvm/encrypt/partition.rb +80 -0
  36. data/lib/getch/filesystem/lvm/format.rb +11 -7
  37. data/lib/getch/filesystem/lvm/mount.rb +7 -46
  38. data/lib/getch/filesystem/lvm/partition.rb +19 -31
  39. data/lib/getch/filesystem/mount.rb +56 -0
  40. data/lib/getch/filesystem/partition.rb +77 -0
  41. data/lib/getch/filesystem/zfs.rb +14 -0
  42. data/lib/getch/filesystem/zfs/config.rb +57 -0
  43. data/lib/getch/filesystem/zfs/deps.rb +95 -0
  44. data/lib/getch/filesystem/zfs/device.rb +58 -0
  45. data/lib/getch/filesystem/zfs/encrypt.rb +15 -0
  46. data/lib/getch/filesystem/zfs/encrypt/config.rb +67 -0
  47. data/lib/getch/filesystem/zfs/encrypt/deps.rb +97 -0
  48. data/lib/getch/filesystem/zfs/encrypt/device.rb +60 -0
  49. data/lib/getch/filesystem/zfs/encrypt/format.rb +105 -0
  50. data/lib/getch/filesystem/zfs/encrypt/mount.rb +51 -0
  51. data/lib/getch/filesystem/zfs/encrypt/partition.rb +65 -0
  52. data/lib/getch/filesystem/zfs/format.rb +114 -0
  53. data/lib/getch/filesystem/zfs/mount.rb +48 -0
  54. data/lib/getch/filesystem/zfs/partition.rb +64 -0
  55. data/lib/getch/gentoo.rb +8 -4
  56. data/lib/getch/gentoo/boot.rb +32 -17
  57. data/lib/getch/gentoo/chroot.rb +12 -26
  58. data/lib/getch/gentoo/config.rb +37 -12
  59. data/lib/getch/gentoo/sources.rb +26 -29
  60. data/lib/getch/gentoo/use.rb +43 -0
  61. data/lib/getch/gentoo/use_flag.rb +64 -0
  62. data/lib/getch/helpers.rb +35 -13
  63. data/lib/getch/options.rb +23 -8
  64. data/lib/getch/version.rb +1 -1
  65. metadata +46 -18
  66. metadata.gz.sig +0 -0
@@ -0,0 +1,14 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ end
5
+ end
6
+ end
7
+
8
+ require_relative 'zfs/device'
9
+ require_relative 'zfs/partition'
10
+ require_relative 'zfs/format'
11
+ require_relative 'zfs/mount'
12
+ require_relative 'zfs/config'
13
+ require_relative 'zfs/deps'
14
+ require_relative 'zfs/encrypt'
@@ -0,0 +1,57 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ class Config < Getch::FileSystem::Zfs::Device
5
+ def initialize
6
+ super
7
+ gen_uuid
8
+ @root_dir = MOUNTPOINT
9
+ @init = '/usr/lib/systemd/systemd'
10
+ end
11
+
12
+ def fstab
13
+ file = "#{@root_dir}/etc/fstab"
14
+ datas = data_fstab
15
+ File.write(file, datas.join("\n"))
16
+ end
17
+
18
+ def systemd_boot
19
+ return if ! Helpers::efi?
20
+ esp = '/efi'
21
+ dir = "#{@root_dir}/#{esp}/loader/entries/"
22
+ datas_gentoo = [
23
+ 'title Gentoo Linux',
24
+ 'linux /vmlinuz',
25
+ 'initrd /initramfs',
26
+ "options resume=UUID=#{@uuid_swap} root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs"
27
+ ]
28
+ File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
29
+ end
30
+
31
+ # See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
32
+ def grub
33
+ return if Helpers::efi?
34
+ file = "#{@root_dir}/etc/default/grub"
35
+ cmdline = [
36
+ "GRUB_CMDLINE_LINUX=\"resume=UUID=#{@uuid_swap} root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs\""
37
+ ]
38
+ File.write("#{file}", cmdline.join("\n"), mode: 'a')
39
+ end
40
+
41
+ private
42
+
43
+ def gen_uuid
44
+ @uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp()
45
+ @uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
46
+ end
47
+
48
+ def data_fstab
49
+ efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
50
+ swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
51
+
52
+ [ efi, swap ]
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,95 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ class Deps < Getch::FileSystem::Zfs::Device
5
+ def make
6
+ unstable_zfs
7
+ install_deps
8
+ zfs_mountpoint
9
+ auto_module_rebuild
10
+ hostid
11
+ options_make
12
+ Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
13
+ end
14
+
15
+ private
16
+
17
+ def unstable_zfs
18
+ conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
19
+ data = [
20
+ "sys-fs/zfs-kmod",
21
+ "sys-fs/zfs"
22
+ ]
23
+ File.write(conf, data.join("\n"), mode: "w")
24
+ end
25
+
26
+ def install_deps
27
+ Getch::Bask.new('-a zfs').run!
28
+ Getch::Make.new("make modules_prepare").run!
29
+ Getch::Make.new("make -j$(nproc)").run!
30
+ Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
31
+ end
32
+
33
+ # See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
34
+ def zfs_mountpoint
35
+ Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
36
+ Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
37
+ Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
38
+ exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
39
+ exec("systemctl start zfs-zed.service")
40
+ Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
41
+ exec("systemctl enable zfs-zed.service")
42
+ exec("systemctl enable zfs.target")
43
+ end
44
+
45
+ def auto_module_rebuild
46
+ g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
47
+ Helpers::mkdir(g_dir)
48
+ # See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
49
+ content=<<EOF
50
+ post_pkg_postinst() {
51
+ # BUG: reinstalls of a source will cause errors
52
+ CURRENT_KV=$(uname -r)
53
+ # Check to see if genkernel has been run previously for the running kernel and use that config
54
+ if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
55
+ genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
56
+ elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
57
+ genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
58
+ else # No valid configs known
59
+ genkernel all
60
+ fi
61
+ }
62
+ EOF
63
+ File.write("#{g_dir}/gentoo-sources", content)
64
+ end
65
+
66
+ def hostid
67
+ hostid_value=`hostid`.chomp
68
+ File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
69
+ end
70
+
71
+ def options_make
72
+ bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
73
+ datas = [
74
+ '',
75
+ bootloader,
76
+ 'INSTALL="yes"',
77
+ 'MENUCONFIG="no"',
78
+ 'CLEAN="yes"',
79
+ 'SAVE_CONFIG="yes"',
80
+ 'MOUNTBOOT="no"',
81
+ 'MRPROPER="no"',
82
+ 'ZFS="yes"',
83
+ 'MODULEREBUILD="yes"'
84
+ ]
85
+ file = "#{MOUNTPOINT}/etc/genkernel.conf"
86
+ File.write(file, datas.join("\n"), mode: 'a')
87
+ end
88
+
89
+ def exec(cmd)
90
+ Getch::Chroot.new(cmd).run!
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,58 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ class Device < Getch::FileSystem::Device
5
+ def initialize
6
+ super
7
+ @id = Helpers::pool_id(@dev_root)
8
+ @boot_pool_name = "bpool-#{@id}"
9
+ @pool_name = "rpool-#{@id}"
10
+ @zfs_home = @user ? true : false
11
+ end
12
+
13
+ private
14
+
15
+ def search_boot
16
+ if @efi
17
+ if @boot_disk
18
+ @dev_esp = "/dev/#{@boot_disk}1"
19
+ else
20
+ @dev_esp = "/dev/#{@disk}1"
21
+ @root_part += 1
22
+ end
23
+ else
24
+ if @boot_disk
25
+ @dev_gpt = "/dev/#{@boot_disk}1"
26
+ @dev_boot = "/dev/#{@boot_disk}2"
27
+ @dev_grub = "/dev/#{@boot_disk}"
28
+ else
29
+ @dev_gpt = "/dev/#{@disk}1"
30
+ @dev_boot = "/dev/#{@disk}2"
31
+ @dev_grub = "/dev/#{@disk}"
32
+ @root_part += 2
33
+ end
34
+ end
35
+ end
36
+
37
+ def search_swap
38
+ if @cache_disk
39
+ @dev_swap = "/dev/#{@cache_disk}1"
40
+ @dev_log = "/dev/#{@cache_disk}2"
41
+ @dev_cache = "/dev/#{@cache_disk}3"
42
+ else
43
+ @dev_swap = "/dev/#{@disk}#{@root_part}"
44
+ @root_part += 1
45
+ end
46
+ end
47
+
48
+ def search_root
49
+ if @root_part == 1
50
+ @dev_root = "/dev/#{@disk}"
51
+ else
52
+ @dev_root = "/dev/#{@disk}#{@root_part}"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ module Encrypt
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require_relative 'encrypt/device'
11
+ require_relative 'encrypt/partition'
12
+ require_relative 'encrypt/format'
13
+ require_relative 'encrypt/mount'
14
+ require_relative 'encrypt/config'
15
+ require_relative 'encrypt/deps'
@@ -0,0 +1,67 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ module Encrypt
5
+ class Config < Getch::FileSystem::Zfs::Encrypt::Device
6
+ def initialize
7
+ super
8
+ gen_uuid
9
+ @root_dir = MOUNTPOINT
10
+ @init = '/usr/lib/systemd/systemd'
11
+ crypttab
12
+ end
13
+
14
+ def fstab
15
+ file = "#{@root_dir}/etc/fstab"
16
+ datas = data_fstab
17
+ File.write(file, datas.join("\n"))
18
+ end
19
+
20
+ def systemd_boot
21
+ return if ! @efi
22
+ esp = '/efi'
23
+ dir = "#{@root_dir}/#{esp}/loader/entries/"
24
+ datas_gentoo = [
25
+ 'title Gentoo Linux',
26
+ 'linux /vmlinuz',
27
+ 'initrd /initramfs',
28
+ "options root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs keymap=#{DEFAULT_OPTIONS[:keymap]}"
29
+ ]
30
+ File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
31
+ end
32
+
33
+ def crypttab
34
+ datas = [
35
+ "cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=512"
36
+ ]
37
+ File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
38
+ end
39
+
40
+ # See https://wiki.gentoo.org/wiki/ZFS#ZFS_root
41
+ def grub
42
+ return if @efi
43
+ file = "#{@root_dir}/etc/default/grub"
44
+ cmdline = [
45
+ "GRUB_CMDLINE_LINUX=\"root=ZFS=#{@pool_name}/ROOT/gentoo init=#{@init} dozfs keymap=#{DEFAULT_OPTIONS[:keymap]}\""
46
+ ]
47
+ File.write("#{file}", cmdline.join("\n"), mode: 'a')
48
+ end
49
+
50
+ private
51
+
52
+ def gen_uuid
53
+ @partuuid_swap = Helpers::partuuid(@dev_swap)
54
+ @uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
55
+ end
56
+
57
+ def data_fstab
58
+ boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
59
+ swap = @dev_swap ? "/dev/mapper/cryptswap none swap discard 0 0" : ''
60
+
61
+ [ boot_efi, swap ]
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,97 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ module Encrypt
5
+ class Deps < Getch::FileSystem::Zfs::Encrypt::Device
6
+ def make
7
+ unstable_zfs
8
+ install_deps
9
+ zfs_mountpoint
10
+ auto_module_rebuild
11
+ hostid
12
+ options_make
13
+ Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
14
+ end
15
+
16
+ private
17
+ def unstable_zfs
18
+ conf = "#{MOUNTPOINT}/etc/portage/package.accept_keywords/zfs"
19
+ data = [
20
+ "sys-fs/zfs-kmod",
21
+ "sys-fs/zfs"
22
+ ]
23
+ File.write(conf, data.join("\n"), mode: "w")
24
+ end
25
+
26
+ def install_deps
27
+ Getch::Bask.new('-a zfs').run!
28
+ Getch::Make.new("make modules_prepare").run!
29
+ Getch::Make.new("make -j$(nproc)").run!
30
+ Getch::Emerge.new('genkernel sys-fs/zfs').pkg!
31
+ end
32
+
33
+ # See: https://wiki.archlinux.org/index.php/ZFS#Using_zfs-mount-generator
34
+ def zfs_mountpoint
35
+ Helpers::mkdir("#{MOUNTPOINT}/etc/zfs/zfs-list.cache")
36
+ Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@boot_pool_name}") if @dev_boot
37
+ Helpers::touch("#{MOUNTPOINT}/etc/zfs/zfs-list.cache/#{@pool_name}")
38
+ exec("ln -fs /usr/libexec/zfs/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d/")
39
+ exec("systemctl start zfs-zed.service")
40
+ Helpers::sys("sed -Ei \"s|/mnt/?|/|\" #{MOUNTPOINT}/etc/zfs/zfs-list.cache/*")
41
+ exec("systemctl enable zfs-zed.service")
42
+ exec("systemctl enable zfs.target")
43
+ end
44
+
45
+ def auto_module_rebuild
46
+ g_dir="#{MOUNTPOINT}/etc/portage/env/sys-kernel"
47
+ Helpers::mkdir(g_dir)
48
+ # See https://wiki.gentoo.org/wiki/Kernel/Upgrade#Automated_build_and_installation
49
+ content=<<EOF
50
+ post_pkg_postinst() {
51
+ # BUG: reinstalls of a source will cause errors
52
+ CURRENT_KV=$(uname -r)
53
+ # Check to see if genkernel has been run previously for the running kernel and use that config
54
+ if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
55
+ genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
56
+ elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
57
+ genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
58
+ else # No valid configs known
59
+ genkernel all
60
+ fi
61
+ }
62
+ EOF
63
+ File.write("#{g_dir}/gentoo-sources", content)
64
+ end
65
+
66
+ def hostid
67
+ hostid_value=`hostid`.chomp
68
+ File.write("#{MOUNTPOINT}/etc/hostid", hostid_value, mode: 'w')
69
+ end
70
+
71
+ def options_make
72
+ bootloader = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
73
+ datas = [
74
+ '',
75
+ bootloader,
76
+ 'INSTALL="yes"',
77
+ 'MENUCONFIG="no"',
78
+ 'CLEAN="yes"',
79
+ 'KEYMAP="yes"',
80
+ 'SAVE_CONFIG="yes"',
81
+ 'MOUNTBOOT="no"',
82
+ 'MRPROPER="no"',
83
+ 'ZFS="yes"',
84
+ 'MODULEREBUILD="yes"'
85
+ ]
86
+ file = "#{MOUNTPOINT}/etc/genkernel.conf"
87
+ File.write(file, datas.join("\n"), mode: 'a')
88
+ end
89
+
90
+ def exec(cmd)
91
+ Getch::Chroot.new(cmd).run!
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,60 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Zfs
4
+ module Encrypt
5
+ class Device < Getch::FileSystem::Device
6
+ def initialize
7
+ super
8
+ @id = Helpers::pool_id(@dev_root)
9
+ @boot_pool_name = "bpool-#{@id}"
10
+ @pool_name = "rpool-#{@id}"
11
+ @zfs_home = @user ? true : false
12
+ end
13
+
14
+ private
15
+
16
+ def search_boot
17
+ if @efi
18
+ if @boot_disk
19
+ @dev_esp = "/dev/#{@boot_disk}1"
20
+ else
21
+ @dev_esp = "/dev/#{@disk}1"
22
+ @root_part += 1
23
+ end
24
+ else
25
+ if @boot_disk
26
+ @dev_gpt = "/dev/#{@boot_disk}1"
27
+ @dev_boot = "/dev/#{@boot_disk}2"
28
+ @dev_grub = "/dev/#{@boot_disk}"
29
+ else
30
+ @dev_gpt = "/dev/#{@disk}1"
31
+ @dev_boot = "/dev/#{@disk}2"
32
+ @dev_grub = "/dev/#{@disk}"
33
+ @root_part += 2
34
+ end
35
+ end
36
+ end
37
+
38
+ def search_swap
39
+ if @cache_disk
40
+ @dev_swap = "/dev/#{@cache_disk}1"
41
+ @dev_log = "/dev/#{@cache_disk}2"
42
+ @dev_cache = "/dev/#{@cache_disk}3"
43
+ else
44
+ @dev_swap = "/dev/#{@disk}#{@root_part}"
45
+ @root_part += 1
46
+ end
47
+ end
48
+
49
+ def search_root
50
+ if @root_part == 1
51
+ @dev_root = "/dev/#{@disk}"
52
+ else
53
+ @dev_root = "/dev/#{@disk}#{@root_part}"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end