getch 0.0.2 → 0.0.7

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.
@@ -0,0 +1,37 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Ext4
4
+ module Encrypt
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
+ private
16
+ def install_efi
17
+ end
18
+
19
+ def install_bios
20
+ exec("euse -p sys-boot/grub -E device-mapper")
21
+ end
22
+
23
+ def install_deps
24
+ exec("euse -p sys-apps/systemd -E cryptsetup")
25
+ Helpers::emerge('genkernel cryptsetup lvm2')
26
+ exec("genkernel --install --luks --keymap #{DEFAULT_OPTIONS[:keyboard]} --lvm --kernel-config=/usr/src/linux/.config initramfs")
27
+ exec("systemctl enable lvm2-monitor")
28
+ end
29
+
30
+ def exec(cmd)
31
+ Helpers::run_chroot(cmd, MOUNTPOINT)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Ext4
4
+ module Encrypt
5
+ class Device
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
+ @vg = 'vg0'
12
+ @lv_root = "/dev/mapper/#{@vg}-root"
13
+ @lv_swap = "/dev/mapper/#{@vg}-swap"
14
+ @lv_home = @user ? "/dev/mapper/#{@vg}-home" : nil
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Ext4
4
+ module Encrypt
5
+ class Format < Getch::FileSystem::Ext4::Encrypt::Device
6
+ def initialize
7
+ super
8
+ @fs = 'ext4'
9
+ @state = Getch::States.new()
10
+ format
11
+ end
12
+
13
+ def format
14
+ return if STATES[:format]
15
+ puts "Format #{@disk} with #{@fs}"
16
+ system("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
17
+ system("mkswap #{@lv_swap}")
18
+ system("mkfs.#{@fs} #{@lv_root}")
19
+ system("mkfs.#{@fs} #{@lv_home}") if @lv_home
20
+ @state.format
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,64 @@
1
+ require 'fileutils'
2
+
3
+ module Getch
4
+ module FileSystem
5
+ module Ext4
6
+ module Encrypt
7
+ class Mount < Getch::FileSystem::Ext4::Encrypt::Device
8
+ def initialize
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
14
+ @state = Getch::States.new()
15
+ end
16
+
17
+ def run
18
+ 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 ! @lv_swap
31
+ system("swapon #{@lv_swap}")
32
+ end
33
+
34
+ def mount_root
35
+ return if ! @lv_root
36
+ Dir.mkdir(@root_dir, 0700) if ! Dir.exist?(@root_dir)
37
+ system("mount #{@lv_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 ! @lv_home
54
+ if @user != nil then
55
+ FileUtils.mkdir_p @home_dir, mode: 0700 if ! Dir.exist?(@home_dir)
56
+ system("mount #{@lv_home} #{@home_dir}")
57
+ end
58
+ @state.mount
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,95 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Ext4
4
+ module Encrypt
5
+ class Partition < Getch::FileSystem::Ext4::Encrypt::Device
6
+ def initialize
7
+ super
8
+ @state = Getch::States.new()
9
+ run_partition
10
+ end
11
+
12
+ def run_partition
13
+ return if STATES[:partition ]
14
+ clear_struct
15
+ cleaning
16
+ boot
17
+ others
18
+ luks
19
+ lvm
20
+ @state.partition
21
+ end
22
+
23
+ private
24
+
25
+ def clear_struct
26
+ exec("sgdisk -Z /dev/#{@disk}")
27
+ exec("wipefs -a /dev/#{@disk}")
28
+ end
29
+
30
+ def cleaning
31
+ puts
32
+ print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
33
+ case gets.chomp
34
+ when /^y|^Y/
35
+ bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
36
+ exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
37
+ else
38
+ return
39
+ end
40
+ end
41
+
42
+ def boot
43
+ if Helpers::efi?
44
+ exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}}")
45
+ else
46
+ exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
47
+ end
48
+ end
49
+
50
+ def others
51
+ exec("sgdisk -n2:0:+0 -t2:8309 /dev/#{@disk}")
52
+ end
53
+
54
+ def luks
55
+ if Helpers::efi?
56
+ exec("cryptsetup --use-random luksFormat /dev/#{@disk}2")
57
+ exec("cryptsetup open --type luks /dev/#{@disk}2 crypt-lvm")
58
+ else
59
+ # GRUB do not support LUKS2
60
+ exec("cryptsetup --use-random luksFormat --type luks1 /dev/#{@disk}2")
61
+ exec("cryptsetup open --type luks1 /dev/#{@disk}2 crypt-lvm")
62
+ end
63
+ end
64
+
65
+ def lvm
66
+ mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
67
+ exec("pvcreate /dev/mapper/crypt-lvm")
68
+ exec("vgcreate #{@vg} /dev/mapper/crypt-lvm")
69
+ exec("lvcreate -L 15G -n root #{@vg}")
70
+ exec("lvcreate -L #{mem} -n swap #{@vg}")
71
+ exec("lvcreate -l 100%FREE -n home #{@vg}") if @user
72
+ exec("vgchange --available y")
73
+ end
74
+
75
+ # Follow https://wiki.archlinux.org/index.php/Partitioning
76
+ # Partition_efi
77
+ # /boot/efi - EFI system partition - 260MB
78
+ # / - Root
79
+ # swap - Linux Swap - size of the ram
80
+ # /home - Home
81
+
82
+ # Partition_bios
83
+ # None - Bios Boot Partition - 1MiB
84
+ # / - Root
85
+ # swap - Linux Swap - size of the ram
86
+ # /home - Home
87
+
88
+ def exec(cmd)
89
+ Getch::Command.new(cmd).run!
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,24 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Ext4
4
+ class Format < Getch::FileSystem::Ext4::Device
5
+ def initialize
6
+ super
7
+ @fs = 'ext4'
8
+ @state = Getch::States.new()
9
+ format
10
+ end
11
+
12
+ def format
13
+ return if STATES[:format]
14
+ puts "Format #{@disk} with #{@fs}"
15
+ system("mkfs.fat -F32 #{@dev_boot_efi}") if Helpers::efi?
16
+ system("mkswap -f #{@dev_swap}")
17
+ system("mkfs.#{@fs} #{@dev_root}")
18
+ system("mkfs.#{@fs} #{@dev_home}") if @dev_home
19
+ @state.format
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,62 @@
1
+ require 'fileutils'
2
+
3
+ module Getch
4
+ module FileSystem
5
+ module Ext4
6
+ class Mount < Getch::FileSystem::Ext4::Device
7
+ def initialize
8
+ 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()
14
+ end
15
+
16
+ def run
17
+ 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
57
+ @state.mount
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,75 @@
1
+ module Getch
2
+ module FileSystem
3
+ module Ext4
4
+ class Partition < Getch::FileSystem::Ext4::Device
5
+ def initialize
6
+ super
7
+ @state = Getch::States.new()
8
+ run_partition
9
+ end
10
+
11
+ def run_partition
12
+ return if STATES[:partition ]
13
+ clear_struct
14
+ cleaning
15
+ if Helpers::efi?
16
+ partition_efi
17
+ else
18
+ partition_bios
19
+ end
20
+ @state.partition
21
+ end
22
+
23
+ private
24
+
25
+ def clear_struct
26
+ exec("sgdisk -Z /dev/#{@disk}")
27
+ exec("wipefs -a /dev/#{@disk}")
28
+ end
29
+
30
+ def cleaning
31
+ puts
32
+ print "Cleaning data on #{@disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
33
+ case gets.chomp
34
+ when /^y|^Y/
35
+ bloc=`blockdev --getbsz /dev/#{@disk}`.chomp
36
+ exec("dd if=/dev/urandom of=/dev/#{@disk} bs=#{bloc} status=progress")
37
+ else
38
+ return
39
+ end
40
+ end
41
+
42
+ # Follow https://wiki.archlinux.org/index.php/Partitioning
43
+ def partition_efi
44
+ # /boot/efi - EFI system partition - 260MB
45
+ # / - Root
46
+ # swap - Linux Swap - size of the ram
47
+ # /home - Home
48
+ mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
49
+
50
+ exec("sgdisk -n1:1M:+260M -t1:EF00 /dev/#{@disk}")
51
+ exec("sgdisk -n2:0:+15G -t2:8304 /dev/#{@disk}")
52
+ exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
53
+ exec("sgdisk -n4:0:0 -t4:8302 /dev/#{@disk}") if @dev_home
54
+ end
55
+
56
+ def partition_bios
57
+ # None - Bios Boot Partition - 1MiB
58
+ # / - Root
59
+ # swap - Linux Swap - size of the ram
60
+ # /home - Home
61
+ mem=`awk '/MemTotal/ {print $2}' /proc/meminfo`.chomp + 'K'
62
+
63
+ exec("sgdisk -n1:1MiB:+1MiB -t1:EF02 /dev/#{@disk}")
64
+ exec("sgdisk -n2:0:+15G -t2:8304 /dev/#{@disk}")
65
+ exec("sgdisk -n3:0:+#{mem} -t3:8200 /dev/#{@disk}")
66
+ exec("sgdisk -n4:0:0 -t4:8302 /dev/#{@disk}") if @dev_home
67
+ end
68
+
69
+ def exec(cmd)
70
+ Getch::Command.new(cmd).run!
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,67 @@
1
+ require 'open-uri'
2
+ require 'open3'
3
+ require_relative 'gentoo/stage'
4
+ require_relative 'gentoo/config'
5
+ require_relative 'gentoo/chroot'
6
+ require_relative 'gentoo/sources'
7
+ require_relative 'gentoo/boot'
8
+
9
+ module Getch
10
+ 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
40
+ chroot = Getch::Gentoo::Chroot.new()
41
+ chroot.update
42
+ chroot.world
43
+ chroot.systemd
44
+ return if STATES[:gentoo_kernel]
45
+ chroot.kernel
46
+ chroot.kernel_deps
47
+ chroot.install_pkgs
48
+ end
49
+
50
+ def kernel
51
+ return if STATES[:gentoo_kernel]
52
+ source = Getch::Gentoo::Sources.new()
53
+ new
54
+ source.init_config
55
+ source.build_kspp
56
+ source.build_others
57
+ source.make
58
+ @state.kernel
59
+ end
60
+
61
+ def boot(options)
62
+ boot = Getch::Gentoo::Boot.new(options)
63
+ boot.start
64
+ end
65
+ end
66
+ end
67
+ end