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,61 @@
1
+ module Getch
2
+ module FileSystem
3
+ class Device
4
+ def initialize
5
+ @efi = Helpers::efi?
6
+ @root_part = 1
7
+ @user = DEFAULT_OPTIONS[:username]
8
+
9
+ @disk = DEFAULT_OPTIONS[:disk]
10
+ @boot_disk = DEFAULT_OPTIONS[:boot_disk]
11
+ @cache_disk = DEFAULT_OPTIONS[:cache_disk]
12
+ @home_disk = DEFAULT_OPTIONS[:home_disk]
13
+
14
+ search_boot
15
+ search_swap
16
+ search_root
17
+ search_home
18
+ end
19
+
20
+ private
21
+ def search_boot
22
+ if @efi
23
+ if @boot_disk
24
+ @dev_esp = "/dev/#{@boot_disk}#{@root_part}"
25
+ else
26
+ @dev_esp = "/dev/#{@disk}#{@root_part}"
27
+ @root_part += 1
28
+ end
29
+ else
30
+ if @boot_disk
31
+ @dev_gpt = "/dev/#{@boot_disk}#{@root_part}"
32
+ @dev_grub = "/dev/#{@boot_disk}"
33
+ else
34
+ @dev_gpt = "/dev/#{@disk}#{@root_part}"
35
+ @dev_grub = "/dev/#{@disk}"
36
+ @root_part += 1
37
+ end
38
+ end
39
+ end
40
+
41
+ def search_swap
42
+ if @cache_disk
43
+ @dev_swap = "/dev/#{@cache_disk}1"
44
+ else
45
+ @dev_swap = "/dev/#{@disk}#{@root_part}"
46
+ @root_part += 1
47
+ end
48
+ end
49
+
50
+ def search_root
51
+ @dev_root = "/dev/#{@disk}#{@root_part}"
52
+ end
53
+
54
+ def search_home
55
+ if @home_disk
56
+ @dev_home = "/dev/#{@home_disk}1"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -17,7 +17,7 @@ module Getch
17
17
 
18
18
  def systemd_boot
19
19
  return if ! Helpers::efi?
20
- esp = '/boot/efi'
20
+ esp = '/efi'
21
21
  dir = "#{@root_dir}/#{esp}/loader/entries/"
22
22
  datas_gentoo = [
23
23
  'title Gentoo Linux',
@@ -30,28 +30,27 @@ module Getch
30
30
  def grub
31
31
  return if Helpers::efi?
32
32
  file = "#{@root_dir}/etc/default/grub"
33
- cmdline = "GRUB_CMDLINE_LINUX=\"resume=#{@dev_swap} root=#{@dev_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\"\n"
33
+ cmdline = "GRUB_CMDLINE_LINUX=\"resume=PARTUUID=#{@partuuid_swap} root=PARTUUID=#{@partuuid_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\"\n"
34
34
  File.write(file, cmdline, mode: 'a')
35
35
  end
36
36
 
37
37
  private
38
38
 
39
39
  def gen_uuid
40
- @partuuid_root = `lsblk -o "PARTUUID" #{@dev_root} | tail -1`.chomp() if @dev_root
41
- @uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp() if @dev_swap
40
+ @partuuid_root = Helpers::partuuid(@dev_root)
41
+ @partuuid_swap = Helpers::partuuid(@dev_swap)
42
42
  @uuid_root = `lsblk -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
43
- @uuid_boot = `lsblk -o "UUID" #{@dev_boot} | tail -1`.chomp() if @dev_boot
44
- @uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
43
+ @uuid_esp = `lsblk -o "UUID" #{@dev_esp} | tail -1`.chomp() if @dev_esp
45
44
  @uuid_home = `lsblk -o "UUID" #{@dev_home} | tail -1`.chomp() if @dev_home
46
45
  end
47
46
 
48
47
  def data_fstab
49
- boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,noatime 1 2" : ''
50
- swap = @dev_swap ? "UUID=#{@uuid_swap} none swap discard 0 0" : ''
48
+ esp = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
49
+ swap = @dev_swap ? "PARTUUID=#{@partuuid_swap} none swap discard 0 0" : ''
51
50
  root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
52
51
  home = @dev_home ? "UUID=#{@uuid_home} /home/#{@user} ext4 defaults 0 2" : ''
53
52
 
54
- [ boot_efi, swap, root, home ]
53
+ [ esp, swap, root, home ]
55
54
  end
56
55
  end
57
56
  end
@@ -1,14 +1,9 @@
1
1
  module Getch
2
2
  module FileSystem
3
3
  module Ext4
4
- class Device
4
+ class Device < Getch::FileSystem::Device
5
5
  def initialize
6
- @disk = DEFAULT_OPTIONS[:disk]
7
- @user = DEFAULT_OPTIONS[:username]
8
- @dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
9
- @dev_root = "/dev/#{@disk}2"
10
- @dev_swap = "/dev/#{@disk}3"
11
- @dev_home = @user ? "/dev/#{@disk}4" : nil
6
+ super
12
7
  end
13
8
  end
14
9
  end
@@ -22,21 +22,21 @@ module Getch
22
22
 
23
23
  def systemd_boot
24
24
  return if ! Helpers::efi?
25
- esp = '/boot/efi'
25
+ esp = '/efi'
26
26
  dir = "#{@root_dir}/#{esp}/loader/entries/"
27
27
  datas_gentoo = [
28
28
  'title Gentoo Linux',
29
29
  'linux /vmlinuz',
30
30
  'initrd /initramfs',
31
- "options crypt_root=UUID=#{@uuid_root} root=/dev/mapper/root init=#{@init} keymap=#{DEFAULT_OPTIONS[:keymap]} rw"
31
+ "options crypt_root=UUID=#{@uuid_dev_root} root=/dev/mapper/root init=#{@init} keymap=#{DEFAULT_OPTIONS[:keymap]} rw"
32
32
  ]
33
33
  File.write("#{dir}/gentoo.conf", datas_gentoo.join("\n"))
34
34
  end
35
35
 
36
36
  def crypttab
37
- home = @dev_home ? "crypthome UUID=#{@uuid_home} /root/secretkeys/crypto_keyfile.bin luks" : ''
37
+ home = @home_disk ? "crypthome UUID=#{@uuid_home} /root/secretkeys/crypto_keyfile.bin luks" : ''
38
38
  datas = [
39
- "cryptswap UUID=#{@uuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=256",
39
+ "cryptswap PARTUUID=#{@partuuid_swap} /dev/urandom swap,cipher=aes-xts-plain64:sha256,size=512",
40
40
  home
41
41
  ]
42
42
  File.write("#{@root_dir}/etc/crypttab", datas.join("\n"))
@@ -46,7 +46,7 @@ module Getch
46
46
  return if Helpers::efi?
47
47
  file = "#{@root_dir}/etc/default/grub"
48
48
  cmdline = [
49
- "GRUB_CMDLINE_LINUX=\"crypt_root=UUID=#{@uuid_dev_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=#{DEFAULT_OPTIONS[:keymap]}\"",
49
+ "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=#{DEFAULT_OPTIONS[:keymap]}\"",
50
50
  "GRUB_ENABLE_CRYPTODISK=y"
51
51
  ]
52
52
  File.write(file, cmdline.join("\n"), mode: 'a')
@@ -55,16 +55,15 @@ module Getch
55
55
  private
56
56
 
57
57
  def gen_uuid
58
- @partuuid_root = `lsblk -o "PARTUUID" #{@dev_root} | tail -1`.chomp() if @dev_root
59
- @uuid_swap = `lsblk -o "UUID" #{@dev_swap} | tail -1`.chomp() if @dev_swap
58
+ @partuuid_swap = Helpers::partuuid(@dev_swap)
60
59
  @uuid_dev_root = `lsblk -d -o "UUID" #{@dev_root} | tail -1`.chomp() if @dev_root
61
- @uuid_boot_efi = `lsblk -o "UUID" #{@dev_boot_efi} | tail -1`.chomp() if @dev_boot_efi
60
+ @uuid_esp = Helpers::uuid(@dev_esp) if @dev_esp
62
61
  @uuid_root = `lsblk -d -o "UUID" #{@luks_root} | tail -1`.chomp() if @dev_root
63
62
  @uuid_home = `lsblk -d -o "UUID" #{@dev_home} | tail -1`.chomp() if @luks_home
64
63
  end
65
64
 
66
65
  def data_fstab
67
- boot_efi = @dev_boot_efi ? "UUID=#{@uuid_boot_efi} /boot/efi vfat noauto,noatime 1 2" : ''
66
+ boot_efi = @dev_esp ? "UUID=#{@uuid_esp} /efi vfat noauto,noatime 1 2" : ''
68
67
  swap = @dev_swap ? "#{@luks_swap} none swap discard 0 0 " : ''
69
68
  root = @dev_root ? "UUID=#{@uuid_root} / ext4 defaults 0 1" : ''
70
69
  home = @dev_home ? "#{@luks_home} /home/#{@user} ext4 defaults 0 2" : ''
@@ -3,23 +3,13 @@ module Getch
3
3
  module Ext4
4
4
  module Encrypt
5
5
  class Deps
6
- def initialize
7
- if Helpers::efi?
8
- install_efi
9
- else
10
- install_bios
11
- end
12
- install_deps
13
- end
14
-
15
6
  def make
7
+ install_deps
16
8
  genkernel
17
9
  Getch::Make.new("genkernel --kernel-config=/usr/src/linux/.config all").run!
18
10
  end
19
11
 
20
12
  private
21
- def install_efi
22
- end
23
13
 
24
14
  def genkernel
25
15
  grub = Helpers::efi? ? 'BOOTLOADER="no"' : 'BOOTLOADER="grub2"'
@@ -39,18 +29,12 @@ module Getch
39
29
  File.write(file, datas.join("\n"), mode: 'a')
40
30
  end
41
31
 
42
- def install_bios
43
- exec("euse -p sys-boot/grub -E device-mapper")
44
- exec("euse -p sys-fs/cryptsetup -E luks1_default")
45
- end
46
-
47
32
  def install_deps
48
- exec("euse -E cryptsetup") if ! Helpers::grep?("#{MOUNTPOINT}/etc/portage/make.conf", /cryptsetup/)
49
- Getch::Emerge.new('genkernel sys-apps/systemd sys-fs/cryptsetup').pkg!
33
+ Getch::Emerge.new('genkernel').pkg!
50
34
  end
51
35
 
52
36
  def exec(cmd)
53
- Helpers::run_chroot(cmd, MOUNTPOINT)
37
+ Getch::Chroot.new(cmd).run!
54
38
  end
55
39
  end
56
40
  end
@@ -2,16 +2,11 @@ module Getch
2
2
  module FileSystem
3
3
  module Ext4
4
4
  module Encrypt
5
- class Device
5
+ class Device < Getch::FileSystem::Device
6
6
  def initialize
7
- @disk = DEFAULT_OPTIONS[:disk]
8
- @user = DEFAULT_OPTIONS[:username]
9
- @dev_boot_efi = Helpers::efi? ? "/dev/#{@disk}1" : nil
10
- @dev_root = "/dev/#{@disk}2"
11
- @dev_swap = "/dev/#{@disk}3"
12
- @dev_home = @user ? "/dev/#{@disk}4" : nil
7
+ super
13
8
  @luks_root = "/dev/mapper/cryptroot"
14
- @luks_home = @user ? "/dev/mapper/crypthome" : nil
9
+ @luks_home = @home_disk ? "/dev/mapper/crypthome" : nil
15
10
  @luks_swap = "/dev/mapper/cryptswap"
16
11
  end
17
12
  end
@@ -5,18 +5,16 @@ module Getch
5
5
  class Format < Getch::FileSystem::Ext4::Encrypt::Device
6
6
  def initialize
7
7
  super
8
- @fs = 'ext4'
9
8
  @state = Getch::States.new()
10
9
  format
11
10
  end
12
11
 
13
12
  def format
14
13
  return if STATES[:format]
15
- puts "Format #{@disk} with #{@fs}"
16
- exec("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
17
- exec("mkfs.#{@fs} -F #{@luks_root}")
14
+ exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
15
+ exec("mkfs.ext4 -F #{@luks_root}")
18
16
  exec("mkswap -f #{@dev_swap}")
19
- exec("mkfs.#{@fs} -F #{@luks_home}") if @dev_home
17
+ exec("mkfs.ext4 -F #{@luks_home}") if @dev_home
20
18
  @state.format
21
19
  end
22
20
 
@@ -7,54 +7,17 @@ module Getch
7
7
  class Mount < Getch::FileSystem::Ext4::Encrypt::Device
8
8
  def initialize
9
9
  super
10
- @root_dir = MOUNTPOINT
11
- @boot_dir = "#{@root_dir}/boot"
12
- @boot_efi_dir = "#{@root_dir}/boot/efi"
13
- @home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
10
+ @mount = Getch::FileSystem::Mount.new
14
11
  @state = Getch::States.new()
15
12
  end
16
13
 
17
14
  def run
18
15
  return if STATES[:mount]
19
- #mount_swap
20
- mount_root
21
- mount_boot
22
- mount_home
23
- mount_boot_efi
24
- @state.mount
25
- end
26
-
27
- private
28
-
29
- def mount_swap
30
- return if ! @dev_swap
31
- system("swapon #{@dev_swap}")
32
- end
33
-
34
- def mount_root
35
- return if ! @dev_root
36
- Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
37
- system("mount #{@luks_root} #{@root_dir}")
38
- end
39
-
40
- def mount_boot_efi
41
- return if ! @dev_boot_efi
42
- FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
43
- system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
44
- end
45
-
46
- def mount_boot
47
- return if ! @dev_boot
48
- FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
49
- system("mount #{@dev_boot} #{@boot_dir}")
50
- end
51
-
52
- def mount_home
53
- return if ! @dev_home
54
- if @user != nil then
55
- FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
56
- system("mount #{@luks_home} #{@home_dir}")
57
- end
16
+ @mount.swap(@dev_swap)
17
+ @mount.root(@luks_root)
18
+ @mount.boot(@dev_boot)
19
+ @mount.esp(@dev_esp)
20
+ @mount.home(@luks_home)
58
21
  @state.mount
59
22
  end
60
23
  end
@@ -5,15 +5,17 @@ module Getch
5
5
  class Partition < Getch::FileSystem::Ext4::Encrypt::Device
6
6
  def initialize
7
7
  super
8
- @state = Getch::States.new()
8
+ @state = Getch::States.new
9
+ @partition = Getch::FileSystem::Partition.new
10
+ @clean = Getch::FileSystem::Clean
9
11
  @log = Log.new
10
12
  run_partition
11
13
  end
12
14
 
13
15
  def run_partition
14
16
  return if STATES[:partition ]
15
- clear_struct
16
- cleaning
17
+ @clean.hdd(@disk)
18
+ @clean.external_disk(@disk, @boot_disk, @cache_disk, @home_disk)
17
19
  if Helpers::efi?
18
20
  partition_efi
19
21
  encrypt_efi
@@ -26,35 +28,16 @@ module Getch
26
28
 
27
29
  private
28
30
 
29
- def clear_struct
30
- exec("sgdisk -Z /dev/#{@disk}")
31
- exec("wipefs -a /dev/#{@disk}")
32
- end
33
-
34
- def cleaning
35
- puts
36
- print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
37
- case gets.chomp
38
- when /^y|^Y/
39
- bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
40
- exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
41
- else
42
- return
43
- end
44
- end
45
-
46
31
  # Follow https://wiki.archlinux.org/index.php/Partitioning
47
32
  def partition_efi
48
- # /boot/efi - EFI system partition - 260MB
49
- # / - Root
50
- # swap - Linux Swap - size of the ram
51
- # /home - Home
52
- mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
53
-
54
- exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}")
55
- exec("sgdisk -n2:0:+15G -t2:8309 /dev/#{@disk}")
56
- exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
57
- exec("sgdisk -n4:0:0 -t4:8309 /dev/#{@disk}") if @dev_home
33
+ # /efi - EFI system partition - 260MB
34
+ # swap - Linux Swap - size of the ram
35
+ # / - Root
36
+ # /home - Home
37
+ @partition.efi(@dev_esp)
38
+ @partition.swap(@dev_swap)
39
+ @partition.root(@dev_root, "8309")
40
+ @partition.home(@dev_home, "8309") if @dev_home
58
41
  end
59
42
 
60
43
  def encrypt_efi
@@ -90,20 +73,18 @@ module Getch
90
73
  key_name = "crypto_keyfile.bin"
91
74
  @key_path = "#{keys_dir}/#{key_name}"
92
75
  FileUtils.mkdir keys_dir, mode: 0700 if ! Dir.exist?(keys_dir)
93
- Getch::Command.new("dd bs=512 count=4 if=/dev/urandom of=#{@key_path}").run!
76
+ exec("dd bs=512 count=4 if=/dev/urandom of=#{@key_path}")
94
77
  end
95
78
 
96
79
  def partition_bios
97
80
  # None - Bios Boot Partition - 1MiB
98
- # / - Root
99
81
  # swap - Linux Swap - size of the ram
82
+ # / - Root
100
83
  # /home - Home
101
- mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
102
-
103
- exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
104
- exec("sgdisk -n2:0:+15G -t2:8309 /dev/#{@disk}")
105
- exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
106
- exec("sgdisk -n4:0:0 -t4:8309 /dev/#{@disk}") if @dev_home
84
+ @partition.gpt(@dev_gpt)
85
+ @partition.swap(@dev_swap)
86
+ @partition.root(@dev_root, "8309")
87
+ @partition.home(@dev_home, "8309") if @dev_home
107
88
  end
108
89
 
109
90
  def exec(cmd)
@@ -4,18 +4,16 @@ module Getch
4
4
  class Format < Getch::FileSystem::Ext4::Device
5
5
  def initialize
6
6
  super
7
- @fs = 'ext4'
8
7
  @state = Getch::States.new()
9
8
  format
10
9
  end
11
10
 
12
11
  def format
13
12
  return if STATES[:format]
14
- puts "Format #{@disk} with #{@fs}"
15
- exec("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
13
+ exec("mkfs.fat -F32 #{@dev_esp}") if @dev_esp
16
14
  exec("mkswap -f #{@dev_swap}")
17
- exec("mkfs.#{@fs} -F #{@dev_root}")
18
- exec("mkfs.#{@fs} -F #{@dev_home}") if @dev_home
15
+ exec("mkfs.ext4 -F #{@dev_root}")
16
+ exec("mkfs.ext4 -F #{@dev_home}") if @dev_home
19
17
  @state.format
20
18
  end
21
19
 
@@ -1,59 +1,20 @@
1
- require 'fileutils'
2
-
3
1
  module Getch
4
2
  module FileSystem
5
3
  module Ext4
6
4
  class Mount < Getch::FileSystem::Ext4::Device
7
5
  def initialize
8
6
  super
9
- @root_dir = MOUNTPOINT
10
- @boot_dir = "#{@root_dir}/boot"
11
- @boot_efi_dir = "#{@root_dir}/boot/efi"
12
- @home_dir = @user ? "#{@root_dir}/home/#{@user}" : nil
13
- @state = Getch::States.new()
7
+ @mount = Getch::FileSystem::Mount.new
8
+ @state = Getch::States.new
14
9
  end
15
10
 
16
11
  def run
17
12
  return if STATES[:mount]
18
- mount_swap
19
- mount_root
20
- mount_boot
21
- mount_home
22
- mount_boot_efi
23
- @state.mount
24
- end
25
-
26
- private
27
-
28
- def mount_swap
29
- return if ! @dev_swap
30
- system("swapon #{@dev_swap}")
31
- end
32
-
33
- def mount_root
34
- return if ! @dev_root
35
- Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
36
- system("mount #{@dev_root} #{@root_dir}")
37
- end
38
-
39
- def mount_boot_efi
40
- return if ! @dev_boot_efi
41
- FileUtils.mkdir_p @boot_efi_dir, mode: 0700 if ! Dir.exist?(@boot_efi_dir)
42
- system("mount #{@dev_boot_efi} #{@boot_efi_dir}")
43
- end
44
-
45
- def mount_boot
46
- return if ! @dev_boot
47
- FileUtils.mkdir_p @boot_dir, mode: 0700 if ! Dir.exist?(@boot_dir)
48
- system("mount #{@dev_boot} #{@boot_dir}")
49
- end
50
-
51
- def mount_home
52
- return if ! @dev_home
53
- if @user != nil then
54
- FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
55
- system("mount #{@dev_home} #{@home_dir}")
56
- end
13
+ @mount.swap(@dev_swap)
14
+ @mount.root(@dev_root)
15
+ @mount.boot(@dev_boot)
16
+ @mount.esp(@dev_esp)
17
+ @mount.home(@dev_home)
57
18
  @state.mount
58
19
  end
59
20
  end